This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 57981 - Open 4.0 project throws NPE
Summary: Open 4.0 project throws NPE
Status: CLOSED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Web Project (show other bugs)
Version: 4.x
Hardware: All All
: P1 blocker (vote)
Assignee: Pavel Buzek
URL:
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2005-04-18 13:26 UTC by zikmund
Modified: 2006-03-24 13:01 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
java.lang.NullPointerException at org.netbeans.modules.web.project.UpdateHelper.saveUpdate(UpdateHelper.java:302) (2.35 KB, text/plain)
2005-04-18 13:28 UTC, zikmund
Details

Note You need to log in before you can comment on or make changes to this bug.
Description zikmund 2005-04-18 13:26:58 UTC
Build 200504171930

1) Open 4.0 Web project
2) project's context menu | Resolve missing reference
3) Upgrade project
4) ERROR:
Broken reference window doesn't appear. NPE is thrown (see attachment)
Comment 1 zikmund 2005-04-18 13:28:10 UTC
Created attachment 21700 [details]
java.lang.NullPointerException at org.netbeans.modules.web.project.UpdateHelper.saveUpdate(UpdateHelper.java:302)
Comment 2 zikmund 2005-04-18 13:37:32 UTC
Any library, project or JAR file (which were on the 4.0 project's classpath) are
not packaged into WAR file until you modify project's Properties. Although they
are part of the build/clean targets.
Comment 3 zikmund 2005-04-18 14:50:53 UTC
After creating test directory in 4.0 project structure, there are still no
default Compile/Tun Tests classpath items in project's properties. I think it is
a consequence of this NPE. If not, I'll file a new issue.
Comment 4 Pavel Buzek 2005-04-18 18:57:13 UTC
The "updateListener" is supposed to remove servlet api and jsp api libraries.
How is it ensured that WebProjectProperties are created before this is called??
I think this code relied on WebProject creating WPP when open, which was removed
because it caused performance problems. That would explain the regression -- is
it know when this last worked?

Anyway, there is code in UpdateHelper that seems to remove these libraries. I am
testing with 40 project and it works ok, so I removed the problematic (and
seemingly useless) code. But it is strange that the code that removes the
libraries in WPP was added in the same version as the code in UpdateHelper that
does this so maybe I am missing something. Adding Marek to comment.

Checking in src/org/netbeans/modules/web/project/UpdateHelper.java;
/cvs/web/project/src/org/netbeans/modules/web/project/UpdateHelper.java,v  <-- 
UpdateHelper.java
new revision: 1.15; previous revision: 1.14
done
Checking in
src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java;
/cvs/web/project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java,v
 <--  WebProjectProperties.java
new revision: 1.91; previous revision: 1.90
done
Comment 5 Marek Fukala 2005-04-19 08:48:55 UTC
The code wasn't useless :-). It handles a situation when an user opens a 4.0
project, opens project properties, do some changes and then close the dialog. In
such a case the WebProjectProperties caches the libraries data in a memory model
and then, when user closes the dialog and confirms project upgrade, it saves the
data from memory and rewrites the updated ones. It is possible that there is a
much more elegant solution to this problem than the "updateListener" hack, but
it works. 

As Pavel correctly pointed out the problem is that when WebProjectProperties
instance is not created and the UpdateHelper is asked to upgrade project, then
the "updateListener" is not registered and hence the code throws the reported
NPE. IMO the minimal sufficient fix is to check the listener not to be null.

Steps to reproduce the problem with not removed libraries after Pavel's commit:
1) open a 4.0 project
=> broken references warning dialog appears
2) close it
3) open project properties and go to libraries
4) close the project props. dialog
=> project upgrade dialog appears
5) choose upgrade project
=> servlet24 and jsp20 libraries are not removed
Comment 6 zikmund 2005-04-19 08:55:06 UTC
The regression came in time 0321-0328 - I suspect issue 56844 fix.
Comment 7 Marek Fukala 2005-04-19 09:03:37 UTC
reverted Pavel's commit and fixed

Checking in src/org/netbeans/modules/web/project/UpdateHelper.java;
/cvs/web/project/src/org/netbeans/modules/web/project/UpdateHelper.java,v  <-- 
UpdateHelper.java
new revision: 1.16; previous revision: 1.15
done
Checking in
src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java;
/cvs/web/project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java,v
 <--  WebProjectProperties.java
new revision: 1.92; previous revision: 1.91
done


cvs diff -r1.14 UpdateHelper.java

Index: UpdateHelper.java
===================================================================
RCS file: /cvs/web/project/src/org/netbeans/modules/web/project/UpdateHelper.java,v
retrieving revision 1.14
retrieving revision 1.16
diff -u -r1.14 -r1.16
--- UpdateHelper.java   25 Mar 2005 09:59:46 -0000      1.14
+++ UpdateHelper.java   19 Apr 2005 08:00:16 -0000      1.16
@@ -299,7 +299,7 @@
         }

         //fire project updated
-        projectUpdateListener.projectUpdated();
+        if(projectUpdateListener != null) projectUpdateListener.projectUpdated();

         //create conf dir if doesn't exist and copy default manifest inside
         try {
@@ -473,7 +473,7 @@
         public boolean canUpdate ();
     }

-    private ProjectUpdateListener projectUpdateListener;
+    private ProjectUpdateListener projectUpdateListener = null;

     public void setProjectUpdateListener(ProjectUpdateListener l) {
         this.projectUpdateListener = l;

Comment 8 Marek Fukala 2005-04-19 09:06:34 UTC
Yes Karle, the regression was caused by Issue #56844 for sure. As Pavel wrote,
the "updateListener" wasn't initialized when resolving broken references and
hence the code thrown the NPE. It is fixed now.
Comment 9 Pavel Buzek 2005-04-20 02:18:13 UTC
I agree with the fix. Thanks for correcting me, Marku.
Comment 10 Marek Fukala 2005-04-20 07:57:18 UTC
fixed in release41 branch

Checking in src/org/netbeans/modules/web/project/UpdateHelper.java;
/cvs/web/project/src/org/netbeans/modules/web/project/UpdateHelper.java,v  <-- 
UpdateHelper.java
new revision: 1.14.2.1; previous revision: 1.14
done
Comment 11 zikmund 2005-04-20 10:37:36 UTC
The second fix was verified in trunk by QE.
Comment 12 zikmund 2005-04-29 11:51:31 UTC
Verified in release41 branch too.