amaembo / huntbugs

Java bytecode static analyzer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FP: Local variable is assigned to a value which is never used

ben-manes opened this issue · comments

This code assigns a new value to the local variable field and this value is never
used subsequently. Probably something else was meant or the assignment could be removed.

This one is odd because the field is used in the happy path.

Field field = null;
try {
  // try OpenJDK field name
  field = Unsafe.class.getDeclaredField(openJdk);
} catch (NoSuchFieldException e) {
  try {
    // try Android field name...
  } catch (NoSuchFieldException e2) {
    // try to create a new instance...
  }
  field.setAccessible(true);
  return (Unsafe) field.get(null);
}

Are you sure that field.setAccessible and return are inside the catch block?

Typo. I think it was because its initialized to null, which as stated wasn't required.