Skip to content

Conversation

koganlev
Copy link

Fix JAR URL encoding for special characters

Fixes SCL-24273: Classes decompiled from JAR files with special characters in their names are not resolved.

Problem

Manual JAR URL construction like new URL(s"jar:file://$path!/") fails when filenames contain special characters (spaces, #, @, &, +, %) due to improper encoding.

Solution

Replace manual URL construction with standard Java APIs:

  • Use Path.toUri().toURL() for proper RFC 3986 URI encoding
  • Add SafeJarLoader utility with fallback mechanisms
  • Fix 4 files: package.scala, Artifact.scala, compiler-shared package.scala, ScalaMavenImporter.scala
  • Follows existing codebase patterns (toUri().toURL() used elsewhere)

Testing

  • SafeJarLoaderTest: Unit tests with various special characters
  • SCL24273IntegrationTest: End-to-end integration scenarios
  • JarUrlEncodingTest: Compiler-shared module tests
  • Full backward compatibility maintained

This uses the same approach already used throughout the IntelliJ Scala codebase for proper URL encoding.

Replace manual jar:file: URL construction with proper Path.toUri() conversion
to handle JAR filenames containing special characters (#, spaces, @, &, +, %).

- Add SafeJarLoader utility with proper URI encoding and fallback mechanisms
- Fix LibraryExt.jarUrls in package.scala to use SafeJarLoader.createJarUrl
- Fix Artifact.readProperty to use SafeJarLoader.createJarResourceUrlFromUri
- Fix compiler-shared package.scala readProperty with proper URI encoding
- Fix ScalaMavenImporter to use Paths.get().toUri() for JAR URLs
- Add comprehensive test coverage for special character scenarios
- Maintain full backward compatibility

The root cause was manual URL construction like `new URL(s"jar:file://$path")`
instead of using Java's standard Path→URI conversion APIs, causing malformed
URLs that URLClassLoader couldn't handle.

This fix uses proper RFC 3986 URI encoding via Path.toUri().toURL() with
robust error handling and detailed logging for troubleshooting.
@unkarjedy unkarjedy requested a review from vasilmkd September 22, 2025 09:30
@unkarjedy
Copy link
Member

Thanks for the PR, we will try to look into it this week!

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

Successfully merging this pull request may close these issues.

2 participants