Skip to content

Commit 6634032

Browse files
Test chaining a caught exception that may already have its cause
The Apache Derby shape behind DERBY-2472: exceptions caught in a loop are chained with initCause, but their constructor may already have set the cause, so the call can throw "Can't overwrite cause". The catch parameter's state is unknown, so the call is reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6559819 commit 6634032

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package testSuite.classes.try_catch_error;
2+
3+
// shape of Apache Derby's StandardException: the constructor may already set the cause
4+
class StoreException extends Exception {
5+
StoreException(String message, Throwable cause) {
6+
super(message, cause);
7+
}
8+
}

‎liquidjava-example/src/main/java/testSuite/classes/try_catch_error/Test.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,22 @@ static void finallyChangesVariableCheckedInTry(int x) {
168168
@Refinement("_ > 0")
169169
int z = x; // Expect: Refinement Error
170170
}
171+
172+
static void drop(int i) throws StoreException {
173+
throw new StoreException("cannot drop " + i, new RuntimeException());
174+
}
175+
176+
// a caught exception may already carry its cause (Apache Derby, DERBY-2472, fixed in 1870e8fa:
177+
// chaining with initCause threw "Can't overwrite cause")
178+
static void chainCaughtExceptions() throws StoreException {
179+
StoreException top = null;
180+
for (int i = 0; i < 2; i++) {
181+
try {
182+
drop(i);
183+
} catch (StoreException e) {
184+
e.initCause(top); // Expect: State Refinement Error
185+
top = e;
186+
}
187+
}
188+
}
171189
}

0 commit comments

Comments
 (0)