JVM crashes with ArrayIndexOutOfBoundsException because of Native Code

890 views Asked by At

I have a JSP program where I'm trying to load checkboxes dynamically by using columns from a xls for which I'm using a native library called JEP to use Python to get the data.I know I can use something like ApachePOI to do the same but I need to use JEP in the same web app later.

JSP for checkboxes:

<%@ page import ="Excel.getCSV" %>
<%@page  import = "java.util.ArrayList " %>
 <% ArrayList<String> columns = new ArrayList<String>(); 


columns= getCSV.columnGetter();
//String hobbies[];
for(int i=0;i<columns.size();i++){  String str= columns.get(i);
%> <li class="mdl-list__item">

<input type="checkbox" name="hobbies[]" id="hobby1" value= <%= str %> /> 
<%= str %> <!-- all of this works -->
</li> 

To process form data

<%@ page import = "java.io.*,java.util.*" %>

<%@ page import ="org.apache.commons.lang3.ArrayUtils" %>
<%
String[] form = {"asda","asd"};
//form = request.getParameterValues("hobbies[]"); I have tried using 
//ArrayUtils.isNotEmpty instead of using the enum
System.out.println("I am here"); //This works
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {

System.out.println("I actually reached here");// Crashes before printing 
this.

%>
<jsp:forward page = "Page3.jsp" /><%                    
<% } 
 %>

Column getter code:

public static ArrayList<String> columnGetter() throws JepException {
    try(Jep jep = new Jep()) {
         jep.set("pathToPython", path);
         jep.eval("from foo import getColumn");
         jep.eval("x= getColumn(pathToPython,1)");
         names=(ArrayList<String>) jep.getValue("x");
         jep.close();
       }

    return names;}

JVM crashes with the following error:

#The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

So I removed the Native code (JEP code) and the program works.

The Problem

Avoiding the Native Code is not a solution. So I saw the error log, according to that there is a "ArrayIndexOutOfBoundsException"

Internal exceptions (10 events):
Event: 16.868 Thread 0x000000001ec47000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000dacc0b00) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db032ec8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db033100) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 17.232 Thread 0x000000001b19d000 Implicit null exception at 0x000000000534ebb1 to 0x00000000053512e1
Event: 17.271 Thread 0x000000001b19d000 Implicit null exception at 0x0000000004ec1ead to 0x0000000004ec4159
Event: 17.272 Thread 0x000000001b19d000 Implicit null exception at 0x0000000004cae411 to 0x0000000004cae849
Event: 17.611 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': 10604> (0x00000000d6608708) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7a88) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7cc0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\interpreter\interpreterRuntime.cpp, line 366]
Event: 87.626 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x00000000ddf7cb58) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u181\11358\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605]

I tried to deduce what might be causing that and I came up empty. The JEP code was used to generate the checkboxes, that works fine. I tried to use sys.out to debug the code. The error occurs when I press the button, which causes the enum to get populated and at this point when the while condition is checked, JVM crashes with ArrayIndex out of bounds. I have tried using a string array for the form values, then using .length ArrayUtils.isNotEmpty methods neither of which should throw that error.

Question

Why is JVM crashing where its crashing? If it is a problem with JEP, shouldn't it crash before generating the checkbox?

1

There are 1 answers

0
Neel bedarkar On BEST ANSWER

Well, I found the reason. I don't know why the error is Arrayindexoutofbounds in the logs, but the error occurred because my JEP library was in a folder which couldn't be accessed by my class.