由于本机代码,JVM与ArrayIndexOutOfBoundsException崩溃

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了由于本机代码,JVM与ArrayIndexOutOfBoundsException崩溃相关的知识,希望对你有一定的参考价值。

我有一个JSP程序,我试图通过使用xls中的列来动态加载复选框,我正在使用一个名为JEP的本地库来使用Python来获取数据。我知道我可以使用类似ApachePOI的东西来执行同样但我需要稍后在同一个Web应用程序中使用JEP。

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崩溃时出现以下错误:

#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:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db032ec8) thrown at [C:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 17.217 Thread 0x000000001b19d000 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000db033100) thrown at [C:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.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:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7a88) thrown at [C:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.576 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException': -1> (0x00000000ddeb7cc0) thrown at [C:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevminterpreterinterpreterRuntime.cpp, line 366]
Event: 87.626 Thread 0x000000001be5e800 Exception <a 'java/lang/ArrayIndexOutOfBoundsException'> (0x00000000ddf7cb58) thrown at [C:
eworkspace8-2-build-windows-amd64-cygwinjdk8u18111358hotspotsrcsharevm
untimesharedRuntime.cpp, line 605]

我试图推断出可能导致这种情况的原因而且我空洞了。 JEP代码用于生成复选框,工作正常。我试图使用sys.out来调试代码。当我按下按钮导致枚举被填充时发生错误,此时检查while条件时,JVM与ArrayIndex超出界限时崩溃。我已经尝试使用字符串数组作为表单值,然后使用.length ArrayUtils.isNotEmpty方法,这两种方法都不应该抛出该错误。

Question

为什么JVM在崩溃的地方崩溃?如果是JEP的问题,在生成复选框之前不应该崩溃吗?

答案

好吧,我找到了原因。我不知道为什么错误是日志中的Arrayindexoutofbounds,但是因为我的JEP库位于我的类无法访问的文件夹中而发生错误。

以上是关于由于本机代码,JVM与ArrayIndexOutOfBoundsException崩溃的主要内容,如果未能解决你的问题,请参考以下文章

与 Perl 代码的自动交互

与 Perl 代码的自动交互

抗崩溃的Java IPC

JVM_FindSignal 函数不断分配本机内存

JVM中的本机内存跟踪

使用本机 API 的替代解决方案:JVM_LoadClass0、JVM_AllocateNewArray 和 JVM_AllocateNewObject