The message indicates that the line buz = 2 is completely pointless, since the value si never used. Since buz is a local variable, its value is forgotten once the method ends. Next time the method runs, the variable will have a different value, starting with 5. So what was the point of setting it to 2?
There's a reason "DU - Anomaly" is in the "controversial" section: it's not always an indicator of incorrect code. In this case the final assignment is meaningless, so it lets you know that you may have done something other than you intended.
Joined: Jul 17, 2008
whatever i am doing in my code is fine as per my requirements. Nothing is done useless here.
This is just a snapshot of the code given by PMD.
If you want people to explain exactly what PMD means, then (not surprisingly) you'll have to let folks see exactly what PMD is seeing. Otherwise people are just guessing, or explaining what's wrong with your code even though it's not your real code. If you show us made-up code, then of course, we can only guess at what the real stuff looks like.
Alternately, if this really is the actual code you're using, one of two things is probably true:
(a) Your instructor is imposing really strange requirements on you, in order to try to force you to learn something. Be aware that the code you're being forced to write does not really resemble real-world code that anyone might use to do something useful. Other than learning something, perhaps. If this is the case, you should simply ignore PMD entirely, at least while taking your current course. The goals of PMD's creators are incompatible with those of your instructor.
(b) Your code really is doing useless things, despite your disclaimers, and you simply don't understand why that is true. If this is the case, you aren't going to learn anything new by simply insisting that your code is "fine per my requirements". Maybe you could describe those requirements in more detail.
Joined: Jul 17, 2008
Ok here is the code:
This is the snapshot of the code. Skip undefined variables.
As it is a pretty big code. To make it easy. I have written short.
PMD is giving me informational message for- boolean recalculateDuty = false;
Set<DBRecordKey> sDBSplDuties = new HashSet<DBRecordKey>();
I am passing these field variables to method startCalculatingDuties, Inside this method it can change its value as per requirement.
Also sDBSplDuties is paased to this method- sDBSplDuties