Skip to content

Commit 72bdf34

Browse files
committed
Simplified URL to File location.
1 parent 602cbde commit 72bdf34

1 file changed

Lines changed: 21 additions & 40 deletions

File tree

src/matlabcontrol/Configuration.java

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -203,68 +203,49 @@ static String getSupportCodeLocation() throws MatlabConnectionException {
203203
URL url = codeSource.getLocation();
204204
if (url != null) {
205205
//Convert from url to absolute path
206-
try {
207-
//uri cannot be null, but this method can throw a URISyntaxException
208-
URI uri = url.toURI();
209-
210-
//path could be null
211-
String path = uri.getPath();
212-
if (path != null) {
213-
try {
214-
File file = new File(path).getCanonicalFile();
215-
if (file.exists()) {
216-
return file.getAbsolutePath();
217-
} else {
218-
ClassLoader loader = Configuration.class.getClassLoader();
219-
throw new MatlabConnectionException("Support code location was determined improperly." +
220-
" Location does not exist.\n" +
221-
"Location determined as: " + file.getAbsolutePath() + "\n" +
222-
"Path: " + path + "\n" +
223-
"URI Location: " + uri + "\n" +
224-
"URL Location: " + url + "\n" +
225-
"Code Source: " + codeSource + "\n" +
226-
"Protection Domain: " + domain + "\n" +
227-
"Class Loader: " + loader +
228-
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
229-
}
230-
}
231-
//Unable to resolve canconical path
232-
catch (IOException e) {
206+
//path could be null
207+
String path = url.getFile();
208+
if (path != null) {
209+
try {
210+
File file = new File(path).getCanonicalFile();
211+
if (file.exists()) {
212+
return file.getAbsolutePath();
213+
} else {
233214
ClassLoader loader = Configuration.class.getClassLoader();
234-
throw new MatlabConnectionException("Support code location could not be determined. " +
235-
"Could not resolve canonical path.\n" +
215+
throw new MatlabConnectionException("Support code location was determined improperly." +
216+
" Location does not exist.\n" +
217+
"Location determined as: " + file.getAbsolutePath() + "\n" +
236218
"Path: " + path + "\n" +
237-
"URI Location: " + uri + "\n" +
238219
"URL Location: " + url + "\n" +
239220
"Code Source: " + codeSource + "\n" +
240221
"Protection Domain: " + domain + "\n" +
241222
"Class Loader: " + loader +
242-
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e);
223+
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
243224
}
244225
}
245-
//path was null
246-
else {
226+
//Unable to resolve canconical path
227+
catch (IOException e) {
247228
ClassLoader loader = Configuration.class.getClassLoader();
248229
throw new MatlabConnectionException("Support code location could not be determined. " +
249-
"Could not get path from URI location.\n" +
250-
"URI Location: " + uri + "\n" +
230+
"Could not resolve canonical path.\n" +
231+
"Path: " + path + "\n" +
251232
"URL Location: " + url + "\n" +
252233
"Code Source: " + codeSource + "\n" +
253234
"Protection Domain: " + domain + "\n" +
254235
"Class Loader: " + loader +
255-
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
236+
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e);
256237
}
257238
}
258-
//Unable to convert URL to URI
259-
catch (URISyntaxException e) {
239+
//path was null
240+
else {
260241
ClassLoader loader = Configuration.class.getClassLoader();
261242
throw new MatlabConnectionException("Support code location could not be determined. " +
262-
"Could not convert from URL to URI location.\n" +
243+
"Could not get path from URI location.\n" +
263244
"URL Location: " + url + "\n" +
264245
"Code Source: " + codeSource + "\n" +
265246
"Protection Domain: " + domain + "\n" +
266247
"Class Loader: " + loader +
267-
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e);
248+
(loader == null ? "" : "\nClass Loader Class: " + loader.getClass()));
268249
}
269250
}
270251
//url was null

0 commit comments

Comments
 (0)