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

Bug 347887

Summary: Multithreading issue in InternalPlatform.getContentTypeManager leads to NullpointerException in org.eclipse.emf.ecore.resource.impl.PlatformContentHandlerImpl
Product: [Eclipse Project] Platform Reporter: Andreas Buehler <abuehler>
Component: RuntimeAssignee: platform-runtime-inbox <platform-runtime-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: critical    
Priority: P3 CC: pwebster, remy.suen
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Stacktrace of the NullPointerException none

Description Andreas Buehler CLA 2011-06-01 04:16:24 EDT
Build Identifier: 3.6.0

We use the Eclipse RCP platform in a highly concurrent environment.
Sometimes our application throws a NullPointerException shortly after it's being started - which is not really reproducible in a safe way.

The stacktrace issues a NullPointer in this line: org.eclipse.emf.ecore.resource.impl.PlatformContentHandlerImpl.contentDescription(PlatformContentHandlerImpl.java:92)

After investigating the source code, I came to the conclusion that the only way a NullPointer could happen is that the InternalPlatform.getContentTypeManager returns null.

I believe the lazy initialisation in this method is not threadsafe and therefore this issue occures.

Thread A recognizes the contentTracker as null and instantiates the member.
but between the class instantiation of the Service Tracker and the call to "open()" Thread B recognizes the member variable beeing set and jumps to the end of the method, calling getService() on the "at this point" not opened service tracker. 
The service tracker itself will return null in case it's not yet being opened :-(


Reproducible: Sometimes

Steps to Reproduce:
1. Access Platform.getContentTypeManager simultaneously in multiple threads
2.
3.
Comment 1 Andreas Buehler CLA 2011-06-01 04:18:30 EDT
Created attachment 197064 [details]
Stacktrace of the NullPointerException

The attachments shows the Nullpointer, which is caused by the Platform.getContentTypeManager not being threadsafe
Comment 2 DJ Houghton CLA 2011-09-21 13:33:27 EDT
I believe this is a duplicate of bug 356306.
Please re-open if you are still seeing this behaviour in recent builds.
Thanks.

*** This bug has been marked as a duplicate of bug 356306 ***