Skip to content

Commit 0af20e1

Browse files
committed
The best of both approaches for jar detection. (#18)
1 parent 39a1f5f commit 0af20e1

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/matlabcontrol/Configuration.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.lang.reflect.Method;
1111
import java.net.URISyntaxException;
1212
import java.net.URL;
13-
import java.net.URLEncoder;
1413
import java.security.CodeSource;
1514
import java.security.ProtectionDomain;
1615

@@ -204,22 +203,27 @@ static String getSupportCodeLocation() throws MatlabConnectionException {
204203
if (url != null) {
205204
//Convert from url to absolute path
206205
try {
207-
// make sure that the url is properly encoded
208-
URL encoded = new URL(URLEncoder.encode(url.toString(), "UTF-8"));
209-
File file = new File(encoded.toURI()).getCanonicalFile();
206+
// generate canonical file using URL path
207+
File file = new File(url.getPath()).getCanonicalFile();
210208
if (file.exists()) {
211209
return file.getAbsolutePath();
212210
} else {
213-
ClassLoader loader = Configuration.class.getClassLoader();
214-
throw new MatlabConnectionException("Support code location was determined improperly." +
215-
" Location does not exist.\n" +
216-
"Location determined as: " + file.getAbsolutePath() + "\n" +
217-
"File: " + file + "\n" +
218-
"URL Location: " + url + "\n" +
219-
"Code Source: " + codeSource + "\n" +
220-
"Protection Domain: " + domain + "\n" +
221-
"Class Loader: " + loader +
222-
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
211+
// generate canonical file using URI
212+
file = new File(url.toURI()).getCanonicalFile();
213+
if (file.exists()) {
214+
return file.getAbsolutePath();
215+
} else {
216+
ClassLoader loader = Configuration.class.getClassLoader();
217+
throw new MatlabConnectionException("Support code location was determined improperly." +
218+
" Location does not exist.\n" +
219+
"Location determined as: " + file.getAbsolutePath() + "\n" +
220+
"File: " + file + "\n" +
221+
"URL Location: " + url + "\n" +
222+
"Code Source: " + codeSource + "\n" +
223+
"Protection Domain: " + domain + "\n" +
224+
"Class Loader: " + loader +
225+
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
226+
}
223227
}
224228
}
225229
//Unable to resolve canconical path

0 commit comments

Comments
 (0)