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

Bug 359512

Summary: NullPointerException in TaglibIndex due to race condition.
Product: [WebTools] WTP Source Editing Reporter: Andrew McCulloch <Andrew.McCulloch>
Component: jst.jspAssignee: Nick Sandonato <nsand.dev>
Status: RESOLVED FIXED QA Contact: Nick Sandonato <nsand.dev>
Severity: normal    
Priority: P3 CC: Andrew.McCulloch, raghunathan.srinivasan, thatnitind
Version: 3.3.1   
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Andrew McCulloch CLA 2011-09-30 01:41:58 EDT
Build Identifier: M20110909-1335

TaglibIndex is not thread safe which can result in an NPE.

	void fireCurrentDelta(Object trigger) {
		if (fCurrentTopLevelDelta != null) {
			fCurrentTopLevelDelta.trigger = trigger;
			ITaglibIndexDelta delta = fCurrentTopLevelDelta;
			fCurrentTopLevelDelta = null;
			fireTaglibDelta(delta);
		}
	}

... is not protected against multiple thread access so it is possible that fCurrentTopLevelDelta will be non-null when 2 threads enter the 'if' block and be subsequently set to null by the first thread before the second thread executes the statement 'ITaglibIndexDelta delta = fCurrentTopLevelDelta;'.  This would cause a NullPointerException in fireTaglibDelta(delta) since delta will be null.

Reproducible: Sometimes

Steps to Reproduce:
This is a race condition and I have only had the NPE logged once after thousands of executions.
Comment 1 Nick Sandonato CLA 2011-10-11 16:32:30 EDT
Nice catch, Andrew. Thanks for the report! I've synchronized the code in that block.