Author Login
Post Reply
hi all,
when i create a strategy with allowNonMatch="true"
a NullPointerException in the generated code will be
thrown if a do a strategy call with a non-registered type
System.out.println(strategy.filter("hello"));
System.out.println(strategy.filter(new Integer(3)));
// throws NPE in tapestry generated code
// although it should just return null
System.out.println(strategy.filter(new Long(1)));
is this a bug? (5.0.15)
see code below:
g,
kris
public interface Filter<T>
{
T filter(T value);
}
some filter implementation
public class StringFilter implements Filter<String>{
public String filter(String value){
return value.toLowerCase();
}}
public class IntegerFilter implements Filter<Integer> {
public Integer filter(Integer value){
return new Integer(42);
}}
my module
public class StrategyModule {
public Filter buildFilter(StrategyBuilder builder)
{
Map<Class, Filter> registrations
= new HashMap<Class, Filter>();
registrations.put(String.class, new StringFilter());
registrations.put(Integer.class, new IntegerFilter());
return builder.build(StrategyRegistry.newInstance(Filter.class,
registrations, true));
}
}
main test method
public class StrategyMainTest {
public static void main(String[] args) {
RegistryBuilder builder = new RegistryBuilder();
builder.add(StrategyModule.class);
Registry r = builder.build();
r.performRegistryStartup();
Filter strategy = r.getService(Filter.class);
System.out.println(strategy.filter("hello"));
System.out.println(strategy.filter(new Integer(3)));
// throws NPE in tapestry generated code
System.out.println(strategy.filter(new Long(1)));
...
}}