Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 370547 - CloseableURLClassLoader should handle both encoded and unencoded URLs
Summary: CloseableURLClassLoader should handle both encoded and unencoded URLs
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Server-Side (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows All
: P3 major with 19 votes (vote)
Target Milestone: Kepler M7   Edit
Assignee: equinox.server-side-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-03 07:56 EST by Andreas Hoegger CLA
Modified: 2013-04-03 11:25 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (2.77 KB, patch)
2012-02-03 08:09 EST, Andreas Hoegger CLA
no flags Details | Diff
alternative patch (4.19 KB, patch)
2012-03-12 14:21 EDT, Thomas Watson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Hoegger CLA 2012-02-03 07:56:39 EST
This bug shows up with spaces (e.g. C:/Program Files/TomcatX) in the installation directory of the web container (e.g. Apache Tomcat).

Having a server application with a fragment hanging on the system.bundle the CloseableURLClassLoader is not able to find any class of the fragment.

To reproduce:
fragment (host: system.bundle)
  AClass
plugin (any)
  Activator{
    start(){
      Class.forName("myfragment.AClass");
    }
  }
Export the application as war file and deploy it on a web container.

With no spaces in the web container installation dir the class got resolved. With spaces in the installation dir a ClassNotFound exception occurs.
Comment 1 Andreas Hoegger CLA 2012-02-03 08:09:23 EST
Created attachment 210511 [details]
Proposed patch

After a shot analysis I came up with the attached patch.

The CloseableURLClassLoader:safeAddLoader(URL url) is called with (url.getPath()):
- "C:/Program Files/tomcat/work/Catalina/localhost/testapp/eclipse/plugins/org.eclipse.osgi_XXX.jar"
- "C:/Program%20Files/tomcat/work/Catalina/localhost/testapp/eclipse/plugins/myFrament_XXX.jar" 
- ...
Comment 2 Thomas Watson CLA 2012-02-03 09:17:20 EST
Thanks for the patch!  Will look to release a fix in M6.
Comment 3 Simon Kaegi CLA 2012-02-03 09:28:22 EST
Good catch Andreas. Thanks.

URL encoding in Java is truly a horrible problem. What you have might be fine but it would be a good idea to also take a look at org.eclipse.core.runtime.URIUtil to ensure corner cases are covered as well.
Comment 4 Thomas Watson CLA 2012-03-12 14:01:46 EDT
Not going to make M6.

(In reply to comment #3)
> Good catch Andreas. Thanks.
> 
> URL encoding in Java is truly a horrible problem. What you have might be fine
> but it would be a good idea to also take a look at
> org.eclipse.core.runtime.URIUtil to ensure corner cases are covered as well.

I have an alternative patch that takes this into account.  But I am not well equipped to test this out in time for M6.
Comment 5 Thomas Watson CLA 2012-03-12 14:21:45 EDT
Created attachment 212486 [details]
alternative patch
Comment 6 Thomas Watson CLA 2012-04-25 11:31:26 EDT
Sorry, I am not confident in releasing this patch without additional review and testing by others that are more familiar with using and testing the servlet bridge.  If I don't get that by the end of this week this bug will have to get deferred.
Comment 7 Thomas Watson CLA 2012-05-14 10:30:54 EDT
Moving out of the Juno release to SR1.
Comment 8 Thomas Watson CLA 2013-01-09 09:55:28 EST
I'm going to release this for M5 Kepler.
Comment 10 David Williams CLA 2013-04-02 18:40:47 EDT
While doing a "local test build", I saw compile errors likely related to this change ... my local build just finished, so don't think it's a mere timing issue. 
I've not looked closer if "prereqs" changed? Or something? 


[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.17.0:compile (default-compile) on project org.eclipse.equinox.servletbridge: Compilation failure: Compilation failure:
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java:[182,0]
[ERROR] File file = new File(toURI(url));
[ERROR] ^^^^^
[ERROR] The method toURI(URL) from the type CloseableURLClassLoader refers to the missing type URI
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java:[191,0]
[ERROR] } catch (URISyntaxException e1) {
[ERROR] ^^^^^^^^^^^^^^^^^^
[ERROR] URISyntaxException cannot be resolved to a type
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java:[198,0]
[ERROR] private static URI toURI(URL url) throws URISyntaxException {
[ERROR] ^^^
[ERROR] URI cannot be resolved to a type
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java:[198,0]
[ERROR] private static URI toURI(URL url) throws URISyntaxException {
[ERROR] ^^^^^^^^^^^^^^^^^^
[ERROR] URISyntaxException cannot be resolved to a type
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.servletbridge/src/org/eclipse/equinox/servletbridge/CloseableURLClassLoader.java:[211,0]
[ERROR] return new URI(SCHEME_FILE, null, pathString, null);
[ERROR] ^^^
[ERROR] URI cannot be resolved to a type
Comment 11 Thomas Watson CLA 2013-04-03 08:45:59 EDT
I did not realize org.eclipse.equinox.servletbridge still required foundation 1.0 as an EE.  I bumped it up to foundation 1.1 / Java 1.4

http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=6cbfe68501fbc775691c97c19c624145b88718a2
Comment 12 David Williams CLA 2013-04-03 11:01:46 EDT
Perhaps unrelated to this bug and change, but while trying to verify it with a local build, I am getting compile errors in test related bundles? 


[INFO] Building jar: /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.weaving.caching.j9/target/org.eclipse.equinox.weaving.caching.j9-1.0.200-SNAPSHOT.jar
[INFO] Building jar: /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.bidi.tests/target/org.eclipse.equinox.bidi.tests-1.0.0-SNAPSHOT.jar
[INFO] Building jar: /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.bundles/bundles/org.eclipse.equinox.cm.test/target/org.eclipse.equinox.cm.test-1.0.0.jar
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.17.0:compile (default-compile) on project org.eclipse.osgi.tests: Compilation failure: Compilation failure:
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.framework/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java:[99,0]
[ERROR] Map<String, Object> configuration = new HashMap<String, Object>();
[ERROR] ^^^^^^^^^^^^^^
[ERROR] Syntax error, parameterized types are only available if source level is 1.5 or greater
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.framework/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java:[99,0]
[ERROR] Map<String, Object> configuration = new HashMap<String, Object>();
[ERROR] ^^^^^^^^^^^^^^
[ERROR] Syntax error, parameterized types are only available if source level is 1.5 or greater
[ERROR] /data/shared/eclipse/builds/4I/master/gitCache/eclipse.platform.releng.aggregator/rt.equinox.framework/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java:[135,0]
.... [many more]
Comment 13 Thomas Watson CLA 2013-04-03 11:25:53 EDT
(In reply to comment #12)
> Perhaps unrelated to this bug and change, but while trying to verify it with
> a local build, I am getting compile errors in test related bundles? 
> 

This is related to bug 386298.