Skip to content

Commit

Permalink
Fix warnings caused by deprecated constructor calls with primitive ar…
Browse files Browse the repository at this point in the history
…gument (#58)

* Remove explicit manual boxing in main, peers, and tests

Explicit manual boxing (i.e. wrapping of primitive values in objects) is
unnecessary under Java 5 and newer, and can be safely removed.

Issue: #47

* Suppress warnings in which Number constructor is used intentionally

Instantiating a new Long, Integer, Short or Byte object from a primitive
long, integer, short or byte argument is deprecated. It is recommended
that we use the more efficient static method valueOf() (introduced in
Java 5) instead, which caches objects for values between -128 and 127
inclusive.

However in JPF, there are few cases where the use of Number constructor
is intentional (So to bypass the caching). This commit suppress warnings
from appearing in such cases.

Issue: #47
  • Loading branch information
gayanW authored and cyrille-artho committed May 26, 2018
1 parent 1e02daf commit 981fb1a
Show file tree
Hide file tree
Showing 48 changed files with 146 additions and 139 deletions.
8 changes: 4 additions & 4 deletions src/main/gov/nasa/jpf/jvm/ClassFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -955,22 +955,22 @@ protected void parseCp(int cpCount) throws ClassParseException {
dataIdx[i] = j++;

int iVal = (data[j++]&0xff)<<24 | (data[j++]&0xff)<<16 | (data[j++]&0xff)<<8 | (data[j++]&0xff);
values[i] = new Integer(iVal);
values[i] = iVal;
break;

case CONSTANT_FLOAT: // Float_info { u1 tag; u4 bytes; }
dataIdx[i] = j++;

int iBits = (data[j++]&0xff)<<24 | (data[j++]&0xff)<<16 | (data[j++]&0xff)<<8 | (data[j++]&0xff);
float fVal = Float.intBitsToFloat(iBits);
values[i] = new Float(fVal);
values[i] = fVal;
break;

case CONSTANT_LONG: // Long_info { u1 tag; u4 high_bytes; u4 low_bytes; }
dataIdx[i] = j++;
long lVal = (data[j++]&0xffL)<<56 | (data[j++]&0xffL)<<48 | (data[j++]&0xffL)<<40 | (data[j++]&0xffL)<<32
| (data[j++]&0xffL)<<24 | (data[j++]&0xffL)<<16 | (data[j++]&0xffL)<<8 | (data[j++]&0xffL);
values[i] = new Long(lVal);
values[i] = lVal;

dataIdx[++i] = -1; // 8 byte cpValue occupy 2 index slots
break;
Expand All @@ -981,7 +981,7 @@ protected void parseCp(int cpCount) throws ClassParseException {
long lBits = (data[j++]&0xffL)<<56 | (data[j++]&0xffL)<<48 | (data[j++]&0xffL)<<40 | (data[j++]&0xffL)<<32
| (data[j++]&0xffL)<<24 | (data[j++]&0xffL)<<16 | (data[j++]&0xffL)<<8 | (data[j++]&0xffL);
double dVal = Double.longBitsToDouble(lBits);
values[i] = new Double(dVal);
values[i] = dVal;

dataIdx[++i] = -1; // 8 byte cpValue occupy 2 index slots
break;
Expand Down
16 changes: 8 additions & 8 deletions src/main/gov/nasa/jpf/jvm/JVMNativeStackFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,41 @@ public void setArguments (ThreadInfo ti){

case Types.T_SHORT:
ival = callerFrame.peek(stackOffset);
a[j] = new Short((short) ival);
a[j] = (short) ival;

break;

case Types.T_INT:
ival = callerFrame.peek(stackOffset);
a[j] = new Integer(ival);
a[j] = ival;

break;

case Types.T_LONG:
lval = callerFrame.peekLong(stackOffset);
stackOffset++; // 2 stack words
a[j] = new Long(lval);
a[j] = lval;

break;

case Types.T_FLOAT:
ival = callerFrame.peek(stackOffset);
a[j] = new Float(Types.intToFloat(ival));
a[j] = Types.intToFloat(ival);

break;

case Types.T_DOUBLE:
lval = callerFrame.peekLong(stackOffset);
stackOffset++; // 2 stack words
a[j] = new Double(Types.longToDouble(lval));
a[j] = Types.longToDouble(lval);

break;

default:
// NOTE - we have to store T_REFERENCE as an Integer, because
// it shows up in our native method as an 'int'
ival = callerFrame.peek(stackOffset);
a[j] = new Integer(ival);
a[j] = ival;
}

stackOffset++;
Expand All @@ -114,10 +114,10 @@ public void setArguments (ThreadInfo ti){
a[0] = ti.getMJIEnv();

if (nmi.isStatic()) {
a[1] = new Integer( nmi.getClassInfo().getClassObjectRef());
a[1] = nmi.getClassInfo().getClassObjectRef();
} else {
int thisRef = callerFrame.getCalleeThis(nmi);
a[1] = new Integer( thisRef);
a[1] = thisRef;

setThis(thisRef);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/jvm/bytecode/DRETURN.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Object getReturnValue(ThreadInfo ti) {
ret = frame.peekLong();
}

return new Double(Types.longToDouble(ret));
return Types.longToDouble(ret);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/jvm/bytecode/FRETURN.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Float getReturnValue (ThreadInfo ti) {
ret = frame.peekFloat();
}

return new Float(ret);
return ret;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/jvm/bytecode/IRETURN.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Object getReturnValue(ThreadInfo ti) {
ret = frame.peek();
}

return new Integer(ret);
return ret;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/jvm/bytecode/LRETURN.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Object getReturnValue(ThreadInfo ti) {
ret = frame.peekLong();
}

return new Long(ret);
return ret;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/listener/DeadlockAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Instruction getReportInsn(ThreadInfo ti){
}

void printLocOn (PrintWriter pw) {
pw.print(String.format("%6d", new Integer(stateId)));
pw.print(String.format("%6d", stateId));

if (insn != null) {
pw.print(String.format(" %18.18s ", insn.getMnemonic()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/gov/nasa/jpf/listener/Perturbator.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void executeInstruction (VM vm, ThreadInfo ti, Instruction insnToExecute)
// pop the callee stackframe and modify the caller stackframe
// note that we don't need to enter in order to get the perturbation base
// value because its already on the operand stack
ChoiceGenerator<?> cg = e.perturbator.createChoiceGenerator("perturbReturn", ti.getTopFrame(), new Integer(0));
ChoiceGenerator<?> cg = e.perturbator.createChoiceGenerator("perturbReturn", ti.getTopFrame(), 0);
if (ss.setNextChoiceGenerator(cg)){
ti.skipInstruction(insnToExecute);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Inst
}

} else { // first time around, create&set the CG and reexecute
ChoiceGenerator<?> cg = p.perturbator.createChoiceGenerator( "perturbGetField", frame, new Integer(0));
ChoiceGenerator<?> cg = p.perturbator.createChoiceGenerator( "perturbGetField", frame, 0);
if (ss.setNextChoiceGenerator(cg)){
assert savedFrame != null;
// we could more efficiently restore the stackframe
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/util/DynamicIntArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean hasNext() {

@Override
public Integer next() {
return new Integer(get(i++));
return get(i++);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/gov/nasa/jpf/util/SimplePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ public void add(E e) {
public static void main(String[] args) {
SimplePool<Integer> pool = new SimplePool<Integer>(4);
for (int i = 0; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o != p) throw new RuntimeException();
Integer q = pool.pool(p);
if (q != p) throw new RuntimeException();
}
for (int i = 0; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o == p) throw new RuntimeException();
if (!o.equals(p)) throw new RuntimeException();
}
for (int i = 1; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o != p) throw new RuntimeException();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/gov/nasa/jpf/util/SparseObjVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static void main(String[] args) {

// add some
for (int i = -4200; i < 4200; i += 10) {
vect.set(i, new Integer(i));
vect.set(i, i);
}

// check for added & non-added
Expand All @@ -230,7 +230,7 @@ public static void main(String[] args) {

// add some more
for (int i = -4201; i < 4200; i += 10) {
vect.set(i, new Integer(i));
vect.set(i, i);
}

// check all added
Expand Down Expand Up @@ -268,10 +268,10 @@ public static void main(String[] args) {

// add even more
for (int i = -4203; i < 4200; i += 10) {
vect.set(i, new Integer(i));
vect.set(i, i);
}
for (int i = -4204; i < 4200; i += 10) {
vect.set(i, new Integer(i));
vect.set(i, i);
}
}
}
6 changes: 3 additions & 3 deletions src/main/gov/nasa/jpf/util/WeakPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ public void add(E e) {
public static void main(String[] args) {
WeakPool<Integer> pool = new WeakPool<Integer>(4);
for (int i = 0; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o != p) throw new RuntimeException();
Integer q = pool.pool(p);
if (q != p) throw new RuntimeException();
}
for (int i = 0; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o == p) throw new RuntimeException();
if (!o.equals(p)) throw new RuntimeException();
}
for (int i = 1; i < 1000000; i += 42) {
Integer o = new Integer(i);
Integer o = i;
Integer p = pool.pool(o);
if (o != p) throw new RuntimeException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/BooleanFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean isBooleanField() {
@Override
public Object getValueObject (Fields f){
int i = f.getIntValue(storageOffset);
return new Boolean(i != 0);
return i != 0;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/ByteFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
int i = f.getIntValue(storageOffset);
return new Byte((byte)i);
return (byte) i;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/CharFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
int i = f.getIntValue(storageOffset);
return new Character((char)i);
return (char) i;
}

}
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/DoubleFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
double d = f.getDoubleValue(storageOffset);
return new Double(d);
return d;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/FloatFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
float v = f.getFloatValue(storageOffset);
return new Float(v);
return v;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/IntegerFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
int i = f.getIntValue(storageOffset);
return new Integer(i);
return i;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/gov/nasa/jpf/vm/LongFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String valueToString (Fields f) {
@Override
public Object getValueObject (Fields f){
long v = f.getLongValue(storageOffset);
return new Long(v);
return v;
}

@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/gov/nasa/jpf/vm/MJIEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -844,31 +844,31 @@ public Boolean getBooleanObject (int objref){
}

public Byte getByteObject (int objref){
return new Byte(getByteField(objref, "value"));
return getByteField(objref, "value");
}

public Character getCharObject (int objref){
return new Character(getCharField(objref, "value"));
return getCharField(objref, "value");
}

public Short getShortObject (int objref){
return new Short(getShortField(objref, "value"));
return getShortField(objref, "value");
}

public Integer getIntegerObject (int objref){
return new Integer(getIntField(objref, "value"));
return getIntField(objref, "value");
}

public Long getLongObject (int objref){
return new Long(getLongField(objref, "value"));
return getLongField(objref, "value");
}

public Float getFloatObject (int objref){
return new Float(getFloatField(objref, "value"));
return getFloatField(objref, "value");
}

public Double getDoubleObject (int objref){
return new Double(getDoubleField(objref, "value"));
return getDoubleField(objref, "value");
}

// danger - the returned arrays could be used to modify contents of stored objects
Expand Down
Loading

0 comments on commit 981fb1a

Please sign in to comment.