Skip to content

Commit 542bb71

Browse files
committed
Return back
1 parent 68fbb85 commit 542bb71

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

compiler/core/src/zserio/tools/ExtensionManager.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,23 @@ private File getWorkingDirectory()
144144
{
145145
try
146146
{
147-
final URL execUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
148-
System.out.println("execUrl = " + execUrl);
149-
final String decodedExecUrlPath = URLDecoder.decode(execUrl.getPath(), "UTF-8");
150-
final File decodedExecFile = new File(new URI(decodedExecUrlPath));
147+
final String execUrlPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
148+
final String decodedExecUrlPath = URLDecoder.decode(execUrlPath, "UTF-8");
149+
// check if decodedExecUrlPath is really URL, newer Java versions 11 or 17 returns normal path
150+
System.out.println("decodedExecUrlPath = " + decodedExecUrlPath);
151+
File decodedExecFile = null;
152+
try
153+
{
154+
decodedExecFile = new File(new URI(decodedExecUrlPath));
155+
}
156+
catch (URISyntaxException | IllegalArgumentException excpt)
157+
{
158+
decodedExecFile = new File(decodedExecUrlPath);
159+
}
160+
if (decodedExecFile.getPath().startsWith("file:"))
161+
{
162+
decodedExecFile = new File(decodedExecFile.getPath().replaceFirst("^file:", ""));
163+
}
151164

152165
System.out.println("decodedExecFile = " + decodedExecFile);
153166
System.out.println("decodedExecFile.getParentFile() = " + decodedExecFile.getParentFile());
@@ -156,7 +169,7 @@ private File getWorkingDirectory()
156169

157170
return decodedExecFile.getParentFile();
158171
}
159-
catch (SecurityException | URISyntaxException | UnsupportedEncodingException excpt)
172+
catch (SecurityException | UnsupportedEncodingException excpt)
160173
{
161174
return null;
162175
}

0 commit comments

Comments
 (0)