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

java.lang.NullPointerException: Cannot read field "declaringScope" because "outerLocalVariable" is null after upgrading from 2.11 to 2.12.1 #10065

Open
koendecock opened this issue Dec 17, 2024 · 2 comments

Comments

@koendecock
Copy link

GWT version:2.12.1

After upgrading gwt in our application from 2.11 to 2.12.1 we get the below error during the gwt compilation process.
java.lang.NullPointerException: Cannot read field "declaringScope" because "outerLocalVariable" is null

The full stack trace:
[INFO] [ERROR] Unexpected internal compiler error
[INFO] java.lang.NullPointerException: Cannot read field "declaringScope" because "outerLocalVariable" is null
[INFO] at org.eclipse.jdt.internal.compiler.lookup.BlockScope.getEmulationPath(BlockScope.java:831)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.pushLambdaExpressionLocalsIntoMethodScope(GwtAstBuilder.java:1264)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.visit(GwtAstBuilder.java:1253)
[INFO] at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.traverse(LambdaExpression.java:787)
[INFO] at org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.traverse(ExplicitConstructorCall.java:524)
[INFO] at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.traverse(ConstructorDeclaration.java:704)
[INFO] at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1831)
[INFO] at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1683)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.processImpl(GwtAstBuilder.java:4122)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.process(GwtAstBuilder.java:4160)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$UnitProcessorImpl.process(CompilationStateBuilder.java:128)
[INFO] at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:322)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.processCompiledUnits(Compiler.java:575)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:475)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
[INFO] at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:1021)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:322)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:532)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:464)
[INFO] at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:426)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:210)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:190)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:131)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:192)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:143)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:132)
[INFO] at com.google.gwt.dev.Compiler$1.run(Compiler.java:110)
[INFO] at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO] at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO] at com.google.gwt.dev.Compiler.main(Compiler.java:113)

@niloc132
Copy link
Member

I've put up a snapshot build to test with - this is 2.12.1 plus a single try/catch in AstVisitor.visit(LambdaExpression,BlockScope) to dump the context of the error. It looks like a few others of those are missing, I'll add them also for the next release. Please try GWT version 2.12.2-10065-lambda-test-SNAPSHOT from https://repo.vertispan.com/gwt-snapshot/, it should give us a little more context, and possible offer a workaround.

Reading pushLambdaExpressionLocalsIntoMethodScope where this failed, it appears that we're iterating the syntheticArguments array and one of those entries had a actualOuterLocalVariable that was null. Synthetic arguments are usually something like an "effectively final" variable in the method where the lambda was declared - readable, but not writable. The compiler wraps those up as "constructor arguments", same as if this was an inner class of some kind, and then the method can access them as fields of the inner type.

The syntheticArguments array was not created by GWT, but passed in from LambdaExpression.outerLocalVariables - so something fishy is happening there. Either we have a new kind of outer local variable that a lambda effectively closes over (but doesn't correspond to a real variable) and GWT is missing support for this, or we've hit a bug in JDT?

There is another field in SyntheticArgumentBinding, perhaps to look for a matching field instead of a local? That field isn't new though, both fields have been there for 22 years...
https://github.com/eclipse-jdt/eclipse.jdt.core/blame/master/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticArgumentBinding.java

@koendecock
Copy link
Author

koendecock commented Dec 17, 2024

Hi Colin,

thank you for this version. I've testen and the compilation failure has more details.

[INFO] [ERROR] An internal compiler exception occurred
[INFO] com.google.gwt.dev.jjs.InternalCompilerException: Error constructing Java AST
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.translateException(GwtAstBuilder.java:4190)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.visit(GwtAstBuilder.java:1257)
[INFO] at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.traverse(LambdaExpression.java:787)
[INFO] at org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.traverse(ExplicitConstructorCall.java:524)
[INFO] at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.traverse(ConstructorDeclaration.java:704)
[INFO] at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1831)
[INFO] at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1683)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.processImpl(GwtAstBuilder.java:4126)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.process(GwtAstBuilder.java:4164)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$UnitProcessorImpl.process(CompilationStateBuilder.java:128)
[INFO] at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:322)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.processCompiledUnits(Compiler.java:575)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:475)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)
[INFO] at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:1021)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:322)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:532)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:464)
[INFO] at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:426)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:210)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:190)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:131)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:192)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:143)
[INFO] at com.google.gwt.dev.Compiler.compile(Compiler.java:132)
[INFO] at com.google.gwt.dev.Compiler$1.run(Compiler.java:110)
[INFO] at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO] at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO] at com.google.gwt.dev.Compiler.main(Compiler.java:113)
[INFO] Caused by: java.lang.NullPointerException: Cannot read field "declaringScope" because "outerLocalVariable" is null
[INFO] at org.eclipse.jdt.internal.compiler.lookup.BlockScope.getEmulationPath(BlockScope.java:831)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.pushLambdaExpressionLocalsIntoMethodScope(GwtAstBuilder.java:1268)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.visit(GwtAstBuilder.java:1254)
[INFO] ... 27 more
[INFO] [ERROR] at PdfVersiesView.java(273): (<no type> afdruk) -> {
[INFO] //...
[INFO] }
[INFO] org.eclipse.jdt.internal.compiler.ast.LambdaExpression
[INFO] ------------------------------------------------------------------------

It looks like the compiler is complaining about the <no type> of afdruk variable.

The actual code is
private class DownloadCell extends ActionImageResourceCell<AfdrukMetaDataResource> { public DownloadCell() { super(afdruk -> { //... }); }

After changing it to the below code (by not using lambda) resolves the compilation problem .
private class DownloadCell extends ActionImageResourceCell<AfdrukMetaDataResource> { public DownloadCell() { super(new Delegate<AfdrukMetaDataResource>() { @Override public void execute(AfdrukMetaDataResource afdruk) { //... } }); }

The parent class ActionImageResourceCell looks like this

public abstract class ActionImageResourceCell<C> extends ActionCell<C> { public ActionImageResourceCell(ActionCell.Delegate<C> delegate) { super("(ignored)", delegate); }

Regards, Koen

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

No branches or pull requests

2 participants