Skip to content

Commit

Permalink
Suppress warnings in which Number constructor is used intendedly
Browse files Browse the repository at this point in the history
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 committed May 26, 2018
1 parent ba2abc0 commit ddd3c52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void testBooleanCache(){
}

@Test
@SuppressWarnings("deprecation")
public void testIntCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Integer i1 = Integer.valueOf( 1); // should be cached
Expand All @@ -142,6 +143,7 @@ public void testIntCacheBoxObject() throws SecurityException, NoSuchMethodExcept
}

@Test
@SuppressWarnings("deprecation")
public void testCharacterCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Character c1 = Character.valueOf( '?'); // should be cached
Expand All @@ -155,6 +157,7 @@ public void testCharacterCacheBoxObject() throws SecurityException, NoSuchMethod
}

@Test
@SuppressWarnings("deprecation")
public void testByteCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Byte b1 = Byte.valueOf( (byte)1); // should be cached
Expand All @@ -168,6 +171,7 @@ public void testByteCacheBoxObject() throws SecurityException, NoSuchMethodExcep
}

@Test
@SuppressWarnings("deprecation")
public void testShortCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Short s1 = Short.valueOf((short)1); // should be cached
Expand All @@ -181,6 +185,7 @@ public void testShortCacheBoxObject() throws SecurityException, NoSuchMethodExce
}

@Test
@SuppressWarnings("deprecation")
public void testLongCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Long l1 = Long.valueOf(1); // should be cached
Expand All @@ -194,6 +199,7 @@ public void testLongCacheBoxObject() throws SecurityException, NoSuchMethodExcep
}

@Test
@SuppressWarnings("deprecation")
public void testBooleanCacheBoxObject() throws SecurityException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
if (verifyNoPropertyViolation(JPF_ARGS)){
Boolean b1 = Boolean.valueOf(true); // should be cached
Expand Down
1 change: 1 addition & 0 deletions src/tests/gov/nasa/jpf/test/mc/basic/AttrsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ int goModel (double d, int i) {
}
}

@SuppressWarnings("deprecation")
@Test public void testInteger() {
if (verifyNoPropertyViolation()) {
int v = 42;
Expand Down

0 comments on commit ddd3c52

Please sign in to comment.