It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

This instrumented code fails to execute

This code:

var reflections = new Reflections("my.package");
var types = reflections
.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 @3141366; java.lang.String is in module java.base of loader 'bootstrap')


1 answer

1 accepted

0 votes
Answer accepted

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!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Keep your team in the loop with Team @mentions in Jira Software!

Hi everyone! My name is Jenny, a Product Manager at Atlassian. After launching Team @mentions in Confluence, we heard a lot of positive feedback from customers that they love how easy it is to @men...

155 views 4 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you