gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 376 forks source link

InternalCompilerException when using the "finalize" method #1666

Closed dankurka closed 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 1659

Found in GWT Release: gwt-windows-1.4.60

Detailed description:
internal compiler error shown when compiling with the OBFUSCATED flag;
here's the log:

<<
Analyzing permutation #1
      [ERROR] An internal compiler exception occurred
com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during
visit.
        at
com.google.gwt.dev.jjs.ast.JVisitor.translateException(JVisitor.java:538)
        at com.google.gwt.dev.jjs.ast.JVisitor.doTraverse(JVisitor.java:529)
        at
com.google.gwt.dev.jjs.ast.JVisitor.doAcceptWithInsertRemove(JVisitor.java:521)
        at
com.google.gwt.dev.jjs.ast.JVisitor.acceptWithInsertRemove(JVisitor.java:81)
        at com.google.gwt.dev.jjs.ast.JClassType.traverse(JClassType.java:50)
        at com.google.gwt.dev.jjs.ast.JVisitor.doTraverse(JVisitor.java:527)
        at com.google.gwt.dev.jjs.ast.JVisitor.doAccept(JVisitor.java:509)
        at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:69)
        at
com.google.gwt.dev.jjs.impl.GenerateJavaScriptAST$CreateNamesAndScopesVisitor.visit(GenerateJavaScriptAST.java:253)
        at com.google.gwt.dev.jjs.ast.JClassType.traverse(JClassType.java:48)
        at com.google.gwt.dev.jjs.ast.JVisitor.doTraverse(JVisitor.java:527)
        at com.google.gwt.dev.jjs.ast.JVisitor.doAccept(JVisitor.java:515)
        at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:77)
        at com.google.gwt.dev.jjs.ast.JProgram.traverse(JProgram.java:699)
        at com.google.gwt.dev.jjs.ast.JVisitor.doTraverse(JVisitor.java:527)
        at com.google.gwt.dev.jjs.ast.JVisitor.doAccept(JVisitor.java:509)
        at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:69)
        at
com.google.gwt.dev.jjs.impl.GenerateJavaScriptAST.execImpl(GenerateJavaScriptAST.java:1783)
        at
com.google.gwt.dev.jjs.impl.GenerateJavaScriptAST.exec(GenerateJavaScriptAST.java:1653)
        at
com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.compile(JavaToJavaScriptCompiler.java:385)
        at
com.google.gwt.dev.GWTCompiler.realizePermutation(GWTCompiler.java:688)
        at
com.google.gwt.dev.GWTCompiler.compilePermutations(GWTCompiler.java:411)
        at com.google.gwt.dev.GWTCompiler.distill(GWTCompiler.java:335)
        at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:755)
        at com.google.gwt.dev.GWTCompiler.run(GWTCompiler.java:745)
        at com.google.gwt.dev.GWTCompiler.main(GWTCompiler.java:213)
Caused by: java.lang.NullPointerException
        at java.util.TreeMap.compare(TreeMap.java:1093)
        at java.util.TreeMap.getEntry(TreeMap.java:347)
        at java.util.TreeMap.get(TreeMap.java:265)
        at
com.google.gwt.dev.js.ast.JsScope.findExistingNameNoRecurse(JsScope.java:212)
        at com.google.gwt.dev.js.ast.JsScope.declareName(JsScope.java:94)
        at
com.google.gwt.dev.jjs.impl.GenerateJavaScriptAST$CreateNamesAndScopesVisitor.visit(GenerateJavaScriptAST.java:299)
        at com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:141)
        at com.google.gwt.dev.jjs.ast.JVisitor.doTraverse(JVisitor.java:527)
        ... 24 more
         [ERROR] at SimpleAnimator.java(75): public abstract void finalize();
         [ERROR] at SimpleAnimator.java(5): abstract class SimpleAnimator
extends
Object implements Animator, Rule 
         [ERROR] at FadeIn.java(7): final class FadeIn extends SimpleAnimator 
         [ERROR] <no source info>: <JProgram>
[ERROR] Build failed
>>

The code to reproduce this behaviour is quite big, I'm trying to reproduce
it without the need of the whole project. 

Workaround if you have one:
compile in either PRETTY or DETAILED mode

Links to the relevant GWT Developer Forum posts:
 Issue 497 and other "internal compiler error" related issues, often do not
show up in hosted mode, when code isn't translated yed, so maybe the
problem resides in the names translation phase...

Reported by giancarlo.todone on 2007-09-16 00:17:55

dankurka commented 9 years ago
This problem occurs specifically with the "finalize" method.  Object methods get
special treatment during GenerateJavaScriptAST, and I missed including a
pre-obfuscated ident for "finalize".

Reported by gwt.team.scottb on 2007-09-17 19:52:06

dankurka commented 9 years ago
Committed as r1438.

Reported by gwt.team.scottb on 2007-09-18 18:53:40

dankurka commented 9 years ago

Reported by sumitchandel+legacy@google.com on 2008-04-28 23:20:12

dankurka commented 9 years ago
I am getting something similar, but my workaround was different (changing the code
generation style did not work).

In my case, I had to remove a function call in my onModuleLoad().  In the snippet
below, I commented out the doCommand and everything worked.

    public void onModuleLoad()
    {
        singleton = this;

        GWT.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());

    doCommand("init");
    }

    static public void doCommand(String action)
    {

I'm using 1.5 RC1

Stack trace attached.  The error pointed to completely unrelated code.  I had to
backtrack from a version that did compile to find this.

Reported by fileformat on 2008-07-11 14:42:38


dankurka commented 9 years ago
This is an unrelated bug that has been fixed since RC1.

Reported by scottb+legacy@google.com on 2008-07-11 15:47:44

dankurka commented 9 years ago
1_5_RC has been released.

Reported by scottb+legacy@google.com on 2008-08-14 02:24:19

dankurka commented 9 years ago

Reported by rjrjr@google.com on 2011-02-09 00:18:08

dankurka commented 9 years ago
A similar thing happens in 2.2:

   [ERROR] An internal compiler exception occurred
com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during visit.
    at com.google.gwt.dev.jjs.ast.JVisitor.translateException(JVisitor.java:108)
    at com.google.gwt.dev.jjs.ast.JVisitor.accept(JVisitor.java:146)
[...]

I managed to track it down, it was because of an unfinished for loop (simplified here):

//

for (Integer value : new ArrayList<Integer>())
    ; // TODO

//

It seems that the compiler cannot optimize it out and commits hara kiri :).

Reported by papuska on 2011-04-01 20:00:21

dankurka commented 9 years ago
Can you please file a new bug?  This isn't related to the issue you're updating.

Reported by scottb@google.com on 2011-04-01 20:09:13