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 197861

Summary: Incorrect URL port value in JarClassLoader
Product: platform Reporter: Jaroslav Tulach <jtulach>
Component: Module SystemAssignee: Jaroslav Tulach <jtulach>
Status: RESOLVED FIXED    
Severity: normal CC: jglick
Priority: P1    
Version: 6.x   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:
Attachments: I cannot reproduce the faulty behavior, URLs seem to be equal

Description Jaroslav Tulach 2011-04-19 09:16:54 UTC
org.netbeans.JarClassLoader.java:880 uses a literal of 0. This causes URL.equals(Object) to fail when comparing URLs that were 
constructed using the different means. 

The URL spec violation is that they are setting the port without setting the 
host.  The specification prohibits that.  If the host is not set, the port 
must be -1.  The standard URL constructors ensure this is always the case.   
However, JarClassLoader bypasses those constructors and calls 
URLStreamHandler.setURL(), and explicitly sets the port to 0.  They need to 
change that code to be consistent with URLs created with the standard 
constructors, and use -1.  Should only be a 2 character change in the file, I 
think.
Comment 1 Jaroslav Tulach 2011-04-19 10:24:20 UTC
Created attachment 107830 [details]
I cannot reproduce the faulty behavior, URLs seem to be equal
Comment 2 Jaroslav Tulach 2011-04-19 12:28:35 UTC
To reproduce one needs to use URL(u, "/relative/path"): ergonomics#63fed943e185

Jesse, please review, I'd like to put the fix into release692 branch.
Comment 3 Jesse Glick 2011-04-19 17:17:43 UTC
Fix looks OK to me.

Note that new URL("jar:file:/....jar!/...").getHost() => "" rather than null, which will be another difference from the current code. Probably it makes no difference.

Would prefer that testURLsAreEqual be moved inside JarClassLoaderTest, probably right beneath testJarURLConnection, so that Ctrl-F6 from JarClassLoader.java runs all relevant tests.
Comment 4 Jaroslav Tulach 2011-04-19 19:11:08 UTC
changeset:   a6da24c443cd
branch:      release692
parent:      591d43f0314b
parent:      63fed943e185
user:        Jaroslav Tulach <jtulach@netbeans.org>
date:        Tue Apr 19 21:02:06 2011 +0200
summary:     Backport of #197861 to release692 branch


I started with the test in JarClassLoaderTest, but it does not work. It needs to obtain URL from the original handler first, and only then initialize JarClassLoader. This is a bit fragile, and it is better to isolate this into own test case.
Comment 5 Quality Engineering 2011-04-20 05:01:21 UTC
Integrated into 'main-golden', will be available in build *201104200000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/63fed943e185
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #197861: Copy the host and port