Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException thrown when compile long js #529

Closed
lalicw opened this issue Mar 28, 2019 · 7 comments
Closed

ArrayIndexOutOfBoundsException thrown when compile long js #529

lalicw opened this issue Mar 28, 2019 · 7 comments

Comments

@lalicw
Copy link

lalicw commented Mar 28, 2019

When we upgrade rhino from 1.7.R4 to 1.7.7.1, compilation error occurs for an exists long js which is ok in 1.7.R4.

the js has 2445 lines and 82277 characters, contains java importer, inner function and many comments. Before we upgrde the rhino, it's ok, we try to debug the source code and it's too complex to find out the root cause.

java.lang.ArrayIndexOutOfBoundsException: -32748
        at org.mozilla.classfile.ClassFileWriter$StackMapTable.executeBlock:1731
        at org.mozilla.classfile.ClassFileWriter$StackMapTable.executeWorkList:1712
        at org.mozilla.classfile.ClassFileWriter$StackMapTable.verify:1626
        at org.mozilla.classfile.ClassFileWriter$StackMapTable.generate:1472
        at org.mozilla.classfile.ClassFileWriter.stopMethod:290
        at org.mozilla...optimizer.BodyCodegen.generateBodyCode:1292
        at org.mozilla...optimizer.Codegen.generateCode:306
        at org.mozilla...optimizer.Codegen.compileToClassFile:166
        at org.mozilla...optimizer.ClassCompiler.compileToClassFiles:155
        at com.huawei...script.JsCompiler.processSource:314
        at com.huawei...script.JsCompiler.compile:74

the js file structure is like this

var javaImporter = JavaImporter();   

javaImporter.importPackage(Packages.java.lang);
javaImporter.importPackage(Packages.java.util); 
javaImporter.importClass(Packages.com.xxx.xxx.XXX);

with(javaImporter)
{
	function run(message)
	{
               function isEmpty(paramField)
               { 
   	               if("" ==paramField && null == paramField && "null" == String(paramField))
	              {
		              return true;
	              }
	             return false;
                }
                //...
         }

        function _isEmpty(value)
       {
            return value == "";
       }
      //...
}

JDK 1.8
Version:1.7.7.1

@lalicw
Copy link
Author

lalicw commented Mar 28, 2019

We use the default CompilerEnvirons which mean we just new a CompilerEnvirons and don't invoke any set method. we tried the newest version of rhino but still not work.

@lalicw
Copy link
Author

lalicw commented Mar 28, 2019

   private void finalizeSuperBlockStarts() {
        if (GenerateStackMap) {
            for (int i = 0; i < itsExceptionTableTop; i++) {
                ExceptionTableEntry ete = itsExceptionTable[i];
               // it seems the getLabelPC return value more than 32767
                short handlerPC = (short) getLabelPC(ete.itsHandlerLabel);
                addSuperBlockStart(handlerPC);
            }

the tail values in itsLabelTable is as below:
image

@lalicw
Copy link
Author

lalicw commented Mar 28, 2019

After i do some change as below in ClassFileWriter.java, it seems ok. but i'm not sure it's affect.

short xxx = (short) getLabelPC(...)

to

int xxx = getLabelPC(...)

@rbri
Copy link
Collaborator

rbri commented Mar 31, 2019

Did some history check, this was introduced with commit f81158c in 2010. For me it looks like some refactoring leftover because both involved methods are working with int's.

@lalicw
Copy link
Author

lalicw commented Apr 4, 2019

Did some history check, this was introduced with commit f81158c in 2010. For me it looks like some refactoring leftover because both involved methods are working with int's.

sorry, i'm not sure what you are talking about...
do you mean it's refactoring leftovers and will be fixed in the future release?
but when we use 1.7R4 it seems ok, it’s a strange result...

what if i need to fix it temporarily?

@alexbrickwedde
Copy link

I also ran into this issue today. Will it be fixed?

@rbri
Copy link
Collaborator

rbri commented Dec 3, 2019

Fix is on the way...

@gbrail gbrail closed this as completed in 4921759 Dec 6, 2019
gbrail pushed a commit that referenced this issue Dec 10, 2019
Fix ArrayIndexOutOfBoundsException while compiling.

* use int instead of short like in many other places, add a test case that passes after this change
fixes #529
* add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants