Skip to content

Commit d23a0ee

Browse files
authored
Add constructors to MalformedPackageURLException (#170)
Add constructors to `MalformedPackageURLException` to propagate the underlying cause.
1 parent ee6dda9 commit d23a0ee

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/main/java/com/github/packageurl/MalformedPackageURLException.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
* @since 1.0.0
2929
*/
3030
public class MalformedPackageURLException extends Exception {
31-
32-
private static final long serialVersionUID = 1095476478991047663L;
31+
private static final long serialVersionUID = -3428748639194901696L;
3332

3433
/**
3534
* Constructs a {@code MalformedPackageURLException} with no detail message.
@@ -47,4 +46,24 @@ public MalformedPackageURLException(String msg) {
4746
super(msg);
4847
}
4948

49+
/**
50+
* Constructs a new {@code MalformedPackageURLException} with the specified detail message and
51+
* cause.
52+
*
53+
* @param message the detail message
54+
* @param cause the cause
55+
*/
56+
public MalformedPackageURLException(String message, Throwable cause) {
57+
super(message, cause);
58+
}
59+
60+
/**
61+
* Constructs a new {@code MalformedPackageURLException} with the specified cause and a detail
62+
* message of {@code (cause==null ? null : cause.toString())}.
63+
*
64+
* @param cause the cause
65+
*/
66+
public MalformedPackageURLException(Throwable cause) {
67+
super(cause);
68+
}
5069
}

src/main/java/com/github/packageurl/PackageURL.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ private String validatePath(final String[] segments, final boolean isSubpath) th
363363
}
364364
return segment;
365365
}).collect(Collectors.joining("/"));
366-
} catch (ValidationException ex) {
367-
throw new MalformedPackageURLException(ex.getMessage());
366+
} catch (ValidationException e) {
367+
throw new MalformedPackageURLException(e);
368368
}
369369
}
370370

@@ -590,7 +590,7 @@ private void parse(final String purl) throws MalformedPackageURLException {
590590
}
591591
verifyTypeConstraints(this.type, this.namespace, this.name);
592592
} catch (URISyntaxException e) {
593-
throw new MalformedPackageURLException("Invalid purl: " + e.getMessage());
593+
throw new MalformedPackageURLException("Invalid purl: " + e.getMessage(), e);
594594
}
595595
}
596596

@@ -624,8 +624,8 @@ private Map<String, String> parseQualifiers(final String encodedString) throws M
624624
},
625625
TreeMap<String, String>::putAll);
626626
return validateQualifiers(results);
627-
} catch (ValidationException ex) {
628-
throw new MalformedPackageURLException(ex.getMessage());
627+
} catch (ValidationException e) {
628+
throw new MalformedPackageURLException(e);
629629
}
630630
}
631631

0 commit comments

Comments
 (0)