This code:
var reflections = new Reflections("my.package");
var types = reflections
.getTypesAnnotatedWith(GenerateMessages.class)
.stream();
types.map(Class::getFields).flatMap(Stream::of)
.forEach(field -> {
try {
String key = (String) field.get(null); // <- FAILS HERE
} catch (IllegalArgumentException | IllegalAccessException e) {
this.getLogger().error("Cannot access field", e);
}
});
fails when instrumented by Clover on the line commented with FAILS HERE. This is the thrown exception:
java.lang.ClassCastException: class com_atlassian_clover.TestNameSniffer$1
cannot be cast to class java.lang.String
(com_atlassian_clover.TestNameSniffer$1 is in unnamed module of loader
java.net.URLClassLoader @3141366; java.lang.String is in module java.base of loader 'bootstrap')
I've just realized the code assumes that the fields of those classes are of type String, since that is the adopted convention in that project, but I assume Clover is adding other fields so I need to be more careful on casting!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.