Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343301

Summary: NPE working with array initializer
Product: [WebTools] JSDT Reporter: Benjamin Reed <ranger>
Component: GeneralAssignee: Nitin Dahyabhai <thatnitind>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: major    
Priority: P3 CC: cbridgha, cmjaun, david_williams, nsand.dev
Version: 3.2.3Flags: david_williams: pmc_approved+
thatnitind: pmc_approved? (raghunathan.srinivasan)
thatnitind: pmc_approved? (naci.dai)
thatnitind: pmc_approved? (deboer)
thatnitind: pmc_approved? (neil.hauge)
thatnitind: pmc_approved? (kaloyan)
cbridgha: pmc_approved+
cmjaun: review+
Target Milestone: 3.2.4   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard: PMC_approved
Attachments:
Description Flags
proposed patch none

Description Benjamin Reed CLA 2011-04-19 14:32:19 EDT
Build Identifier: M20110210-1200

I'm attempting to edit opennms-webapp/src/main/webapp/WEB-INF/tags/form/input.tag in the OpenNMS codebase, and I get an NPE when it tries to build.

Error
Tue Apr 19 14:26:36 EDT 2011
Errors running builder 'JavaScript Validator' on project 'opennms-webapp'.

java.lang.NullPointerException
	at org.eclipse.wst.jsdt.internal.compiler.ast.ConditionalExpression.analyseCode(ConditionalExpression.java:50)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ArrayInitializer.analyseCode(ArrayInitializer.java:42)
	at org.eclipse.wst.jsdt.internal.compiler.ast.LocalDeclaration.analyseCode(LocalDeclaration.java:73)
	at org.eclipse.wst.jsdt.internal.compiler.ast.Block.analyseCode(Block.java:48)
	at org.eclipse.wst.jsdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:91)
	at org.eclipse.wst.jsdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:93)
	at org.eclipse.wst.jsdt.internal.compiler.ast.AbstractMethodDeclaration.analyseCode(AbstractMethodDeclaration.java:109)
	at org.eclipse.wst.jsdt.internal.compiler.ast.FunctionExpression.analyseCode(FunctionExpression.java:73)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteralField.analyseCode(ObjectLiteralField.java:78)
	at org.eclipse.wst.jsdt.internal.compiler.ast.ObjectLiteral.analyseCode(ObjectLiteral.java:97)
	at org.eclipse.wst.jsdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:86)
	at org.eclipse.wst.jsdt.internal.compiler.ast.FieldReference.analyseAssignment(FieldReference.java:91)
	at org.eclipse.wst.jsdt.internal.compiler.ast.Assignment.analyseCode(Assignment.java:63)
	at org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:155)
	at org.eclipse.wst.jsdt.internal.compiler.Compiler.process(Compiler.java:589)
	at org.eclipse.wst.jsdt.internal.compiler.Compiler.compile(Compiler.java:347)
	at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:288)
	at org.eclipse.wst.jsdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:86)
	at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:227)
	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:629)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:203)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:255)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:258)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:311)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:343)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:242)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


Reproducible: Always

Steps to Reproduce:
1. My Eclipse is set up as documented in http://www.opennms.org/wiki/Eclipse, although I also installed the latest web tools as well
2. git clone git://opennms.git.sourceforge.net/gitroot/opennms/opennms
3. Import -> Existing Maven Projects -> browse to "opennms-webapps"
4. Depending on how your m2eclipse is set up: Maven -> Update Project Configuration
Comment 1 Nitin Dahyabhai CLA 2011-04-19 17:59:30 EDT
Seems to be triggered by a conditional expression :
(((typeof e.labelSeparator) == "undefined") ? this.labelSeparator : e.labelSeparator)
on this condition:
((typeof e.labelSeparator) == "undefined")
Comment 2 Nitin Dahyabhai CLA 2011-04-20 20:38:46 EDT
Created attachment 193770 [details]
proposed patch

When resolving the types (and assigning the optimized constants) for array contents, failure to resolve a type for one of the initial contents results in the remainder not even trying to complete resolution.  This leads to the NPE later on.
Comment 3 Nitin Dahyabhai CLA 2011-04-22 14:46:10 EDT
*Explain why you believe this is a stop-ship defect.

Errors when running a builder can prevent the project from being marked as "built" by that builder.  It may be triggered repeatedly on resource changes only to then keep failing.

*Is there a work-around?

Only by placing the troublesome file in a library instead of a source folder, but we don' get to dictate that to our users.

*How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added?

Ad-hoc tested.

*Give a brief technical overview. Who has reviewed this fix?

When performing the analysis step for an ArrayInitializer, it expects the constant values have all already been computed by the previous resolve step of compilation.  A but in the ArrayInitializer class prevented it from iterating through all of the array contents if one element didn't resolve its type as expected, the resolution step also being expected to have determined whether that element is or is not a constant.  The later elements in the array then aren't resolved nor have their constant values determined at all.  Chris has reviewed the change.

*What is the risk associated with this fix?

Low.  The looping algorithm is calling other methods on the elements to have them do work.  Returning from the method early in the loop when the loop's purpose isn't to "find" a particular element or value is a pretty clear mistake.
Comment 4 Chuck Bridgham CLA 2011-04-22 15:58:45 EDT
looks good - I assume Not returning null won't change any caller's behavior.
Comment 5 Nitin Dahyabhai CLA 2011-04-22 20:22:44 EDT
Released.