Community
Participate
Working Groups
We're seeing NPE's in our adopter product at start up when trying to get structured models for JSPs from the SSE ModelManagerImpl. The root cause is a race condition between threads in the CommentElementRegistry.getConfigurations() method. CommentElementRegistry.getConfigurations() is not thread safe. The problem occurs when getting structured models for two different pages in separate threads. If both pages contain comments, then during the creation of the model parsing will end up in XMLModelParser.createCommentElement() and call CommentElementRegistry.getInstance().getConfigurations(). If both threads enter this at the same time the value of fConfigurations will be null and both threads will begin to construct the array for this value. The first thread will create an empty array of the desired length, assign it to the fConfigurations field, then populate it. Then just before it returns the fConfigurations field, the second thread creates an empty array and assigns it to fConfigurations. The first thread returns this empty array before it is populated and XMLModelParser.createCommentElement() gets the first CommentElementConfiguration element in the array, which is null, and tries to call methods on the null config causing the NPE. Here's the stack trace from error log file... !ENTRY org.eclipse.wst.xml.core 4 4 2011-09-21 14:44:51.484 !MESSAGE null !STACK 0 java.lang.NullPointerException at org.eclipse.wst.xml.core.internal.document.XMLModelParser.createCommentElement(XMLModelParser.java:737) at org.eclipse.wst.xml.core.internal.document.XMLModelParser.insertComment(XMLModelParser.java:945) at org.eclipse.wst.xml.core.internal.document.XMLModelParser.insertStructuredDocumentRegion(XMLModelParser.java:1516) at org.eclipse.wst.xml.core.internal.document.XMLModelParser.replaceStructuredDocumentRegions(XMLModelParser.java:2354) at org.eclipse.wst.xml.core.internal.document.DOMModelImpl.internalSetNewDocument(DOMModelImpl.java:661) at org.eclipse.wst.xml.core.internal.document.DOMModelImpl.setStructuredDocument(DOMModelImpl.java:936) at org.eclipse.wst.sse.core.internal.model.AbstractModelLoader.createModel(AbstractModelLoader.java:127) at org.eclipse.wst.sse.core.internal.FileBufferModelManager.getModel(FileBufferModelManager.java:725) at org.eclipse.wst.sse.core.internal.FileBufferModelManager.getModel(FileBufferModelManager.java:685) at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl._doCommonGetModel(ModelManagerImpl.java:544) at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl._commonGetModel(ModelManagerImpl.java:508) at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl._commonGetModel(ModelManagerImpl.java:481) at org.eclipse.wst.sse.core.internal.model.ModelManagerImpl.getModelForRead(ModelManagerImpl.java:1419) ...
Thanks for the detailed analysis, Carlin! I've synchronized the method to prevent the race condition. Excellent find!