Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings caused by deprecated constructor calls with primitive argument #58

Merged
merged 4 commits into from
May 26, 2018

Conversation

gayanW
Copy link
Collaborator

@gayanW gayanW commented May 26, 2018

This fixes some of the deprecation warnings as stated in #47 (due to the use of the Number constructor on the primitive types) by removing unnecessary explicit manual boxing and by use of @SuppressWarnings("deprecation") annotation.

Issue: #47

gayanW added 4 commits May 26, 2018 18:17
Explicit manual boxing (i.e. wrapping of primitive values in objects) is
unnecessary under Java 5 and newer, and can be safely removed.

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

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

Issue: javapathfinder#47
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: javapathfinder#47
@gayanW
Copy link
Collaborator Author

gayanW commented May 26, 2018

I'm not sure if the Integer constructor calls are used intendedly or not in the following.

@Test
public void testConstructorCallInteger() {
if (verifyNoPropertyViolation()) {
try {
Class<I> cls = I.class;
Constructor<I> ctor = cls.getDeclaredConstructor(new Class<?>[] {Integer.class });
I obj = ctor.newInstance(42);
assertNotNull(obj);
assertEquals(new Integer(42), obj.i);
} catch (Throwable t) {
fail("ctor invocation with Integer failed: " + t);
}
}
}

line 88: assertEquals(new Integer(42), obj.i);

@Test
public void testClone() {
SparseClusterArray<Integer> arr = new SparseClusterArray<Integer>();
arr.set(0, new Integer(0));
arr.set(42, new Integer(42));
arr.set(6762, new Integer(6762));
arr.set(6762, null);
Cloner<Integer> cloner = new Cloner<Integer>() {
@Override
public Integer clone (Integer other) {
return new Integer(other);
}
};
SparseClusterArray<Integer> newArr = arr.deepCopy(cloner);
for (Integer i : newArr) {
System.out.println(i);
}

Also here in line 184: return new Integer(other);

@cyrille-artho cyrille-artho merged commit 981fb1a into javapathfinder:java-10 May 26, 2018
@gayanW gayanW mentioned this pull request May 27, 2018
cyrille-artho added a commit that referenced this pull request May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants