|
8 | 8 | import java.io.File; |
9 | 9 | import java.io.IOException; |
10 | 10 | import java.lang.reflect.Method; |
| 11 | +import java.net.URISyntaxException; |
11 | 12 | import java.net.URL; |
12 | 13 | import java.security.CodeSource; |
13 | 14 | import java.security.ProtectionDomain; |
@@ -201,49 +202,42 @@ static String getSupportCodeLocation() throws MatlabConnectionException { |
201 | 202 | URL url = codeSource.getLocation(); |
202 | 203 | if (url != null) { |
203 | 204 | //Convert from url to absolute path |
204 | | - //path could be null |
205 | | - String path = url.getFile(); |
206 | | - if (path != null) { |
207 | | - try { |
208 | | - File file = new File(path).getCanonicalFile(); |
209 | | - if (file.exists()) { |
210 | | - return file.getAbsolutePath(); |
211 | | - } else { |
212 | | - ClassLoader loader = Configuration.class.getClassLoader(); |
213 | | - throw new MatlabConnectionException("Support code location was determined improperly." + |
214 | | - " Location does not exist.\n" + |
215 | | - "Location determined as: " + file.getAbsolutePath() + "\n" + |
216 | | - "Path: " + path + "\n" + |
217 | | - "URL Location: " + url + "\n" + |
218 | | - "Code Source: " + codeSource + "\n" + |
219 | | - "Protection Domain: " + domain + "\n" + |
220 | | - "Class Loader: " + loader + |
221 | | - (loader == null ? "" : "\nClass Loader Class: " + loader.getClass())); |
222 | | - } |
223 | | - } |
224 | | - //Unable to resolve canconical path |
225 | | - catch (IOException e) { |
| 205 | + try { |
| 206 | + File file = new File(url.toURI()).getCanonicalFile(); |
| 207 | + if (file.exists()) { |
| 208 | + return file.getAbsolutePath(); |
| 209 | + } else { |
226 | 210 | ClassLoader loader = Configuration.class.getClassLoader(); |
227 | | - throw new MatlabConnectionException("Support code location could not be determined. " + |
228 | | - "Could not resolve canonical path.\n" + |
229 | | - "Path: " + path + "\n" + |
| 211 | + throw new MatlabConnectionException("Support code location was determined improperly." + |
| 212 | + " Location does not exist.\n" + |
| 213 | + "Location determined as: " + file.getAbsolutePath() + "\n" + |
| 214 | + "File: " + file + "\n" + |
230 | 215 | "URL Location: " + url + "\n" + |
231 | 216 | "Code Source: " + codeSource + "\n" + |
232 | 217 | "Protection Domain: " + domain + "\n" + |
233 | 218 | "Class Loader: " + loader + |
234 | | - (loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e); |
| 219 | + (loader == null ? "" : "\nClass Loader Class: " + loader.getClass())); |
235 | 220 | } |
236 | 221 | } |
237 | | - //path was null |
238 | | - else { |
| 222 | + //Unable to resolve canconical path |
| 223 | + catch (IOException e) { |
| 224 | + ClassLoader loader = Configuration.class.getClassLoader(); |
| 225 | + throw new MatlabConnectionException("Support code location could not be determined. " + |
| 226 | + "Could not resolve canonical path.\n" + |
| 227 | + "URL Location: " + url + "\n" + |
| 228 | + "Code Source: " + codeSource + "\n" + |
| 229 | + "Protection Domain: " + domain + "\n" + |
| 230 | + "Class Loader: " + loader + |
| 231 | + (loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e); |
| 232 | + } catch (URISyntaxException e) { |
239 | 233 | ClassLoader loader = Configuration.class.getClassLoader(); |
240 | 234 | throw new MatlabConnectionException("Support code location could not be determined. " + |
241 | | - "Could not get path from URI location.\n" + |
| 235 | + "Could not convert URI location to file path.\n" + |
242 | 236 | "URL Location: " + url + "\n" + |
243 | 237 | "Code Source: " + codeSource + "\n" + |
244 | 238 | "Protection Domain: " + domain + "\n" + |
245 | 239 | "Class Loader: " + loader + |
246 | | - (loader == null ? "" : "\nClass Loader Class: " + loader.getClass())); |
| 240 | + (loader == null ? "" : "\nClass Loader Class: " + loader.getClass()), e); |
247 | 241 | } |
248 | 242 | } |
249 | 243 | //url was null |
|
0 commit comments