You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Leo Li (JIRA)" <ji...@apache.org> on 2006/11/02 10:48:37 UTC

[jira] Created: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

[classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
----------------------------------------------------------------------------------------------------------

                 Key: HARMONY-2047
                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
             Project: Harmony
          Issue Type: Bug
            Reporter: Leo Li


ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
Here is the testcase:
(First pls put a property file called "AAA#.properties" in where can be searched by classpath.)

public void testGetResourceAsStream() throws Exception
{
        InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
        assertNotNull(in);
}



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Leo Li (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12450593 ] 
            
Leo Li commented on HARMONY-2047:
---------------------------------

Hi, Paulex:
     1. I need to add the "test#.properties" to a jar which is included in the classpath of running junits and support.jar serves. Besides, I find the other jars used by archive testcases are also add in it.  In my memory, it was a location for resource repositry. Have I missed something? 
     2. Furthermore, in the patch I add "." to the classpath of run-tests in the build.xml of luni module. So I wonder if ClassTest.test_getResourceAsStream_withSharpChar() fails due to this since testcases pass on my machine.
     3. As to "%", after I digging into it, I found it is another story with a different reason. Seems in the getResourceAsStream, RI will not call the decode of URL. Because of the calling stack, I am trying to find an elegent resolution to avoid side-effect. So I recommend to report it as another jira to fix.  

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Assigned To: Paulex Yang
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Oliver Deakin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12446975 ] 
            
Oliver Deakin commented on HARMONY-2047:
----------------------------------------

Walking through this in the debugger, I get the following stack trace:
	URL.<init>(String, String, int, String, URLStreamHandler) line: 418	
	URLAppClassLoader(URLClassLoader).targetURL(URL, String) line: 977	
	URLAppClassLoader(URLClassLoader).findResourceImpl(URL[], String) line: 767	
	URLClassLoader$5.run() line: 667	
	URLClassLoader$5.run() line: 1	
	AccessController.doPrivileged(PrivilegedAction, AccessControlContext) line: 201	
	URLAppClassLoader(URLClassLoader).findResource(String) line: 665	
	URLAppClassLoader(ClassLoader).getResource(String) line: 420	
	URLAppClassLoader(ClassLoader).getResourceAsStream(String) line: 480	
	JIRA2047.main(String[]) line: 6	

So the file location is being found using a URL. However, looking at line 418 of URL.java, we can see that the file path is split when a # is encountered, as the part after the # is expected to be a reference. The spec says:

<spec>
A URL may have appended to it a "fragment", also known as a "ref" or a "reference". The fragment is indicated by the sharp sign character "#" followed by more characters. For example, 
     http://java.sun.com/index.html#chapter1
</spec>

The question is, does the # still apply as a reference when the URL protocol is "file"? I would think not, but cannot see in the spec anything to clarify.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Oliver Deakin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12447478 ] 
            
Oliver Deakin commented on HARMONY-2047:
----------------------------------------

fyi - Im talking about org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Leo Li (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12446764 ] 
            
Leo Li commented on HARMONY-2047:
---------------------------------

Hi, Paulex:
      Both fails. Is it possible that the kernel class call another util class in our scope?

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Assigned: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2047?page=all ]

Paulex Yang reassigned HARMONY-2047:
------------------------------------

    Assignee: Paulex Yang

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Assigned To: Paulex Yang
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12450123 ] 
            
Paulex Yang commented on HARMONY-2047:
--------------------------------------

Leo, the ClassTest.test_getResourceAsStream_withSharpChar() failed with your patch:

junit.framework.AssertionFailedError at org.apache.harmony.luni.tests.java.lang.ClassTest.test_getResourceAsStream_withSharpChar(ClassTest.java:724) at java.lang.reflect.AccessibleObject.invokeV(AccessibleObject.java:25)

I added a test#.properties in support module and rebuilt it, anything else I missed?

And if I commented out the test#.properties related tests, the test can pass in ant script, but cannot pass in Eclipse, because in Eclipse, the path of ***.getClass().getClassLoader().getResourceAsStream("blabla") is different with that of "new File("blabla")".

At last, I also have concerns on the patch itself, it has special handling of '#' for FileURLConnection, but how about other special characters like '%', I wrote a small test for "AAA%.properties", and Harmony also fails to find it. So I think we may need a little general solution? 

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Assigned To: Paulex Yang
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12446670 ] 
            
Paulex Yang commented on HARMONY-2047:
--------------------------------------

This seems a kernel class issue, what's your test VM? IBM VME or DRLVM?

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12450108 ] 
            
Paulex Yang commented on HARMONY-2047:
--------------------------------------

Leo, I don't very understand why the test#.properties goes into support module, if it is used by LUNI only, why not just put it into luni\src\test\java\<package name>\?

And another two small issues about the patch format:
1. Would you rename the patch as HARMONY-xxxx.diff(patch)? so that it is a little easier for me to download/manage the patches.
2. For the new files, possible to provide a shell to add it? It's fine to this one without shell, because it's only one new file, but still, life will be a little easier with that.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Assigned To: Paulex Yang
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Oliver Deakin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12447477 ] 
            
Oliver Deakin commented on HARMONY-2047:
----------------------------------------

ok, stepping a little further through the test gives the following stack:

FileURLConnection.<init>(URL) line: 61	
Handler.openConnection(URL) line: 44	
URL.openConnection() line: 659	
URL.openStream() line: 647	
URLAppClassLoader(ClassLoader).getResourceAsStream(String) line: 482	
JIRA2047.main(String[]) line: 8	

The FileURLConnection constructor looks like:

  public FileURLConnection(URL url) {
        super(url);
        if ((fileName = url.getFile()) == null) {
            fileName = "";
        }
        String host = url.getHost();
        if (host != null && host.length() > 0) {
            fileName = "//" + host + fileName;
        }
        fileName = Util.decode(fileName, false);
    }

so we can see that the fileName is constructed from url.getFile(), which will have already been split around the '#' symbol. As such the FileURLConnection gets created with a fileName of "c:/path/to/file/AAA" instead of "c:/path/to/file/AAA#.properties". 
I wonder if in the case of file protocol we might want to reappend the reference part of the URL onto the fileName. 

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Leo Li (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12449896 ] 
            
Leo Li commented on HARMONY-2047:
---------------------------------

Thank you, Oli. Your plan is OK.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Oliver Deakin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12446987 ] 
            
Oliver Deakin commented on HARMONY-2047:
----------------------------------------

Actually, the splitting of the URL by # is correct, as the following will demonstrate:

URL url =  new URL("file", "", -1, "/c:/path/to/file/AAA#.properties", null);
System.out.println(url.getPath());
System.out.println(url.getFile());
System.out.println(url.getRef());

The same results are produced on the RI and Harmony. The URL constructor parameters are identical to those used in the test case when targetURL() creates the URL to the file. So the reason the file is not found is because we end up looking for c:/path/to/file/AAA instead of c:/path/to/file/AAA#.properties.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Oliver Deakin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-2047?page=comments#action_12447832 ] 
            
Oliver Deakin commented on HARMONY-2047:
----------------------------------------

Leo, Paulex - do you agree with the above analysis. Perhaps rewriting the FileURLConnection constructor to:

public FileURLConnection(URL url) {
        super(url);
        fileName = url.getFile();
        if (url.getRef() != null) {
            fileName += "#" + url.getRef();
        }
        if (fileName == null) {
            fileName = "";
        }
        String host = url.getHost();
        if (host != null && host.length() > 0) {
            fileName = "//" + host + fileName;
        }
        fileName = Util.decode(fileName, false);
    }

is the right solution? Any comments?
With this modification the provided test passes, and all Harmony Junit tests pass.

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (HARMONY-2047) [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name

Posted by "Leo Li (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-2047?page=all ]

Leo Li updated HARMONY-2047:
----------------------------

    Attachment: patch.diff

Will somebody try this?

> [classlib][luni]ClassLoader.getResourceAsStream() fails to get property file with special char in its name
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-2047
>                 URL: http://issues.apache.org/jira/browse/HARMONY-2047
>             Project: Harmony
>          Issue Type: Bug
>            Reporter: Leo Li
>         Attachments: patch.diff
>
>
> ClassLoader.getResourceAsStream() fails to get property file with special char in its name.
> Here is the testcase:
> (First pls put a property file called "AAA#.properties" in where can be searched by classpath.)
> public void testGetResourceAsStream() throws Exception
> {
>         InputStream in = TestClassLoader.class.getClassLoader().getResourceAsStream("AAA#.properties");
>         assertNotNull(in);
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira