Bug 283670 - [exceptions] NullPointerException in org.eclipse.wst.jsdt.internal.compiler.ast.ConditionalExpression.resolveType
Summary: [exceptions] NullPointerException in org.eclipse.wst.jsdt.internal.compiler.a...
Status: RESOLVED WORKSFORME
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 3.2.1   Edit
Assignee: Ian Tewksbury CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2009-07-16 04:18 EDT by Nick Clarke CLA
Modified: 2010-09-24 09:26 EDT (History)
4 users (show)

See Also:


Attachments
File containing the failing statement (13.81 KB, text/plain)
2010-04-17 08:50 EDT, Thomas Hallgren CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clarke CLA 2009-07-16 04:18:48 EDT
My javascript-containing project (Faceted project with java and javascript) fails to build, logging the following error about JavaScript Validator.

Sometimes it works (and manages to mark things like missing semicolons), sometimes it throws this error (and does not mark those errors).

Warning
Thu Jul 16 19:56:09 NZST 2009
Errors running builder 'JavaScript Validator' on project '<my-project-name>'.

java.lang.NullPointerException
	at org.eclipse.wst.jsdt.internal.compiler.ast.ConditionalExpression.resolveType(ConditionalExpression.java:199)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteralField.resolveType(ObjectLiteralField.java:70)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteral.resolveType(ObjectLiteral.java:80)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteralField.resolveType(ObjectLiteralField.java:70)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteral.resolveType(ObjectLiteral.java:80)
	at org.eclipse.wst.jsdt.internal.compiler.ast.Assignment.resolveType(Assignment.java:161)
	at org.eclipse.wst.jsdt.internal.compiler.ast.Expression.resolve(Expression.java:745)
	at org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:402)
	at org.eclipse.wst.jsdt.internal.compiler.Compiler.process(Compiler.java:596)
	at org.eclipse.wst.jsdt.internal.compiler.Compiler.compile(Compiler.java:356)
	at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:311)
	at org.eclipse.wst.jsdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:168)
	at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:248)
	at org.eclipse.wst.jsdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:58)
	at org.eclipse.wst.jsdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:291)
	at org.eclipse.wst.jsdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:199)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:627)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

eclipse.buildId=I20090611-1540
java.version=1.6.0_14
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_NZ
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86 -product org.eclipse.epp.package.jee.product


-- Configuration Details --
Product: Eclipse 1.2.0.20090618-0904 (org.eclipse.epp.package.jee.product)
Installed Features:
 org.eclipse.platform 3.5.0.v20090611a-9gEeG1HFtQcmRThO4O3aR_fqSMvJR2sJ
Comment 1 Chris Jaun CLA 2009-07-20 15:57:52 EDT
Nick,

Please include steps to reproduce your bug. Providing sample code is the best way to do so.

Thanks,
Chris

Comment 2 Chris Jaun CLA 2009-09-15 13:39:18 EDT
Categorizing JSDT bugzillas for planning purposes.
Comment 3 Jacek Pospychala CLA 2009-11-27 09:38:07 EST
For the sake of documentation: ConditionalExpression, where exception is thrown represents an expression like "condition ? valueIfTrue : valueIfFalse".
The exception seems to be thrown in following line (199):

constant = condConstant.booleanValue() ? trueConstant : falseConstant;

only candidate for NPE in this line is condConstant, because it's method is called.
condConstant value is initialized in following assignment in line 194:
 
condConstant = condition.constant 

So condition.constant must be null at that point. Condition.constant should be initialized in condition.resolveTypeExpecting(scope, TypeBinding.BOOLEAN) called in line 142. resolveTypeExpecting(...) basically calls Expression.resolveType(scope) which has many different implementations for all various types of expressions (literal, assignment, reference, etc.). I can't see any Expression subtype that would not 
initialize this.condition in the first few lines, so I can't find out why does this NullPointerException happens :-P

Any sample javascript source code that exhibits this issue would be welcome... :-)
Comment 4 Thomas Hallgren CLA 2010-04-17 08:50:29 EDT
Created attachment 165179 [details]
File containing the failing statement

I get this too. The condition is a FieldReference and the expression looks like this.

 (YAHOO.util.DragDrop ? true : false)

The culprit file is attached.

I managed to get around the problem by changing line 195 from:

 constant = condConstant.booleanValue() ? trueConstant : falseConstant;

to:

 constant = (condConstant != null && condConstant.booleanValue()) ? trueConstant : falseConstant;
Comment 5 Chris Jaun CLA 2010-06-21 15:37:50 EDT
I can't reproduce this and the original defect was opened with a build ID over a year old.
Comment 6 Marco Schoolenberg CLA 2010-09-23 23:09:59 EDT
I am trying to get an open source project to build. 
jadaSite... It's a webshop. I downloaded the WAR and imported it. At the moment it Starts the Java Script Validation I get load of these missing semicolons And then in eclipse popup.
Errors occurred during the build.
Errors running builder 'JavaScript Validator' on project 'jada'.
java.lang.NullPointerException

Could it be the Script Validator used to except something which it doesn't anymore?
Comment 7 Chris Jaun CLA 2010-09-24 09:26:07 EDT
(In reply to comment #6)
> I am trying to get an open source project to build. 
> jadaSite... It's a webshop. I downloaded the WAR and imported it. At the moment
> it Starts the Java Script Validation I get load of these missing semicolons And
> then in eclipse popup.
> Errors occurred during the build.
> Errors running builder 'JavaScript Validator' on project 'jada'.
> java.lang.NullPointerException
> 
> Could it be the Script Validator used to except something which it doesn't
> anymore?



Marco,

This bugzilla is not the appropriate place to ask your question.

If you feel you have found a defect please open a new bug and include a full stack trace. If possible include the files needed or steps to reproduce the problem.

Chris