Community
Participate
Working Groups
The incorrect assignment "countTokens() = 3" in example causes a null pointer exception (Stack trace below). Note that error does not occur outside of if statement test. StringTokenizer tokeniser = new StringTokenizer( "", "" ); if ( tokeniser.countTokens() = 3 ) {} -------------------------------- An internal error occurred during: "Java AST creation". java.lang.NullPointerException org.eclipse.jdt.internal.compiler.ast.Assignment.checkAssignment (Assignment.java:67) org.eclipse.jdt.internal.compiler.ast.Assignment.resolveTypeExpecting (Assignment.java:191) org.eclipse.jdt.internal.compiler.ast.IfStatement.resolve(IfStatement.java:221) org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatement s(AbstractMethodDeclaration.java:395) org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.resolveStatements (ConstructorDeclaration.java:427) org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve (AbstractMethodDeclaration.java:373) org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve (TypeDeclaration.java:920) org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve (TypeDeclaration.java:969) org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve (CompilationUnitDeclaration.java:280) org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve (CompilationUnitResolver.java:436) org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve (CompilationUnitResolver.java:313) org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:657) org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:574) org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST (ASTProvider.java:441) org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:393) org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList enerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:159) org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run (SelectionListenerWithASTManager.java:136) org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
I will investigate.
This seems to be a regression in the compiler due to 1.5 work. The following code doesn't compile anymore. import java.util.StringTokenizer; public class A { public void foo() { StringTokenizer tokeniser = new StringTokenizer( "", "" ); if ( tokeniser.countTokens() = 3 ) {} } } I will attach a patch.
Created attachment 13452 [details] Apply on HEAD
Philippe, Could you please review the patch? Thanks. With this patch the AST creation doesn't fail anymore.
The expected error is: ---------- 1. ERROR in C:\tests_sources\A.java (at line 6) if ( tokeniser.countTokens() = 3 ) {} ^^^^^^^^^^^^^^^^^^^^^^^ The left-hand side of an assignment must be a variable ---------- 1 problem (1 error)
Fix looks good. Please apply it.
Fixed and released in HEAD. Regression test added.
*** Bug 70981 has been marked as a duplicate of this bug. ***
*** Bug 71373 has been marked as a duplicate of this bug. ***