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 157798 - JNLP & ModuleInfo.owns
Summary: JNLP & ModuleInfo.owns
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Module System (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-02 17:33 UTC by puce
Modified: 2009-05-18 21:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Demo app (16.92 KB, application/x-compressed)
2009-02-03 01:00 UTC, Jesse Glick
Details
Bug screenshot (139.28 KB, image/jpeg)
2009-05-07 18:10 UTC, puce
Details

Note You need to log in before you can comment on or make changes to this bug.
Description puce 2009-02-02 17:33:10 UTC
If I have a class Installer, which is a subclass of ModuleInstall, and call ModuleInfo.owns(Installer.class) on the
ModuleInfo object of the Module the Installer class belongs to, I get:

true, if running the NetBeans Platform Application "normally" from the IDE
false, if running as JNLP Application 

I debugged it and found that the ModuleInfo object is an instance of FixedModule and its superclass Module defines the
owns method like this:

    public boolean owns(Class clazz) {
        ClassLoader cl = clazz.getClassLoader();
        if (cl instanceof Util.ModuleProvider) {
            return ((Util.ModuleProvider) cl).getModule() == this;
        }
        return false;
        
    }

When running as a JNLP Application, Installer.class.getClassLoader() returns com.sun.jnlp.JNLPClassLoader, which
probably doesn't implement Util.ModuleProvider?

Note, while we are at it, it would be good to have a method, which returns the ModuleInfo for a class, so one doesn't
have to iterate over all instances, eg. something like:

 public static ModuleInfo getModuleInfo(Class clazz) {
        ClassLoader cl = clazz.getClassLoader();
        if (cl instanceof Util.ModuleProvider) {
            return ((Util.ModuleProvider) cl).getModule();
        }
        return null;
        
    }
Comment 1 Jesse Glick 2009-02-02 17:42:13 UTC
Right, ModuleInfo.owns was never intended to work in JNLP mode, or generally for modules present in the application
classpath rather than loaded dynamically in their own class loaders. I will check if this can be fixed in a
straightforward way. Probably it can be for classes in the main module JAR but not for classes in Class-Path extensions.

ModuleInfo.forClass(Class) could be useful - please file separately as an RFE (keyword API) as this would be tracked
independently.
Comment 2 Jesse Glick 2009-02-03 01:00:11 UTC
Created attachment 76492 [details]
Demo app
Comment 3 Jesse Glick 2009-02-03 01:02:16 UTC
core-main #ff998e324d9a
Comment 4 puce 2009-02-03 18:26:14 UTC
Thanks for the fix.

I will use part of that code as a work-around until we can update to a version, which contains that fix.

I couldn't see where the stream returned by manifest.openStream() gets closed. Couldn't this become a memory leak?
Comment 5 Jesse Glick 2009-02-03 18:57:16 UTC
The stream would get closed upon GC but you're right that this should be closed more forcefully. core-main #58c5ca53da21
Comment 6 Quality Engineering 2009-02-03 20:50:50 UTC
Integrated into 'main-golden', will be available in build *200902031446* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/ff998e324d9a
User: Jesse Glick <jglick@netbeans.org>
Log: #157798: ModuleInfo.owns(Class) did not work in JNLP mode.
Comment 7 puce 2009-02-04 09:54:26 UTC
OK, thanks.

Note that your last fix (stream closing; core-main #58c5ca53da21) did not make it into 'main-golden'
(http://hg.netbeans.org/main/rev/ff998e324d9a).

Was this on purpose?
Comment 8 puce 2009-02-04 14:03:23 UTC
I filed an enhancement issue for the ModuleInfo.forClass(Class) method:
http://www.netbeans.org/issues/show_bug.cgi?id=157828
Comment 9 Jesse Glick 2009-02-04 15:27:03 UTC
Changesets propagate first from core-main to main (pretty quickly, after a continuous build accepts them), then later
into main-golden (after an official daily development build passes). Should be there in a day or so.
Comment 10 Quality Engineering 2009-02-04 21:20:26 UTC
Integrated into 'main-golden', will be available in build *200902041526* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/58c5ca53da21
User: Jesse Glick <jglick@netbeans.org>
Log: #157798 refinement: close InputStream.
Comment 11 puce 2009-05-07 18:08:17 UTC
I just tested the fix of this issue with NetBeans IDE 6.7 Beta and the demo app of this issue:
The ModuleInfo.owns now works when running from inside NetBeans either as JNLP application or as "normal" application.

But when the war-file (Build JNLP Application) is deployed to an application server (eg. jboss v4.2.2) ModuleInfo.owns
always returns true! (see attachment)

Other tests showed that in a similar case Class.getProtectionDomain().getCodeSource().getLocation() doesn't return
something that matches:
file:.+\\.jar

but a String, which starts with "http" and does NOT end with ".jar".

Without further debugging I guess that the last line of org.netbeans.Module.owns comes into action in this case:
return true; // not sure...

Comment 12 puce 2009-05-07 18:10:30 UTC
Created attachment 81760 [details]
Bug screenshot
Comment 13 Jesse Glick 2009-05-14 04:48:56 UTC
Confirmed with Glassfish 2.1. core-main #03cebc7a3dc4
Comment 14 Quality Engineering 2009-05-14 19:03:11 UTC
Integrated into 'main-golden', will be available in build *200905141401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/03cebc7a3dc4
User: Jesse Glick <jglick@netbeans.org>
Log: #157798 cont'd: original fix did not work when deployed as WAR.
Comment 15 puce 2009-05-15 16:26:01 UTC
My first tests showed that this generally works, thanks.

But couldn't this become a performance issue because of the remote URL (http)? If I understand that code correctly, it
will download the jar again for each call to ModuleInfo.owns. But since it is the jar of a class, which is already
locally available, the jar should be locally available, too. Is there an API, which could be used in this fix, which
accesses the local jar instead of the remote one?

I could imagine, that this really could become an issue, when ModuleInfo.owns is called in a loop to get the one, which
returns true (since there is no ModuleInfo.forClass(Class) method yet; see
http://www.netbeans.org/issues/show_bug.cgi?id=157828 ).
Comment 16 Jesse Glick 2009-05-18 21:48:18 UTC
JDK 6 javaws should automatically translate suitable http URLs to locally cached equivalent when opening them. That
said, opening and parsing MANIFEST.MF of hundreds of modules even from a local JAR could be slow, so if ModuleInfo.owns
turns out to be called repeatedly, a separate RFE could ask for it to keep a weak cache CodeSource -> codeName.