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 217775 - NullPointerException at org.netbeans.modules.websvc.rest.wizard.EntityResourcesSetupPanel$FinishEntityPanel.read
Summary: NullPointerException at org.netbeans.modules.websvc.rest.wizard.EntityResourc...
Status: VERIFIED FIXED
Alias: None
Product: webservices
Classification: Unclassified
Component: REST (show other bugs)
Version: 7.3
Hardware: All All
: P3 normal (vote)
Assignee: Denis Anisimov
URL:
Keywords:
: 218188 218342 218440 218516 220354 220940 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-09-04 07:35 UTC by Jiri Skrivanek
Modified: 2012-11-02 10:06 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 192083


Attachments
stacktrace (6.17 KB, text/plain)
2012-09-04 07:35 UTC, Jiri Skrivanek
Details
stacktrace (6.24 KB, text/plain)
2012-10-26 19:27 UTC, Petr Jiricka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Skrivanek 2012-09-04 07:35:33 UTC
Build: NetBeans IDE Dev (Build 201209040001)
VM: Java HotSpot(TM) 64-Bit Server VM, 23.2-b09, Java(TM) SE Runtime Environment, 1.7.0_06-b24
OS: Windows 7

User Comments:
jskrivanek: To reproduce:
- create web project with GlassFish 3.1.2.2 server
- open new file wizard
- choose Web Services|RESTful Web Services from Database and click Next
- select sample data source
- select e.g. Manufacturer table and click Next
- provide package name and click Next




Stacktrace: 
java.lang.NullPointerException
   at org.netbeans.modules.websvc.rest.wizard.EntityResourcesSetupPanel$FinishEntityPanel.read(EntityResourcesSetupPanel.java:139)
   at org.netbeans.modules.websvc.rest.wizard.AbstractPanel.readSettings(AbstractPanel.java:89)
   at org.openide.WizardDescriptor.updateStateOpen(WizardDescriptor.java:849)
   at org.openide.WizardDescriptor.updateState(WizardDescriptor.java:799)
   at org.openide.loaders.TemplateWizard.updateState(TemplateWizard.java:746)
   at org.netbeans.modules.project.ui.NewFileWizard.updateState(NewFileWizard.java:124)
Comment 1 Jiri Skrivanek 2012-09-04 07:35:35 UTC
Created attachment 123851 [details]
stacktrace
Comment 2 Denis Anisimov 2012-09-04 07:52:54 UTC
Please try to reproduce it with fresh userdir.
The mentioned NPE is the consequence of the absence WebRestSupport instance 
in the project's lookup. It means either problem in the lookup functionality or
issue with current and cached binaries interference .
Comment 3 Jiri Skrivanek 2012-09-04 10:07:10 UTC
Reproducible even with empty userdir.
Comment 4 Denis Anisimov 2012-09-04 12:48:10 UTC
I still cannot reproduce with the recent sources and fresh userdir.
NPE is a result of method call on result of project.getLookup().lookup(WebRestSupport.class).
WebRestSupport subclass is registered in the project's lookup via ProjectServiceProvider annotation.
Comment 5 Jiri Skrivanek 2012-09-04 12:51:58 UTC
I tried the latest daily build 201209040947 and it works. Probably some changesets were not propagated from web-main.
Comment 6 Denis Anisimov 2012-09-12 08:20:44 UTC
*** Bug 218188 has been marked as a duplicate of this bug. ***
Comment 7 Jiri Skrivanek 2012-09-12 08:48:50 UTC
Happened again (see bug 218188).
Comment 8 Denis Anisimov 2012-09-14 10:02:43 UTC
*** Bug 218342 has been marked as a duplicate of this bug. ***
Comment 9 Jiri Skrivanek 2012-09-17 07:31:37 UTC
*** Bug 218440 has been marked as a duplicate of this bug. ***
Comment 10 Jaroslav Tulach 2012-09-17 12:33:33 UTC
Why ads believes this is bug in Lookup?
Comment 11 Denis Anisimov 2012-09-18 09:37:15 UTC
*** Bug 218516 has been marked as a duplicate of this bug. ***
Comment 12 Denis Anisimov 2012-09-18 09:39:56 UTC
(In reply to comment #10)
> Why ads believes this is bug in Lookup?

You can read the comment :

>NPE is a result of method call on result of
>project.getLookup().lookup(WebRestSupport.class).
>WebRestSupport subclass is registered in the project's lookup via
>ProjectServiceProvider annotation.
Comment 13 Denis Anisimov 2012-10-18 12:32:46 UTC
*** Bug 220354 has been marked as a duplicate of this bug. ***
Comment 14 Petr Jiricka 2012-10-18 14:00:15 UTC
Lots of duplicates - sounds like a P2. So where does this belong?
Comment 15 Petr Jiricka 2012-10-26 19:27:10 UTC
Created attachment 126642 [details]
stacktrace

RESTful service from patterns in Maven web project.
Comment 16 Petr Jiricka 2012-10-26 19:27:54 UTC
Denis, can you try to reproduce again?
Comment 17 Petr Jiricka 2012-10-26 19:47:03 UTC
More observations: 
1. This happened to me when I created the REST service immediately after creating the Maven project. The workaround is to expand the project node first - after that it does not happen.

2. Looking at the code in the read(...) method, there are some weird things:
- on line 179 there is a check for restSupport != null, but this check is not there on line 180
- line 191 says: if (restSupport instanceof WebRestSupport) - does this make sense? Isn't the else branch unreachable?
Comment 18 Denis Anisimov 2012-10-29 06:49:59 UTC
*** Bug 220940 has been marked as a duplicate of this bug. ***
Comment 19 Denis Anisimov 2012-10-29 06:55:43 UTC
(In reply to comment #17)
> More observations: 
> 1. This happened to me when I created the REST service immediately after
> creating the Maven project. The workaround is to expand the project node first
> - after that it does not happen.
> 
> 2. Looking at the code in the read(...) method, there are some weird things:
> - on line 179 there is a check for restSupport != null, but this check is not
> there on line 180
> - line 191 says: if (restSupport instanceof WebRestSupport) - does this make
> sense? Isn't the else branch unreachable?

That's the outdated rudimentary code which I've forgot to correct when I've
changed the type of restSupport from super type of WebRestSupport.
I'm going to correct the code but it is minor issue which doesn't introduce any
incorrect behavior.
Comment 20 Denis Anisimov 2012-10-29 07:01:56 UTC
(In reply to comment #17)
> More observations: 
> 1. This happened to me when I created the REST service immediately after
> creating the Maven project. The workaround is to expand the project node first
> - after that it does not happen.
> 

Thank you very much Petr for exact steps to reproduce.
Finally I'm able to reproduce it too.
This is exactly the issue: not-expanded Maven project is not able to find
in its lookup WebRestSupport instance.
But it is able to find it right after project node is expanded.
As I already mentioned WebRestSupport subclass is registered via 
@ProjectServiceProvider (see org.netbeans.modules.maven.jaxws.MavenProjectRestSupport).

So as I said from the very beginning this is a lookup issue. But I'm not sure 
is it general lookup issue or some JEE Maven project specific.
I reassign it to JEE Maven project component. Please evaluate and reassign it
if needed.
Comment 21 Martin Janicek 2012-10-29 08:16:29 UTC
(In reply to comment #20)
> This is exactly the issue: not-expanded Maven project is not able to find
> in its lookup WebRestSupport instance.
> But it is able to find it right after project node is expanded.
> As I already mentioned WebRestSupport subclass is registered via 
> @ProjectServiceProvider (see
> org.netbeans.modules.maven.jaxws.MavenProjectRestSupport).

This has nothing to do with maven (it was reproduced for ant based project as well). It is broken since you have pushed the change-set web-main #788245f71835 where you have changed the lookup usage (instead of trying to find RestSupport.class in the project lookup, you are now looking for WebRestSupport.class which isn't registered via @PSP annotation). You can either add WebRestSupport.class to the @PSP registration (for both MavenProjectRestSupport and WebProjectRestSupport) or change the code to use only abstract RestSupport (can't say whether this is possible without deeper knowledge of that code)..

> So as I said from the very beginning this is a lookup issue. But I'm not sure 
> is it general lookup issue or some JEE Maven project specific.
> I reassign it to JEE Maven project component. Please evaluate and reassign it
> if needed.

Evaluated --> Reassigning back.
Comment 22 Denis Anisimov 2012-10-29 08:28:17 UTC
(In reply to comment #21)
> (In reply to comment #20)
> > This is exactly the issue: not-expanded Maven project is not able to find
> > in its lookup WebRestSupport instance.
> > But it is able to find it right after project node is expanded.
> > As I already mentioned WebRestSupport subclass is registered via 
> > @ProjectServiceProvider (see
> > org.netbeans.modules.maven.jaxws.MavenProjectRestSupport).
> 
> This has nothing to do with maven (it was reproduced for ant based project as
> well). It is broken since you have pushed the change-set web-main #788245f71835
> where you have changed the lookup usage (instead of trying to find
> RestSupport.class in the project lookup, you are now looking for
> WebRestSupport.class which isn't registered via @PSP annotation). You can
> either add WebRestSupport.class to the @PSP registration (for both
> MavenProjectRestSupport and WebProjectRestSupport) or change the code to use
> only abstract RestSupport (can't say whether this is possible without deeper
> knowledge of that code)..

Please describe the exact reason why WebRestSupport can be found in the 
following cases :
1) Ant based project has exactly the same @PSP registration. 
WebRestSupport is always found in the project's lookup.
2) WebRestSupport is in the project's lookup after project node is expanded.
It is not in the project's lookup ONLY if project node is not expanded.

From your explanation I see that WebRestSupport mustn't be in the project 
lookup  at all.
Comment 23 Martin Janicek 2012-10-29 08:45:02 UTC
Denis may I ask you why are you still reassigning the issue to me? Your changeset (web-main 788245f71835) was propagated on the 2012-09-01.. this issue is here since the 2012-09-04 ..nothing has been changed in j2ee maven area for weeks. It is quite obvious that you have made this regression.

I'll glad to help you with evaluation and explanation of the problem, but this super-fast reassigning just to get rid of the issue is a little annoying..
Comment 24 Martin Janicek 2012-10-29 09:03:16 UTC
(In reply to comment #22)
> Please describe the exact reason why WebRestSupport can be found in the 
> following cases :
> 1) Ant based project has exactly the same @PSP registration. 
> WebRestSupport is always found in the project's lookup.

That's not true, it was reproduce by jirka in web project as well.

> 2) WebRestSupport is in the project's lookup after project node is expanded.
> It is not in the project's lookup ONLY if project node is not expanded.

Don't know.. I wouldn't expect this either.

As much as I know, @PSP doesn't work with respect to inheritance tree. If you register some interface in @PSP, you shouldn't be able to lookup the concrete implementor. So I wouldn't expect this work even after project node is expanded, but I don't have deep knowledge of how the @PSP is processed (that's a question for someone else)

> From your explanation I see that WebRestSupport mustn't be in the project 
> lookup  at all.

Well it would be ideal. It's a good practice to use an interface instead of concrete class. Of course, I know it's not possible in every situation that's why it's legal to register both (interface and implementor), but you need to be aware of the issue 205151 (if a LookupMerger is registered for that class type, it might caused some problems)
Comment 25 Denis Anisimov 2012-10-29 09:37:33 UTC
There is definitely some inconsistency in the lookup but I'm tired to argue 
against it.
I will rewrite the code on rest side.
Comment 26 Denis Anisimov 2012-10-29 10:31:12 UTC
web-main#8e45a1be9baf
Comment 27 Quality Engineering 2012-10-30 02:35:39 UTC
Integrated into 'main-golden', will be available in build *201210300001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/8e45a1be9baf
User: Denis Anisimov <ads@netbeans.org>
Log: Fix for BZ#217775 - NullPointerException at org.netbeans.modules.websvc.rest.wizard.EntityResourcesSetupPanel$FinishEntityPanel.read
Comment 28 Jaroslav Tulach 2012-10-31 16:06:46 UTC
The correct fix is:

@ProjectServiceProvider(service={ WebRestSupport.class, RestSupport.class }, projectType="org-netbeans-modules-maven/war")

you need to enumerate all the interface you want an implementation to be initially found for. Otherwise it may or may not be found depending on whether somebody else asked for RestSupport.class sooner or not.
Comment 29 Denis Anisimov 2012-11-01 10:41:54 UTC
(In reply to comment #28)
> The correct fix is:
> 
> @ProjectServiceProvider(service={ WebRestSupport.class, RestSupport.class },
> projectType="org-netbeans-modules-maven/war")
> 
> you need to enumerate all the interface you want an implementation to be
> initially found for. Otherwise it may or may not be found depending on whether
> somebody else asked for RestSupport.class sooner or not.

Finally this is the explanation the observed behavior.
Comment 30 Denis Anisimov 2012-11-01 12:35:46 UTC
web-main#7005950a8426
Comment 31 Quality Engineering 2012-11-02 03:28:38 UTC
Integrated into 'main-golden', will be available in build *201211020001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/7005950a8426
User: Denis Anisimov <ads@netbeans.org>
Log: Fix for BZ#217775 - NullPointerException at org.netbeans.modules.websvc.rest.wizard.EntityResourcesSetupPanel$FinishEntityPanel.read