Open robmv opened 1 year ago
I do wonder with inject whether it shouldn't flag as "unused" in this case.
Reason being that ideally, removing fields that are supposedly unused should not affect the rest of the application. The issue with Inject is that it could theoretically have side effects since it could alter the order that CDI resolves dependencies at runtime. Specifically it makes the "Test" class resolve after the "inject" attribute is initialised (I assume, I have never used EJB, I am just going by how Spring handles this).
I agree that this variable is unused in this case, but I do wonder whether stuff like this could risk bulk IDE refactoring operations introducing bugs into the code that could be missed.
Maybe in cases like this, a separate warning is more suitable?
Conversely one could argue that this is then a special case for a specific set of libraries which reduces the generic-ness of stuff, and it depends on the CDI implementation being used in theory. Likewise there is a consideration to be made about the Jakarta rebranding of a lot of components that were previously javax
.
Guess the same argument could be made about doing this for libraries like Spring, Jackson, Gson, MapStruct, Lombok, etc.
I think Eclipse should not be doing magic assumptions about what is unused or not. It will never work for every framework in the world, it isn't scalable. I was checking where these assumptions are made and it has hard-coded references to a few frameworks.
If some user want add a private field that isn't used inside the class but want to ignore the warning/error, they should use "SuppressWarnings" as intended. If Eclipse want to help some users of some frameworks or code generators (Like immutable class generators), where the annotations means "is is being used", then Eclipse should provide a way to list these annotations. But instead of listing the ones where not being used should be reported, the list must be of the annotations where the warning/error is ignored
The discussion in Bugzilla is interesting too.
If I were to fix this, and by fixing I mean making Eclipse not make assumptions about frameworks and just report the warning/error because the user wanted to know unused fields and the fields aren't being used in the class literally, I would do this:
It the following class is defined:
And the compiler is set to show a warning if a private member isn't used, the field
ejb
andcontext
aren't marked butinject
is.¿Is there some kind of exception for
javax.inject.Inject
?I think all of these fields should be marked as not used, they aren't being used internally on the class, like what happens with the
inject
field.