Skip to content

Commit c3ceb63

Browse files
Address additional code review nitpicks
- Fix INamedModelInstance Javadoc: null returned when no JSON key configured - Add null-guard to WrappedException constructor for fail-fast behavior - Prevent duplicate suppressed exceptions on repeated unwraps
1 parent ee92a16 commit c3ceb63

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelInstance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ default boolean hasJsonKey() {
6565
/**
6666
* Get the JSON key flag instance for this model instance, if one is configured.
6767
*
68-
* @return the JSON key flag instance or {@code null} if a JSON key is
68+
* @return the JSON key flag instance or {@code null} if no JSON key is
6969
* configured
7070
*/
7171
@Nullable

core/src/main/java/gov/nist/secauto/metaschema/core/util/ExceptionUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package gov.nist.secauto.metaschema.core.util;
77

8+
import java.util.Arrays;
89
import java.util.Objects;
910

1011
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -97,7 +98,7 @@ public static final class WrappedException
9798
* the exception to wrap
9899
*/
99100
public WrappedException(@NonNull Throwable cause) {
100-
super(cause);
101+
super(Objects.requireNonNull(cause, "cause"));
101102
}
102103

103104
@Override
@@ -131,7 +132,12 @@ public <E extends Throwable> E unwrap(@NonNull Class<E> wrappedExceptionClass) {
131132
Throwable cause = unwrap();
132133
if (wrappedExceptionClass.isInstance(cause)) {
133134
E unwrappedEx = wrappedExceptionClass.cast(cause);
134-
unwrappedEx.addSuppressed(this);
135+
// Avoid adding duplicate suppressed exceptions on repeated unwraps
136+
boolean alreadySuppressed = Arrays.stream(unwrappedEx.getSuppressed())
137+
.anyMatch(s -> s == this);
138+
if (!alreadySuppressed) {
139+
unwrappedEx.addSuppressed(this);
140+
}
135141
return unwrappedEx;
136142
}
137143
throw new IllegalArgumentException(

0 commit comments

Comments
 (0)