Bug 70398 - Java AST creation error due to NullPointerException in IF statement test block.
Summary: Java AST creation error due to NullPointerException in IF statement test block.
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 70981 71373 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-07-20 04:19 EDT by Dan de Vries CLA
Modified: 2005-01-11 11:03 EST (History)
2 users (show)

See Also:


Attachments
Apply on HEAD (718 bytes, patch)
2004-07-20 14:42 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dan de Vries CLA 2004-07-20 04:19:20 EDT
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)
Comment 1 Olivier Thomann CLA 2004-07-20 09:52:30 EDT
I will investigate.
Comment 2 Olivier Thomann CLA 2004-07-20 14:40:48 EDT
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.
Comment 3 Olivier Thomann CLA 2004-07-20 14:42:19 EDT
Created attachment 13452 [details]
Apply on HEAD
Comment 4 Olivier Thomann CLA 2004-07-20 14:43:07 EDT
Philippe,

Could you please review the patch? Thanks.

With this patch the AST creation doesn't fail anymore.
Comment 5 Olivier Thomann CLA 2004-07-20 14:43:33 EDT
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)
Comment 6 Philipe Mulet CLA 2004-07-20 16:13:40 EDT
Fix looks good. Please apply it.
Comment 7 Olivier Thomann CLA 2004-07-20 16:28:09 EDT
Fixed and released in HEAD.
Regression test added.
Comment 8 Olivier Thomann CLA 2004-07-28 11:37:55 EDT
*** Bug 70981 has been marked as a duplicate of this bug. ***
Comment 9 Olivier Thomann CLA 2004-08-04 13:33:19 EDT
*** Bug 71373 has been marked as a duplicate of this bug. ***