From 74ed736f3f5dbfc5e997d6c5396e22d4780fa0e2 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 2 Jan 2024 16:55:22 -0800 Subject: [PATCH 1/3] Fixes #51: make `ResolvedArrayType` have `java.lang.Object` as parent type --- .../classmate/types/ResolvedArrayType.java | 19 ++++++++++++++++--- .../classmate/types/ResolvedObjectType.java | 14 -------------- .../ResolvedArrayType51Test.java} | 6 +++--- 3 files changed, 19 insertions(+), 20 deletions(-) rename src/test/java/com/fasterxml/classmate/{failing/ArrayTypeResolution51Test.java => types/ResolvedArrayType51Test.java} (74%) diff --git a/src/main/java/com/fasterxml/classmate/types/ResolvedArrayType.java b/src/main/java/com/fasterxml/classmate/types/ResolvedArrayType.java index 4630f3a..b7c81d8 100644 --- a/src/main/java/com/fasterxml/classmate/types/ResolvedArrayType.java +++ b/src/main/java/com/fasterxml/classmate/types/ResolvedArrayType.java @@ -7,8 +7,21 @@ public final class ResolvedArrayType extends ResolvedType { - protected final ResolvedType _elementType; + /** + * All Java Arrays extend {@link java.lang.Object} so we need + * a reference + *

+ * Note that direct construction is used instead of construction via + * {@link TypeResolver} due to complexity of doing latter: {@code java.lang.Object} + * also does not implement any interfaces so this should be safe enough. + * + * @since 1.7 + */ + private final static ResolvedObjectType PARENT_TYPE = + ResolvedObjectType.create(Object.class, null, null, null); + protected final ResolvedType _elementType; + /* /********************************************************************** /* Life cycle @@ -34,7 +47,7 @@ public boolean canCreateSubtypes() { */ @Override - public ResolvedType getParentClass() { return null; } + public ResolvedType getParentClass() { return PARENT_TYPE; } @Override public ResolvedType getSelfReferencedType() { return null; } @@ -69,7 +82,7 @@ public boolean isInterface() { /* /********************************************************************** - /* Accessors for raw (minimally procesed) members + /* Accessors for raw (minimally processed) members /********************************************************************** */ diff --git a/src/main/java/com/fasterxml/classmate/types/ResolvedObjectType.java b/src/main/java/com/fasterxml/classmate/types/ResolvedObjectType.java index 5b54221..9b354a8 100644 --- a/src/main/java/com/fasterxml/classmate/types/ResolvedObjectType.java +++ b/src/main/java/com/fasterxml/classmate/types/ResolvedObjectType.java @@ -83,20 +83,6 @@ public ResolvedObjectType(Class erased, TypeBindings bindings, _modifiers = erased.getModifiers(); } - @Deprecated // since 1.1; removed from 1.2 -- kept for binary backwards compatibility - public ResolvedObjectType(Class erased, TypeBindings bindings, - ResolvedObjectType superClass, List interfaces) - { - this(erased, bindings, (ResolvedType) superClass, interfaces); - } - - @Deprecated // since 1.1; removed from 1.2 -- kept for binary backwards compatibility - public ResolvedObjectType(Class erased, TypeBindings bindings, - ResolvedObjectType superClass, ResolvedType[] interfaces) - { - this(erased, bindings, (ResolvedType) superClass, interfaces); - } - public static ResolvedObjectType create(Class erased, TypeBindings bindings, ResolvedType superClass, List interfaces) { diff --git a/src/test/java/com/fasterxml/classmate/failing/ArrayTypeResolution51Test.java b/src/test/java/com/fasterxml/classmate/types/ResolvedArrayType51Test.java similarity index 74% rename from src/test/java/com/fasterxml/classmate/failing/ArrayTypeResolution51Test.java rename to src/test/java/com/fasterxml/classmate/types/ResolvedArrayType51Test.java index ce5cf15..2ae1cc6 100644 --- a/src/test/java/com/fasterxml/classmate/failing/ArrayTypeResolution51Test.java +++ b/src/test/java/com/fasterxml/classmate/types/ResolvedArrayType51Test.java @@ -1,10 +1,10 @@ -package com.fasterxml.classmate.failing; +package com.fasterxml.classmate.types; import com.fasterxml.classmate.BaseTest; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.classmate.TypeResolver; -public class ArrayTypeResolution51Test extends BaseTest +public class ResolvedArrayType51Test extends BaseTest { protected final TypeResolver RESOLVER = new TypeResolver(); @@ -13,6 +13,6 @@ public void testResolvingRawType() { ResolvedType rt = RESOLVER.resolve(Long[].class); ResolvedType parent = rt.getParentClass(); assertNotNull(parent); - assertEquals(Long.class, parent.getErasedType()); + assertEquals(Object.class, parent.getErasedType()); } } From 1f266a907245f17e90365c1b1a0b4d858a137c5c Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 2 Jan 2024 16:57:13 -0800 Subject: [PATCH 2/3] Update release notes --- VERSION.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/VERSION.txt b/VERSION.txt index 35d4808..5df12a2 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -5,6 +5,9 @@ Release notes: 1.7.0 (not yet released) +#51: `TypeResolver.resolve(Long[].class)` should not return a `ResolvedType` + whose parent type is null + (reported by @ljnelson) #75: Move JDK baseline to Java 8 (contributed by Dave B, @mebigfatguy) #83: Simplify code by not calling `Set.contains()` before `add()` From 575670d2561996ff531fabc2c065147abc67cea5 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 2 Jan 2024 17:01:37 -0800 Subject: [PATCH 3/3] Fix a unit test --- .../fasterxml/classmate/types/ResolvedArrayTypeTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fasterxml/classmate/types/ResolvedArrayTypeTest.java b/src/test/java/com/fasterxml/classmate/types/ResolvedArrayTypeTest.java index d1dc6b9..efb8384 100644 --- a/src/test/java/com/fasterxml/classmate/types/ResolvedArrayTypeTest.java +++ b/src/test/java/com/fasterxml/classmate/types/ResolvedArrayTypeTest.java @@ -7,12 +7,11 @@ import java.util.Collection; -import static junit.framework.Assert.*; +import static org.junit.Assert.*; /** * User: blangel */ -@SuppressWarnings("deprecation") public class ResolvedArrayTypeTest { @Test @@ -33,7 +32,9 @@ public void canCreateSubtypes() { @Test public void getParentClass() { ResolvedArrayType arrayType = new ResolvedArrayType(Object.class, null, null); - assertNull(arrayType.getParentClass()); + // With [classmate#51]: + assertNotNull(arrayType.getParentClass()); + assertEquals(Object.class, arrayType.getParentClass().getErasedType()); } @Test