From 026875dd5256051d4e3504f1d9b01f7ce2bb70ff Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Implementation will iterate through all {@link Throwable#getCause() causes}. + *
+ */ + public static void dumpThrowable(final String additionalDescr, final Throwable t, final int causeDepth, final int stackDepth) { System.err.print("Caught "+additionalDescr+" "); - printStackTrace(System.err, t); + printStackTrace(System.err, t, causeDepth, stackDepth); } } diff --git a/src/java/com/jogamp/common/net/Uri.java b/src/java/com/jogamp/common/net/Uri.java index 6bafba2..a6fd4fe 100644 --- a/src/java/com/jogamp/common/net/Uri.java +++ b/src/java/com/jogamp/common/net/Uri.java @@ -1232,7 +1232,12 @@ public class Uri { /** Returns true, if this instance is a {@code file} {@code scheme}, otherwise false. */ public final boolean isFileScheme() { - return FILE_SCHEME.equals( scheme.get() ); + return null != scheme && FILE_SCHEME.equals( scheme.get() ); + } + + /** Returns true, if this instance is a {@code jar} {@code scheme}, otherwise false. */ + public final boolean isJarScheme() { + return null != scheme && JAR_SCHEME.equals( scheme.get() ); } /** @@ -1386,7 +1391,7 @@ public class Uri { if( !emptyString(schemeSpecificPart) ) { final StringBuilder sb = new StringBuilder(); - if( scheme.equals(JAR_SCHEME) ) { + if( isJarScheme() ) { final int idx = schemeSpecificPart.lastIndexOf(JAR_SCHEME_SEPARATOR); if (0 > idx) { throw new URISyntaxException(input.get(), "missing jar separator"); diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 7853555..653520d 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -620,7 +620,7 @@ public class IOUtil { } /** - * @param path assuming a slashified path beginning with "/" as it's root directory, either denotes a file or directory. + * @param path assuming a slashified path, either denotes a file or directory, either relative or absolute. * @return parent of path * @throws URISyntaxException if path is empty or has no parent directory available */ @@ -632,11 +632,11 @@ public class IOUtil { final int e = path.lastIndexOf("/"); if( e < 0 ) { - throw new URISyntaxException(path, "path contains no '/'"); + throw new URISyntaxException(path, "path contains no '/': <"+path+">"); } if( e == 0 ) { // path is root directory - throw new URISyntaxException(path, "path has no parents"); + throw new URISyntaxException(path, "path has no parents: <"+path+">"); } if( e < pl - 1 ) { // path is file, return it's parent directory @@ -646,23 +646,45 @@ public class IOUtil { // path is a directory .. final int p = path.lastIndexOf("/", e-1); if( p >= j) { + // parent itself has '/' - post '!' or no '!' at all return path.substring(0, p+1); + } else { + // parent itself has no '/' + final String parent = path.substring(j, e); + if( parent.equals("..") ) { + throw new URISyntaxException(path, "parent is unresolved: <"+path+">"); + } else { + // parent is '!' or empty (relative path) + return path.substring(0, j); + } } - throw new URISyntaxException(path, "parent of path contains no '/'"); } /** - * @param path assuming a slashified path beginning with "/" as it's root directory, either denotes a file or directory. - * @return clean path string where../
and ./
is resolved.
+ * @param path assuming a slashified path, either denoting a file or directory, either relative or absolute.
+ * @return clean path string where {@code ./} and {@code ../} is resolved,
+ * while keeping a starting {@code ../} at the beginning of a relative path.
* @throws URISyntaxException if path is empty or has no parent directory available while resolving ../
*/
public static String cleanPathString(String path) throws URISyntaxException {
- int idx;
- while ( ( idx = path.indexOf("../") ) >= 0 ) {
- path = getParentOf(path.substring(0, idx)) + path.substring(idx+3);
+ // Resolve './' before '../' to handle case 'parent/./../a.txt' properly.
+ int idx = path.length() - 1;
+ while ( idx >= 1 && ( idx = path.lastIndexOf("./", idx) ) >= 0 ) {
+ if( 0 < idx && path.charAt(idx-1) == '.' ) {
+ idx-=2; // skip '../' -> idx upfront
+ } else {
+ path = path.substring(0, idx) + path.substring(idx+2);
+ idx--; // idx upfront
+ }
}
- while ( ( idx = path.indexOf("./") ) >= 0 ) {
- path = path.substring(0, idx) + path.substring(idx+2);
+ idx = 0;
+ while ( ( idx = path.indexOf("../", idx) ) >= 0 ) {
+ if( 0 == idx ) {
+ idx += 3; // skip starting '../'
+ } else {
+ path = getParentOf(path.substring(0, idx)) + path.substring(idx+3);
+ idx = 0;
+ }
}
return path;
}
diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java
index 745dd12..2580714 100644
--- a/src/java/com/jogamp/common/util/JarUtil.java
+++ b/src/java/com/jogamp/common/util/JarUtil.java
@@ -163,7 +163,7 @@ public class JarUtil {
}
}
}
- if( !uri.scheme.equals( Uri.JAR_SCHEME ) ) {
+ if( !uri.isJarScheme() ) {
throw new IllegalArgumentException("Uri is not using scheme "+Uri.JAR_SCHEME+": <"+uri+">");
}
if(DEBUG) {
@@ -190,7 +190,7 @@ public class JarUtil {
if(null == classJarUri) {
throw new IllegalArgumentException("Uri is null");
}
- if( !classJarUri.scheme.equals(Uri.JAR_SCHEME) ) {
+ if( !classJarUri.isJarScheme() ) {
throw new IllegalArgumentException("Uri is not using scheme "+Uri.JAR_SCHEME+": <"+classJarUri+">");
}
Uri.Encoded ssp = classJarUri.schemeSpecificPart;
@@ -262,7 +262,7 @@ public class JarUtil {
if(null == classJarUri) {
throw new IllegalArgumentException("Uri is null");
}
- if( !classJarUri.scheme.equals(Uri.JAR_SCHEME) ) {
+ if( !classJarUri.isJarScheme() ) {
throw new IllegalArgumentException("Uri is not a using scheme "+Uri.JAR_SCHEME+": <"+classJarUri+">");
}
final Uri.Encoded uriSSP = classJarUri.schemeSpecificPart;
diff --git a/src/java/com/jogamp/common/util/SourcedInterruptedException.java b/src/java/com/jogamp/common/util/SourcedInterruptedException.java
index 49dcd86..2483d5b 100644
--- a/src/java/com/jogamp/common/util/SourcedInterruptedException.java
+++ b/src/java/com/jogamp/common/util/SourcedInterruptedException.java
@@ -150,7 +150,7 @@ public class SourcedInterruptedException extends InterruptedException implements
s.println(s0+" by "+getClass().getSimpleName()+": "+getMessage()+" on thread "+Thread.currentThread().getName());
ExceptionUtils.dumpStack(s, getStackTrace(), 0, -1);
if( null != interruptSource ) {
- ExceptionUtils.dumpCause(s, s0, interruptSource, 1);
+ ExceptionUtils.dumpCause(s, s0, interruptSource, 1, -1, -1);
}
}
@@ -158,9 +158,9 @@ public class SourcedInterruptedException extends InterruptedException implements
public final void printStackTrace(final PrintStream s) {
s.println(getClass().getSimpleName()+": "+getMessage()+" on thread "+Thread.currentThread().getName());
ExceptionUtils.dumpStack(s, getStackTrace(), 0, -1);
- final int causeDepth = ExceptionUtils.dumpCause(s, "Caused", getCause(), 1);
+ final int causeDepth = ExceptionUtils.dumpCause(s, "Caused", getCause(), 1, -1, -1);
if( null != interruptSource ) {
- ExceptionUtils.dumpCause(s, "InterruptSource", interruptSource, causeDepth);
+ ExceptionUtils.dumpCause(s, "InterruptSource", interruptSource, causeDepth, -1, -1);
}
}
}
--
cgit v1.2.3