JD.VNU

JD.VNU shows that the value assigned to a variable was never read after assignment.

Vulnerability and risk

In most cases, it is just less than optimal code, but sometimes, it can signify a major logical error when a value is set up, but never actually used.

Mitigation and prevention

Optimize the code and remove the unused assignments.

Example 1

Copy
     boolean checkArray(int arr[]) {
         for (int i = 0; i < arr.length; i++) {
             int item = arr[i];
             String hexString = Integer.toHexString(item);
             if (i % 2 == 0) {
                 return true;
             }
         }
         return false;
     }

JD.VNU is reported for line 16: a hexString is created for each 'item' in the array, though it is never used afterwards.

Example 2

Copy
     private long getTimeLen(long arr[]) {
         long time1 = 0;
         long time2 = 0;
         long len = 0;
         for (int i = 0; i < arr.length; i += 2) {
             time1 = arr[i];
             time1 = arr[i + 1];
             if (time1 < time2) {
                 long d = time1 - time2;
                 if (d > len) {
                     len = d;
                 }
             }
         }
         return len;
     }

JD.VNU is reported for two assignments in the snippet:

  • assignment on line 14: this operation pointless and unoptimal since 'time1' is overwritten on line 18.
  • assignment on line 18: the developer intended to initialize 'time2' variable but used 'time1' instead.

Related checkers