This method org.lfenergy.compas.sct.commons.Utils#getField(Class<?> clazz, String name) logs an error if the field is declared on the super class, yet returning the correct answer.
It should log an error only if the field is not found.
Plus, the method uses Exception as control flow which is generally an anti-pattern.
Your environment
Version of CoMPAS : 0.0.4
Steps to reproduce
Execute : Utils.getField(TBDA.class, "count");.
Expected behaviour
There should be no error log in the console.
Actual behaviour
The return Field is correct, but in the log you get :
[main] ERROR org.lfenergy.compas.sct.commons.Utils: Cannot find field name count java.lang.NoSuchFieldException: count at java.base/java.lang.Class.getDeclaredField(Class.java:2411) at org.lfenergy.compas.sct.commons.Utils.getField(Utils.java:60) at org.lfenergy.compas.sct.commons.UtilsTest.getField(UtilsTest.java:14) ...
Subject of the issue
This method
org.lfenergy.compas.sct.commons.Utils#getField(Class<?> clazz, String name)
logs an error if the field is declared on the super class, yet returning the correct answer. It should log an error only if the field is not found. Plus, the method uses Exception as control flow which is generally an anti-pattern.Your environment
Steps to reproduce
Execute :
Utils.getField(TBDA.class, "count");
.Expected behaviour
There should be no error log in the console.
Actual behaviour
The return Field is correct, but in the log you get :
[main] ERROR org.lfenergy.compas.sct.commons.Utils: Cannot find field name count java.lang.NoSuchFieldException: count at java.base/java.lang.Class.getDeclaredField(Class.java:2411) at org.lfenergy.compas.sct.commons.Utils.getField(Utils.java:60) at org.lfenergy.compas.sct.commons.UtilsTest.getField(UtilsTest.java:14) ...