Skip to content

Commit

Permalink
[ARIES-1816] Unable to use <null> with generic arguments
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/aries/trunk@1834984 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
gnodet committed Jul 3, 2018
1 parent dc04d12 commit f106a19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private static <E> Match<E> match(Executable<E> executable, List<TypedObject> ar
TypedObject arg = args.get(i);
Type needed = parameterTypes[i];
long sc;
if (needed == arg.type) {
if (arg.type == null || needed == arg.type) {
sc = COST_ASSIGN;
} else if (allowCast && ClassUtil.getClass(needed).isAssignableFrom(ClassUtil.getClass(arg.type))) {
sc = COST_CAST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.aries.blueprint.container;

import org.apache.aries.blueprint.TestBlueprintContainer;
import org.apache.aries.blueprint.di.ExecutionContext;
import org.apache.aries.blueprint.pojos.DummyServiceTrackerCustomizer;
import org.apache.aries.blueprint.pojos.PojoA;
import org.apache.aries.blueprint.utils.generics.OwbParametrizedTypeImpl;
Expand All @@ -31,6 +32,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertNotNull;

Expand Down Expand Up @@ -70,11 +73,31 @@ public void testReorder() {
assertNotNull(match);
}

@Test
public void testParameterWithNullCollections() {
BlueprintContainerImpl container = new BlueprintContainerImpl(null, null, null, null, null, null, null, null, null, null);
BeanRecipe recipe = new BeanRecipe("sessionDef", container, FactoryWithList.class, false, false, false);
recipe.setArguments(Collections.singletonList(null));
recipe.setArgTypes(Collections.<String>singletonList(null));
recipe.setFactoryMethod("init");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
recipe.create();
}

class TIConverter implements TypeInference.Converter {
public TypeInference.TypedObject convert(TypeInference.TypedObject from, Type to) throws Exception {
Object arg = from.getValue();
arg = converter.convert(arg, new GenericType(to));
return new TypeInference.TypedObject(to, arg);
}
}

public static class FactoryWithList {

public static String init(List<Integer> ints) {
return "Hello!";
}

}

}

0 comments on commit f106a19

Please sign in to comment.