Skip to content

Commit

Permalink
Fixes #51: ResolvedArrayType to have parent of java.lang.Object (#84
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cowtowncoder authored Jan 3, 2024
1 parent 6095105 commit b2962d0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
3 changes: 3 additions & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/fasterxml/classmate/types/ResolvedArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*<p>
* 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
Expand All @@ -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; }
Expand Down Expand Up @@ -69,7 +82,7 @@ public boolean isInterface() {

/*
/**********************************************************************
/* Accessors for raw (minimally procesed) members
/* Accessors for raw (minimally processed) members
/**********************************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolvedType> 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<ResolvedType> interfaces)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b2962d0

Please sign in to comment.