Skip to content

Commit

Permalink
Accept nested array type for upUntilUnresolvable check as well
Browse files Browse the repository at this point in the history
Closes gh-33535
  • Loading branch information
jhoeller committed Sep 17, 2024
1 parent 383fa43 commit 20bc5ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void repro() {
assertThat(bf.getBean(AssemblerInjection.class).assembler4).isSameAs(bf.getBean("pageAssembler"));
assertThat(bf.getBean(AssemblerInjection.class).assembler5).isSameAs(bf.getBean("pageAssembler"));
assertThat(bf.getBean(AssemblerInjection.class).assembler6).isSameAs(bf.getBean("pageAssembler"));
assertThat(bf.getBean(AssemblerInjection.class).assembler7).isSameAs(bf.getBean("pageAssembler"));
}
}

Expand Down Expand Up @@ -80,6 +81,9 @@ public static class AssemblerInjection {

@Autowired(required = false)
PageAssembler<String> assembler6;

@Autowired(required = false)
PageAssembler<String[]> assembler7;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,18 @@ private boolean isAssignableFrom(ResolvableType other, boolean strict,
}
}

if (upUntilUnresolvable && (other.isUnresolvableTypeVariable() || other.isWildcardWithoutBounds())) {
return true;
}

// Deal with array by delegating to the component type
if (isArray()) {
return (other.isArray() && getComponentType().isAssignableFrom(
other.getComponentType(), true, matchedBefore, upUntilUnresolvable));
}

if (upUntilUnresolvable && (other.isUnresolvableTypeVariable() || other.isWildcardWithoutBounds())) {
return true;
}

boolean exactMatch = (strict && matchedBefore != null); // We're checking nested generic variables now...
// We're checking nested generic variables now...
boolean exactMatch = (strict && matchedBefore != null);

// Deal with wildcard bounds
WildcardBounds ourBounds = WildcardBounds.get(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,23 @@ void gh32327() throws Exception {
assertThat(repository3.isAssignableFromResolvedPart(repository1)).isFalse();
}

@Test
void gh33535() throws Exception {
ResolvableType repository1 = ResolvableType.forField(Fields.class.getField("stringRepository"));
ResolvableType repository2 = ResolvableType.forField(Fields.class.getField("arrayRepository"));
ResolvableType repository3 = ResolvableType.forMethodReturnType(Methods.class.getMethod("someRepository"));
assertThat(repository1.hasUnresolvableGenerics()).isFalse();
assertThat(repository1.isAssignableFrom(repository3)).isFalse();
assertThat(repository1.isAssignableFromResolvedPart(repository3)).isTrue();
assertThat(repository3.isAssignableFrom(repository1)).isTrue();
assertThat(repository3.isAssignableFromResolvedPart(repository1)).isTrue();
assertThat(repository2.hasUnresolvableGenerics()).isFalse();
assertThat(repository2.isAssignableFrom(repository3)).isFalse();
assertThat(repository2.isAssignableFromResolvedPart(repository3)).isTrue();
assertThat(repository3.isAssignableFrom(repository2)).isTrue();
assertThat(repository3.isAssignableFromResolvedPart(repository2)).isTrue();
}


private ResolvableType testSerialization(ResolvableType type) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -1525,6 +1542,10 @@ static class Fields<T> {
public int[] intArray;

public SomeRepository<? extends Serializable> repository;

public SomeRepository<String> stringRepository;

public SomeRepository<String[]> arrayRepository;
}


Expand Down

0 comments on commit 20bc5ef

Please sign in to comment.