[java] Typeresolution: Return empty set instead of null for erased cadidate set

This commit is contained in:
Andreas Dangel
2017-10-05 20:56:46 +02:00
parent b517838fbb
commit dd596f0aef
2 changed files with 8 additions and 2 deletions

View File

@ -160,7 +160,7 @@ public final class TypeInferenceResolver {
} }
public static Set<Class<?>> getErasedCandidateSet(List<JavaTypeDefinition> erasedSuperTypeSets) { public static Set<Class<?>> getErasedCandidateSet(List<JavaTypeDefinition> erasedSuperTypeSets) {
Set<Class<?>> result = null; Set<Class<?>> result = new HashSet<>();
if (!erasedSuperTypeSets.isEmpty()) { if (!erasedSuperTypeSets.isEmpty()) {
result = erasedSuperTypeSets.get(0).getErasedSuperTypeSet(); result = erasedSuperTypeSets.get(0).getErasedSuperTypeSet();

View File

@ -9,10 +9,12 @@ import static net.sourceforge.pmd.lang.java.typeresolution.typeinference.Inferen
import static net.sourceforge.pmd.lang.java.typeresolution.typeinference.InferenceRuleType.LOOSE_INVOCATION; import static net.sourceforge.pmd.lang.java.typeresolution.typeinference.InferenceRuleType.LOOSE_INVOCATION;
import static net.sourceforge.pmd.lang.java.typeresolution.typeinference.InferenceRuleType.SUBTYPE; import static net.sourceforge.pmd.lang.java.typeresolution.typeinference.InferenceRuleType.SUBTYPE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -306,10 +308,14 @@ public class TypeInferenceTest {
Set<Class<?>> erasedCandidate = TypeInferenceResolver.getErasedCandidateSet(types); Set<Class<?>> erasedCandidate = TypeInferenceResolver.getErasedCandidateSet(types);
assertEquals(erasedCandidate.size(), 3); assertEquals(3, erasedCandidate.size());
assertTrue(erasedCandidate.contains(Object.class)); assertTrue(erasedCandidate.contains(Object.class));
assertTrue(erasedCandidate.contains(Collection.class)); assertTrue(erasedCandidate.contains(Collection.class));
assertTrue(erasedCandidate.contains(Iterable.class)); assertTrue(erasedCandidate.contains(Iterable.class));
Set<Class<?>> emptySet = TypeInferenceResolver.getErasedCandidateSet(Collections.<JavaTypeDefinition>emptyList());
assertNotNull(emptySet);
assertEquals(0, emptySet.size());
} }
@Test @Test