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

Bug 347059

Summary: org.eclipse.wst.server.core.internal.ServerWorkingCopy.save(...) unexpectedly set the Server's modules array to null
Product: [WebTools] WTP ServerTools Reporter: Raymond Lai <rkklai>
Component: wst.serverAssignee: wst.server <wst.server-inbox>
Status: NEW --- QA Contact: Angel Vera <arvera>
Severity: normal    
Priority: P3 CC: rbondi
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Full stacktrace of NPE from log
none
org.eclipse.wst.server.core.prefs before restarting eclipse
none
org.eclipse.wst.server.core.prefs none

Description Raymond Lai CLA 2011-05-24 15:04:30 EDT
Build Identifier: 

org.eclipse.wst.server.core.internal.ServerWorkingCopy.save(boolean, IProgressMonitor) will call org.eclipse.wst.server.core.internal.Server.setInternal(ServerWorkingCopy) which set the ServerWorkingCopy's modules array to the original Server's modules array. However, the ServerWorkingCopy's modules array is always null. Therefore, the org.eclipse.wst.server.core.internal.ServerWorkingCopy.save(boolean, IProgressMonitor) unexpectedly empties the Server's modules array.

Reproducible: Always
Comment 1 Richard Bondi CLA 2014-10-29 16:00:25 EDT
Created attachment 248261 [details]
Full stacktrace of NPE from log
Comment 2 Richard Bondi CLA 2014-10-29 16:10:19 EDT
Created attachment 248262 [details]
org.eclipse.wst.server.core.prefs before restarting eclipse

This is .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.server.core.prefs once a Tomcat 7 server runtime has been selected in Eclipse.
Comment 3 Richard Bondi CLA 2014-10-29 16:11:05 EDT
Created attachment 248263 [details]
org.eclipse.wst.server.core.prefs

This is .plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.server.core.prefs after restarting Eclipse. The tomcat 7 information is now gone.
Comment 4 Richard Bondi CLA 2014-10-29 16:11:27 EDT
Using:  

* Eclipse Java Web Developer Tools	3.6.1.v201409111852	org.eclipse.jst.web_ui.feature.feature.group	Eclipse Web Tools Platform

* Eclipse Luna SR1 (4.4.1)
Build id: v20141016-0854-gg6



To reproduce:
-------------
* In Eclipse, create two or more Servers via the Servers View (Right-click > New > Server, etc), with any webapp(s). Choose Tomcat 7 as your server runtime environment. It doesn't matter whether your servers use the same or a different one to reproduce this bug.
* Restart Eclipse.

Expected result:
----------------
Both servers still exist as before, unchanged.

Actual result:
--------------
One or more of the servers will have lost its "Runtime Environment". The "Runtime Environment" link is inactive. Furthermore:
* If you click the Modules tab and remove the webapp you added, then attempt to save this change, you get a NullPointerException dialog. In the .log file is this exception (full stacktrace is attached): java.lang.NullPointerException
	at org.eclipse.jst.server.tomcat.ui.internal.editor.ServerLocationEditorSection.getSaveStatus(ServerLocationEditorSection.java:534)

Workaround
----------
* Don't attempt to remove the webapp as above.
* Window > Preferences > Server > Runtime Environment
* Click Add...
* Add a tomcat 7 runtime environment (choose Apache > Apache Tomcat v7.0, Finish"
* Click OK to exit Preferences
* In Servers view, double-click a server that is missing a "Runtime Environment"
* Its "Runtime Environment" menu now contains the runtime you just added: select it.
* Repeat for each server without a "Runtime Environment"
* File > Save All

Notes:
------
What is happening when you restart Eclipse is that the .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.server.core.prefs file is being overwritten, losing all the config information in it. (Astonishingly, chmod-ing it to read only, even changing the owner, doesn't work: Eclipse just makes it writable again by the user and overwrites it!)

Two files are attached: a org.eclipse.wst.server.core.prefs before and after an Eclipse restart.