Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method getClassPathEntries create File objects from URL encoded string (with %20 instead of spaces) #3402

Closed
KairatRakhimov opened this issue Mar 12, 2019 · 2 comments

Comments

@KairatRakhimov
Copy link

method com.google.common.reflect.ClassPath:getClassPathEntries(ClassLoader classloader)
Guava 19, Windows 10, Java 8.
At line 392: File object is created from string entry.getFile()
where entry is URL object from URLClassLoader
File file = new File(entry.getFile())

Method URL.getFile() returns absolute file path URL encoded (ex.:

"/C:/Program%20Files/Java/jdk1.8.0_201/jre/lib/ext/access-bridge-64.jar"

)
File object constructor interprets URL encoded characters literally, therefore this file doesnt exists.

Possible solution to use method URL.toURI():
line 392: File file = new File(entry.toURI());

When File(URI uri) constructor is used, it uses URI.getPath() method internally, and it handles URL encoding characters properly.

@jbduncan
Copy link
Contributor

Hi @KairatRakhimov, welcome to Guava. :)

Guava 19.0 is quite old now. What happens if you upgrade from Guava 19.0 to the latest version: 27.0.1-jre at the time of me writing this? Does the code problem you've talked about still exist in that version?

I ask all this because when I open https://github.com/google/guava/blob/master/guava/src/com/google/common/reflect/ClassPath.java, which is the latest version of ClassPath, and if I then type Ctrl+F and enter "getFile", I can't find it anywhere, so I suspect that the problem may already be fixed.

@KairatRakhimov
Copy link
Author

Hi Jonathan, thank you :)

You are right, issue was fixed in this commit fd919e54a55ba169dc7d9f54b7b3485aa7fa0970

Issue may be closed, i will open another one for Eclipse Milo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants