Skip to content

Commit a16107c

Browse files
authored
use Class#isRecord if available (#5195)
1 parent 92ec550 commit a16107c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Project: jackson-databind
1919
#5151: Add new exception type, `MissingInjectValueException`, to be used
2020
for failed `@JacksonInject`
2121
#5179: Add "current token" info into `MismatchedInputException`
22+
#5192: Record types are broken on Android when using R8
23+
(reported by @HelloOO7)
24+
(fix by @pjfanning)
2225
- Generate SBOMs [JSTEP-14]
2326
2427
2.19.1 (13-Jun-2025)

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public final class ClassUtil
2424

2525
private final static Iterator<Object> EMPTY_ITERATOR = Collections.emptyIterator();
2626

27+
// 16-Jun-2025: [databind#5195]: we will dynamically access `Class.isRecord()`
28+
// added in JDK 16, earlier versions do not have it; will eval as `null`.
29+
private final static Method IS_RECORD;
30+
static {
31+
Method m = null;
32+
try {
33+
m = Class.class.getMethod("isRecord");
34+
} catch (NoSuchMethodException e) {
35+
// no-op, will be null
36+
}
37+
IS_RECORD = m;
38+
}
39+
2740
/*
2841
/**********************************************************
2942
/* Simple factory methods
@@ -299,8 +312,19 @@ public static boolean isBogusClass(Class<?> cls) {
299312
* @since 2.12
300313
*/
301314
public static boolean isRecordType(Class<?> cls) {
302-
Class<?> parent = cls.getSuperclass();
303-
return (parent != null) && "java.lang.Record".equals(parent.getName());
315+
// 16-Jun-2025: [databind#5195]: implementation changed from 2.19
316+
// where we checked if `cls.getParent() == "java.lang.Record" which
317+
// caused issues on Android, desugared cases. This is a more reliable
318+
// method for checking.
319+
if (IS_RECORD == null) {
320+
return false;
321+
}
322+
try {
323+
return (Boolean) IS_RECORD.invoke(cls);
324+
} catch (Exception e) {
325+
// hopefully, this is not going to happen
326+
return false;
327+
}
304328
}
305329

306330
/**

0 commit comments

Comments
 (0)