由于本机代码,JVM 因 ArrayIndexOutOfBoundsException 而崩溃
JVM crashes with ArrayIndexOutOfBoundsException because of Native Code
我有一个 JSP 程序,我试图通过使用 xls 中的列动态加载复选框,为此我使用名为 JEP 的本机库来使用 Python 让 data.I 知道我可以使用 ApachePOI 之类的东西来做同样的事情,但稍后我需要在同一个 Web 应用程序中使用 JEP。
JSP 复选框:
<%@ 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>
处理表单数据
<%@ 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" /><%
<% }
%>
第getter栏代码:
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 崩溃并出现以下错误:
#The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
所以我删除了本机代码(JEP 代码)并且程序运行正常。
问题
避免本机代码不是解决方案。所以我看到错误日志,根据有一个 "ArrayIndexOutOfBoundsException"
Internal exceptions (10 events):
Event: 16.868 Thread 0x000000001ec47000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000dacc0b00) thrown at [C:\re\workspace-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605]
我试图推断出可能导致这种情况的原因,但一无所获。 JEP 代码用于生成复选框,效果很好。我尝试使用 sys.out 来调试代码。当我按下按钮时发生错误,这导致枚举被填充,此时当检查 while 条件时,JVM 因 ArrayIndex 超出范围而崩溃。
我试过使用字符串数组作为表单值,然后使用 .length ArrayUtils.isNotEmpty 方法,这两种方法都不应该抛出该错误。
问题
为什么 JVM 在它崩溃的地方崩溃?如果是 JEP 的问题,它不应该在生成复选框之前崩溃吗?
嗯,找到原因了。我不知道为什么日志中的错误是 Arrayindexoutofbounds,但错误发生是因为我的 JEP 库位于我的 class.
无法访问的文件夹中
我有一个 JSP 程序,我试图通过使用 xls 中的列动态加载复选框,为此我使用名为 JEP 的本机库来使用 Python 让 data.I 知道我可以使用 ApachePOI 之类的东西来做同样的事情,但稍后我需要在同一个 Web 应用程序中使用 JEP。
JSP 复选框:
<%@ 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>
处理表单数据
<%@ 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" /><%
<% }
%>
第getter栏代码:
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 崩溃并出现以下错误:
#The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
所以我删除了本机代码(JEP 代码)并且程序运行正常。
问题
避免本机代码不是解决方案。所以我看到错误日志,根据有一个 "ArrayIndexOutOfBoundsException"
Internal exceptions (10 events):
Event: 16.868 Thread 0x000000001ec47000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000dacc0b00) thrown at [C:\re\workspace-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\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-2-build-windows-amd64-cygwin\jdk8u181358\hotspot\src\share\vm\runtime\sharedRuntime.cpp, line 605]
我试图推断出可能导致这种情况的原因,但一无所获。 JEP 代码用于生成复选框,效果很好。我尝试使用 sys.out 来调试代码。当我按下按钮时发生错误,这导致枚举被填充,此时当检查 while 条件时,JVM 因 ArrayIndex 超出范围而崩溃。 我试过使用字符串数组作为表单值,然后使用 .length ArrayUtils.isNotEmpty 方法,这两种方法都不应该抛出该错误。
问题
为什么 JVM 在它崩溃的地方崩溃?如果是 JEP 的问题,它不应该在生成复选框之前崩溃吗?
嗯,找到原因了。我不知道为什么日志中的错误是 Arrayindexoutofbounds,但错误发生是因为我的 JEP 库位于我的 class.
无法访问的文件夹中