Skip to content

Commit 9882fdc

Browse files
committed
Add some additional debugging when testing ProtectionDomain
1 parent 157dc23 commit 9882fdc

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

integration-tests/maven/src/test/resources-filtered/projects/classic/src/main/java/org/acme/ProtectionDomain.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import jakarta.ws.rs.Path;
77
import java.io.IOException;
88
import java.io.InputStream;
9+
import java.io.PrintWriter;
10+
import java.io.StringWriter;
911
import java.net.URL;
12+
import java.util.Arrays;
1013
import java.util.jar.JarInputStream;
1114
import java.util.jar.Manifest;
1215
import java.nio.charset.StandardCharsets;
@@ -46,8 +49,9 @@ private String runAssertions(Supplier<String>... assertions) {
4649

4750
private String assertReadManifestFromJar() {
4851
final String testType = "manifest-from-jar";
52+
URL location = null;
4953
try {
50-
URL location = org.apache.commons.io.Charsets.class.getProtectionDomain().getCodeSource().getLocation();
54+
location = org.apache.commons.io.Charsets.class.getProtectionDomain().getCodeSource().getLocation();
5155
if (location == null) {
5256
return errorResult(testType, "location should not be null");
5357
}
@@ -66,12 +70,19 @@ private String assertReadManifestFromJar() {
6670
}
6771
return SUCCESS;
6872
} catch (Exception e) {
69-
e.printStackTrace();
70-
return errorResult(testType, "exception during resolution of resource");
73+
return errorResult(testType, "Exception during resolution of resource (" + location + "): " + e + "\n" + getStackTraceAsString(e));
7174
}
7275
}
7376

7477
private String errorResult(String testType, String message) {
7578
return testType + " / " + message;
7679
}
80+
81+
private static String getStackTraceAsString(Throwable t) {
82+
StringWriter sw = new StringWriter();
83+
try (PrintWriter pw = new PrintWriter(sw)) {
84+
t.printStackTrace(pw);
85+
}
86+
return sw.toString();
87+
}
7788
}

integration-tests/maven/src/test/resources-filtered/projects/rr-with-json-logging/src/main/java/org/acme/ProtectionDomain.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import jakarta.ws.rs.Path;
77
import java.io.IOException;
88
import java.io.InputStream;
9+
import java.io.PrintWriter;
10+
import java.io.StringWriter;
911
import java.net.URL;
1012
import java.util.jar.JarInputStream;
1113
import java.util.jar.Manifest;
@@ -46,8 +48,9 @@ private String runAssertions(Supplier<String>... assertions) {
4648

4749
private String assertReadManifestFromJar() {
4850
final String testType = "manifest-from-jar";
51+
URL location = null;
4952
try {
50-
URL location = org.apache.commons.io.Charsets.class.getProtectionDomain().getCodeSource().getLocation();
53+
location = org.apache.commons.io.Charsets.class.getProtectionDomain().getCodeSource().getLocation();
5154
if (location == null) {
5255
return errorResult(testType, "location should not be null");
5356
}
@@ -66,12 +69,19 @@ private String assertReadManifestFromJar() {
6669
}
6770
return SUCCESS;
6871
} catch (Exception e) {
69-
e.printStackTrace();
70-
return errorResult(testType, "exception during resolution of resource");
72+
return errorResult(testType, "Exception during resolution of resource (" + location + "): " + e + "\n" + getStackTraceAsString(e));
7173
}
7274
}
7375

7476
private String errorResult(String testType, String message) {
7577
return testType + " / " + message;
7678
}
79+
80+
private static String getStackTraceAsString(Throwable t) {
81+
StringWriter sw = new StringWriter();
82+
try (PrintWriter pw = new PrintWriter(sw)) {
83+
t.printStackTrace(pw);
84+
}
85+
return sw.toString();
86+
}
7787
}

0 commit comments

Comments
 (0)