On Saturday, 3. August 2024, 01:06:14 CEST Ed Erwin wrote:
> With XStream 1.4.20, the method
> `DefaultConverterLookup.lookupConverterForType(Class type)` can throw a
> NullPointerException instead of the intended and more helpful
> ConversionException. For example, the code below throws an unintelligble
> exception when trying to lookup a converter for EnumMap.
This can only happen, if XStream cannot instantiate a converter because of a
module restriction. You shoud open java.base for it.
> It should probably throw a ConversionException. Instead, it throws a
> NullPointerException while trying to create the ConversionException.
Please just open an issue at GitHub.
> A
> simple null-check in the DefaultLookupConverter class would fix this.
>
> ```
> XStream xstream =new XStream(new DomDriver());
>
> Converter forString =
> xstream.getConverterLookup().lookupConverterForType(String.class);
> System.out.println("converter for String = " + forString);
>
> Converter forEnumMap =
> xstream.getConverterLookup().lookupConverterForType(EnumMap.class);
> /*
> A NullPointerException is thrown, so never get here.
> Should have been a ConversionException with a useful message.
> */
>
> System.out.println("converter for EnumMap = " + forEnumMap);
>
> ```
Regards,
Jörg