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

Bug 318492

Summary: NullPointerException in WTP Tomcat when project is recompiled
Product: [WebTools] WTP ServerTools Reporter: Howard Lee <howardtzelee>
Component: jst.serverAssignee: Larry Isaacs <larryisaacs>
Status: RESOLVED FIXED QA Contact: Angel Vera <arvera>
Severity: normal    
Priority: P3 CC: fgiust, kenneth.chenis, mariano.fernandez, patric, thatnitind
Version: 3.2Flags: arvera: review+
Target Milestone: 3.2.2   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/108977
Whiteboard:
Attachments:
Description Flags
Eclipse configuration information none

Description Howard Lee CLA 2010-06-30 12:01:48 EDT
Build Identifier: 20100617-1415

java.lang.NullPointerException
	at org.eclipse.jst.server.tomcat.loader.WtpDirContext.file(WtpDirContext.java:209)
	at org.apache.naming.resources.FileDirContext.lookup(FileDirContext.java:206)
	at org.eclipse.jst.server.tomcat.loader.WtpDirContext.lookup(WtpDirContext.java:289)
	at org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:299)
	at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2601)
	at org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:1088)
	at org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1310)
	at org.apache.catalina.loader.WebappClassLoader.clearReferencesJdbc(WebappClassLoader.java:1797)
	at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1740)
	at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1658)
	at org.apache.catalina.loader.WebappLoader.stop(WebappLoader.java:710)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4649)
	at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3222)
	at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:403)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:595)


Reproducible: Always
Comment 1 Angel Vera CLA 2010-06-30 16:15:03 EDT
At first I wasn't so certain this belongs to us but I then was able to find org.eclipse.jst.server.tomcat.runtime.xx.loader.jar inside of out org.eclipse.jst.server.tomcat.core plugin.

I am not sure how they get build but Larry over to you.
Comment 2 Larry Isaacs CLA 2010-06-30 16:49:53 EDT
This is likely part of Tomcat's "leak prevention" code, which may be tricky to program around.  I'll have to investigate to see what my options are.  Regardless, it would be helpful to know which version of Web Tools and Tomcat you are using.
Comment 3 Howard Lee CLA 2010-07-01 14:55:17 EDT
Created attachment 173251 [details]
Eclipse configuration information
Comment 4 Howard Lee CLA 2010-07-01 15:00:17 EDT
(In reply to comment #2)
> This is likely part of Tomcat's "leak prevention" code, which may be tricky to
> program around.  I'll have to investigate to see what my options are. 
> Regardless, it would be helpful to know which version of Web Tools and Tomcat
> you are using.

I'm using Helios Eclipse J2EE, which appears to use WTP 3.2 (see uploaded configuration for additional details). Using Tomcat 6.0.26 (JDK 1.6 32-bit Windows). I did not have this problem with Eclipse 3.5.2.
Comment 5 Ken Chenis CLA 2010-08-03 08:46:34 EDT
I too get this error, and it is 100% reproducable, however my stack trace is different, and I only get this when publishing if I set "Server modules without publishing" - if enabled I get this error always, if disabled, no error:


!ENTRY org.eclipse.jst.server.tomcat.core 4 0 2010-08-02 17:34:06.425
!MESSAGE Could not publish server configuration: null.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.wst.common.componentcore.internal.resources.VirtualContainer.createVirtualResource(VirtualContainer.java:355)
	at org.eclipse.wst.common.componentcore.internal.resources.VirtualContainer.getResources(VirtualContainer.java:338)
	at org.eclipse.jst.server.tomcat.core.internal.TomcatPublishModuleVisitor.endVisitWebComponent(TomcatPublishModuleVisitor.java:293)
	at org.eclipse.jst.server.tomcat.core.internal.wst.ModuleTraverser.traverseWebComponent(ModuleTraverser.java:220)
	at org.eclipse.jst.server.tomcat.core.internal.wst.ModuleTraverser.traverse(ModuleTraverser.java:117)
	at org.eclipse.jst.server.tomcat.core.internal.TomcatVersionHelper.updateContextsToServeDirectly(TomcatVersionHelper.java:854)
	at org.eclipse.jst.server.tomcat.core.internal.Tomcat60Configuration.updateContextsToServeDirectly(Tomcat60Configuration.java:686)
	at org.eclipse.jst.server.tomcat.core.internal.TomcatServerBehaviour.publishFinish(TomcatServerBehaviour.java:454)
	at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:954)
	at org.eclipse.wst.server.core.model.ServerBehaviourDelegate.publish(ServerBehaviourDelegate.java:775)
	at org.eclipse.wst.server.core.internal.Server.publishImpl(Server.java:2888)
	at org.eclipse.wst.server.core.internal.Server$PublishJob.run(Server.java:337)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


Eclipse: Helios Release 20100617-1415
Tomcat: 6.0.28
Java: JDK 1.6.0_21 X64 
Startup Command Line: start eclipse.exe -data ..\..\Data\WorkSpace -vm ..\jdk\bin\javaw -vmargs -Xmx1024M -Xms512M -XX:MaxPermSize=256M
OS: Windows 7 Enterprise
Comment 6 Larry Isaacs CLA 2010-08-04 15:46:23 EDT
Ken,

This bug is referring to an NPE which is occurring in the running Tomcat where yours is occurring within Eclipse.  Please open a separate bug for your problem.  It wouldn't hurt to attach the ".settings/org.eclipse.wst.common.component" file from the project so I can see if there is anything unusual that would lead to your NPE.

Larry
Comment 7 Fabrizio Giustina CLA 2010-08-09 06:32:10 EDT
I am getting exactly the same NPE, and it looks like it's due to WtpDirContext trying to accessing a non-existing WEB-INF/classes dir.
For some reason here the WEB-INF/classes seems to be added to the classpath checked by the tomcat loader, although it shoudn't.

In my org.eclipse.wst.common.component I have two entries which refer to WEB-INF/classes:

    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>

Anyway, when "serve modules without publishing" is enabled the deploy path specified there should not be used as a real classpath entry.

HTH
Comment 8 Ken Chenis CLA 2010-08-09 11:01:09 EDT
I upgraded WTP to 3.2.1 and this problem has vanished for me.  So I'm not going to open a new bug as Larry suggested at this would not be reproduced with the latest version.  Thanks for the help.
Comment 9 Larry Isaacs CLA 2010-08-17 11:07:48 EDT
The problem is that in recent versions of Tomcat 6.0.x, reloading of a context is calling the release() method on the WtpDirContext, which nulls its instance fields, then later tries to use the WtpDirContext to load a class as part of the "leak prevention" handling.  As written, WtpDirContext isn't written for this use case since it assumed that once release() was called, it wouldn't be used.  It appears the "quirk" of calling release() and then trying to use the WtpDirContext has been fixed in Tomcat 7.0.x, as I don't see the NPE there.  The solution is to add enough null checking to respond appropriately if WtpDirContext is used after release() has been called.

Angel,

I have new source zips (i.e. org.eclipse.jst.server.tomcat.runtime.NN.loader-src.zip files) and custom jars (i.e. org.eclipse.jst.server.tomcat.runtime.NN.loader.jar files) ready to commit to address this.  I would like to include this in WTP 3.2.2 as it does interfere with Tomcat "leak prevention" code.  I have made the same updates for all versions of Tomcat just for consistency.  Since this is custom Tomcat code, I don't have diffs to show what changed.  However, the changes were all simple null checks.  I can attach one of the source zips if you like.  If you approve, I'll commit to WTP 3.2.2 in addition to WTP 3.3.  Thanks.

Fabrizio,

The info you cite isn't the cause of the NPE.  Once I commit the updated jar, you should be able to download one from CVS and replace the one Tomcat is using.  That should get rid of the NPE.  It there is still an issue related to a non-existent "WEB-INF/classes" on the classpath, ask on the WTP newsgroup or open a separate bug so we can look into it.  Thanks.


General FYI: Ken's problem was Bug 317834 which was fixed in WTP 3.2.1.
Comment 10 Angel Vera CLA 2010-08-17 16:34:01 EDT
More null checks are always good, so I am okay with that. 

What is not clear is what will happend in the case that is null. What is the correct behaviour? will this function simply failed (ie. nothing will happen) or will there be a gracious error?
Comment 11 Larry Isaacs CLA 2010-08-18 09:41:59 EDT
I would say the behavior of these Tomcat "naming context" classes, like our WtpDirContext, is technically undefined after the release() method is called.  However, it's fairly clear what would be more graceful than throwing an NPE in the various methods, typically returning null or throwing a NamingException.  With these changes, anything that goes wrong will be Tomcat's fault and not the fault of our custom class because it threw and unexpected NPE.  Since it's a Tomcat bug that it is calling release() and then using the WtpDirContext, it's likely that this bug's NPE is the only one that would occur.  With these changes, I believe Tomcat's "leak prevention" code would be able to continue normally.  I addressed all possible NPE's just to be on the safe side.
Comment 12 Angel Vera CLA 2010-08-18 09:53:34 EDT
Thanks for the extra explanation. I approve
Comment 13 Larry Isaacs CLA 2010-08-20 21:15:23 EDT
Changes released to WTP 3.2.2 and HEAD.

The updated Tomcat 6.0.x version of the custom jar can be downloaded using:

http://dev.eclipse.org/viewcvs/index.cgi/servertools/plugins/org.eclipse.jst.server.tomcat.core/org.eclipse.jst.server.tomcat.runtime.60.loader.jar?revision=1.3.2.1&root=WebTools_Project

Overwrite the one that was copied to the Tomcat 6.0.x installation.
Comment 14 Mariano Eloy Fernández Osca CLA 2010-09-18 07:38:43 EDT
*** Bug 325671 has been marked as a duplicate of this bug. ***
Comment 15 Eclipse Genie CLA 2017-10-11 16:34:16 EDT
New Gerrit change created: https://git.eclipse.org/r/108977