Skip to content

Commit decabed

Browse files
smiklosovicadutra
andauthored
JAVA-2995: CodecNotFoundException doesn't extend DriverException (#1598)
Co-authored-by: Alexandre Dutra <[email protected]>
1 parent b1cf8a8 commit decabed

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

core/revapi.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6817,6 +6817,13 @@
68176817
"new": "method void com.fasterxml.jackson.databind.type.TypeBase::serialize(com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider) throws java.io.IOException",
68186818
"exception": "com.fasterxml.jackson.core.JsonProcessingException",
68196819
"justification": "Upgrade deps around JAVA-2977 to address outstanding CVEs"
6820+
},
6821+
{
6822+
"code": "java.class.nonFinalClassInheritsFromNewClass",
6823+
"old": "class com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException",
6824+
"new": "class com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException",
6825+
"superClass": "com.datastax.oss.driver.api.core.DriverException",
6826+
"justification": "Make CodecNotFoundException to extend DriverException as all other driver exceptions do"
68206827
}
68216828
]
68226829
}

core/src/main/java/com/datastax/oss/driver/api/core/type/codec/CodecNotFoundException.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*/
1616
package com.datastax.oss.driver.api.core.type.codec;
1717

18+
import com.datastax.oss.driver.api.core.DriverException;
1819
import com.datastax.oss.driver.api.core.type.DataType;
1920
import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry;
2021
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
2122
import edu.umd.cs.findbugs.annotations.NonNull;
2223
import edu.umd.cs.findbugs.annotations.Nullable;
2324

2425
/** Thrown when a suitable {@link TypeCodec} cannot be found by the {@link CodecRegistry}. */
25-
public class CodecNotFoundException extends RuntimeException {
26+
public class CodecNotFoundException extends DriverException {
2627

2728
private final DataType cqlType;
2829

@@ -48,7 +49,7 @@ public CodecNotFoundException(
4849

4950
private CodecNotFoundException(
5051
String msg, Throwable cause, DataType cqlType, GenericType<?> javaType) {
51-
super(msg, cause);
52+
super(msg, null, cause, true);
5253
this.cqlType = cqlType;
5354
this.javaType = javaType;
5455
}
@@ -62,4 +63,10 @@ public DataType getCqlType() {
6263
public GenericType<?> getJavaType() {
6364
return javaType;
6465
}
66+
67+
@NonNull
68+
@Override
69+
public DriverException copy() {
70+
return new CodecNotFoundException(getMessage(), getCause(), getCqlType(), getJavaType());
71+
}
6572
}

upgrade_guide/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
## Upgrade guide
22

3+
### 4.15.0
4+
5+
#### CodecNotFoundException now extends DriverException
6+
7+
Before [JAVA-2995](https://datastax-oss.atlassian.net/browse/JAVA-2959), `CodecNotFoundException`
8+
was extending `RuntimeException`. This is a discrepancy as all other exceptions extend
9+
`DriverException`, which in turn extends `RuntimeException`.
10+
11+
This was causing integrators to do workarounds in order to react on all exceptions correctly.
12+
13+
The change introduced by JAVA-2995 shouldn't be a problem for most users. But if your code was using
14+
a logic such as below, it won't compile anymore:
15+
16+
```java
17+
try {
18+
doSomethingWithDriver();
19+
} catch(DriverException e) {
20+
} catch(CodecNotFoundException e) {
21+
}
22+
```
23+
24+
You need to either reverse the catch order and catch `CodecNotFoundException` first:
25+
26+
```java
27+
try {
28+
doSomethingWithDriver();
29+
} catch(CodecNotFoundException e) {
30+
} catch(DriverException e) {
31+
}
32+
```
33+
34+
Or catch only `DriverException`:
35+
36+
```java
37+
try {
38+
doSomethingWithDriver();
39+
} catch(DriverException e) {
40+
}
41+
```
42+
343
### 4.14.0
444

545
#### AllNodesFailedException instead of NoNodeAvailableException in certain cases

0 commit comments

Comments
 (0)