This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 330194 - NPE in nightly in internalGetReferencedBuildConfigs
Summary: NPE in nightly in internalGetReferencedBuildConfigs
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: James Blackburn CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-14 06:37 EST by James Blackburn CLA
Modified: 2010-11-26 09:32 EST (History)
4 users (show)

See Also:
Szymon.Brandys: review+


Attachments
fix v1 (4.58 KB, patch)
2010-11-15 12:16 EST, James Blackburn CLA
Szymon.Brandys: iplog+
Details | Diff
patch 2 + test (11.87 KB, patch)
2010-11-16 04:14 EST, James Blackburn CLA
Szymon.Brandys: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2010-11-14 06:37:26 EST
One of the nightly tests failed with an NPE:
http://download.eclipse.org/eclipse/downloads/drops/N20101113-2000/testresults/html/org.eclipse.pde.api.tools.tests_macosx.cocoa.x86_5.0.html

java.lang.NullPointerException
at org.eclipse.core.internal.resources.Project.internalGetReferencedBuildConfigurations(Project.java:843)
at org.eclipse.core.internal.resources.Workspace.computeActiveBuildConfigurationOrder(Workspace.java:711)
at org.eclipse.core.internal.resources.Workspace.getBuildOrder(Workspace.java:1592)
at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:415)
at org.eclipse.jdt.core.tests.builder.TestingEnvironment.fullBuild(TestingEnvironment.java:464)
at org.eclipse.jdt.core.tests.builder.BuilderTests.fullBuild(BuilderTests.java:390)
at org.eclipse.pde.api.tools.builder.tests.compatibility.BundleVersionTests.setupTest(BundleVersionTests.java:157)
at org.eclipse.pde.api.tools.builder.tests.compatibility.BundleVersionTests.test003(BundleVersionTests.java:227)
at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:377)
at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:210)
at org.eclipse.test.CoreTestApplication.runTests(CoreTestApplication.java:36)
Comment 1 James Blackburn CLA 2010-11-14 06:57:43 EST
The 3 other test failures in org.eclipse.pde.api.tools.tests also look new.
Comment 2 Szymon Brandys CLA 2010-11-15 04:18:06 EST
(In reply to comment #1)
> The 3 other test failures in org.eclipse.pde.api.tools.tests also look new.

test328464 is my fault. I enabled this test accidentally. Pawel P. should have fixed bug 329836 first.
Comment 3 James Blackburn CLA 2010-11-15 11:31:29 EST
The NPE can only happen if getAllBuildConfigReferences() returns null.  AFAICS this can only happen due to concurrent access (no memory barrier between the cache read + write as well as no protection for concurrent cache update).

A more interesting problem is that the PDE tests modify the dynamic order during the pre-build listener.  Workspace.build will then go wrong as we're calculating the order before notifying pre-build.  This is an interesting regression and definitely needs a test.
Comment 4 Michael Rennie CLA 2010-11-15 11:55:03 EST
After running the API tools tests locally on N20101114-2000, I found a pile of console entries like:

"The project cannot be built until its prerequisite exportedbundle is built. Cleaning and building all projects is recommended"

that accompany the NPE / 'Should not be a JDT error' failures. 

This would seem to confirm comment#3.
Comment 5 James Blackburn CLA 2010-11-15 12:16:46 EST
Created attachment 183142 [details]
fix v1

Fix for the issue. Move build order calculation for Workspace#build after the pre-build notification.  The buildOrder calculation is now done within the ws lock. 

PDE tests now pass, as do core.resources builder tests.

Looks like some additional synchronization on the build config reference cache is needed to guard against outside callers of IProject#getReferencedBuildConfigurations and IProject#getReferencedProjects
Comment 6 Szymon Brandys CLA 2010-11-15 13:40:53 EST
The fix is in HEAD.
Comment 7 James Blackburn CLA 2010-11-16 04:14:06 EST
Created attachment 183197 [details]
patch 2 + test

- Add a test that checks changing build order in the pre build notification works for both API IWorkspace#build and Auto build.

- Ensure that the ProjectDesc Build configuration cache is correctly synchronized.  This cache is lazy populated on get (this path isn't necessarily locked by the WS lock).  Consequently we the data-structure is vulnerable to concurrent modification.

- Tidy the Workspace#build moving the remaining implementation into buildInternal so it's less confusing what's going on. 

- Minor non-Javadoc and argument order tweak.
Comment 8 Szymon Brandys CLA 2010-11-16 05:44:16 EST
James, I will commit the fix after the IBuild today.
Comment 9 Szymon Brandys CLA 2010-11-26 09:32:17 EST
The fix is in HEAD.