Skip to content

Commit

Permalink
Fix ExtensionManager to work even for Java 11 and 17
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Dec 5, 2024
1 parent 009923d commit a1a6b02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions compiler/core/src/zserio/tools/ExtensionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,20 @@ private File getWorkingDirectory()
{
final String execUrlPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
final String decodedExecUrlPath = URLDecoder.decode(execUrlPath, "UTF-8");
final Path workingParentPath = Paths.get(new URL(decodedExecUrlPath).toURI()).getParent();
// check if decodedExecUrlPath is really URL, newer Java versions 11 or 17 returns normal path
File decodedExecFile = null;
try
{
decodedExecFile = new File(new URL(decodedExecUrlPath).toURI());
}
catch (MalformedURLException | URISyntaxException excpt)
{
decodedExecFile = new File(decodedExecUrlPath);
}

return (workingParentPath == null) ? null : workingParentPath.toFile();
return decodedExecFile.getParentFile();
}
catch (SecurityException | UnsupportedEncodingException | MalformedURLException |
URISyntaxException excpt)
catch (SecurityException | UnsupportedEncodingException excpt)
{
return null;
}
Expand Down

0 comments on commit a1a6b02

Please sign in to comment.