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

Deprecated constructor calls with primitive argument - Xlint warnings #47

Closed
gayanW opened this issue May 19, 2018 · 4 comments
Closed

Comments

@gayanW
Copy link
Collaborator

gayanW commented May 19, 2018

Several deprecation warnings are showing up on the build logs when compiled with JDK 9 and later.

[javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:247: warning: [deprecation] Byte(byte) in Byte has been deprecated
[javac]           return new Byte((byte) v);
[javac]                  ^
[javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:249: warning: [deprecation] Character(char) in Character has been deprecated
[javac]           return new Character((char) v);
[javac]                  ^
[javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:251: warning: [deprecation] Short(short) in Short has been deprecated
[javac]           return new Short((short) v);
[javac]                  ^
[javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:253: warning: [deprecation] Integer(int) in Integer has been deprecated
[javac]           return new Integer(v);
[javac]                  ^

https://travis-ci.org/javapathfinder/jpf-core/builds/379204138#L2431

@gayanW
Copy link
Collaborator Author

gayanW commented May 19, 2018

These deprecation warnings are mainly due to the use of the Number constructor on the primitive types. We could change those to use the static method valueOf instead. However there seems to have cases where the Number constructor is used intendedly.

So for instance in the BoxObjectCacheTest:
https://github.com/javapathfinder/jpf-core/blob/master/src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java#L137

Just want to make sure that there will be no other side effects once we made the changes.

The other workaround is to simply disable Xlint:deprecation. But in that case we won't gain the performance benefits claimed by valueOf.

@cyrille-artho @Octarine-J

@cyrille-artho
Copy link
Member

cyrille-artho commented May 19, 2018 via email

gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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 added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
gayanW added a commit to gayanW/jpf-core that referenced this issue May 26, 2018
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
cyrille-artho pushed a commit that referenced this issue May 26, 2018
…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
@cyrille-artho cyrille-artho reopened this May 26, 2018
@cyrille-artho
Copy link
Member

Good work. There are still a few open cases in "tests", so I've reopened this issue.

gayanW added a commit to gayanW/jpf-core that referenced this issue May 27, 2018
Replace attempts to instantiate a new Long, Integer, Short or Byte
object from a primitive long, integer, short or byte argument, with more
efficient static method valueOf() (introduced in Java 5), which will
cache objects for values between -128 and 127 inclusive.

We can't use assertEquals(42, obj.i); in
gov.nasa.jpf.test.vm.reflection.ConstructorTest#testConstructorCallInteger
as both assertEquals (Object, Object) and assertEquals (int, int) in
TestJPF match (Ambiguous method call)

Issue: javapathfinder#47
gayanW added a commit to gayanW/jpf-core that referenced this issue May 27, 2018
Replace attempts to instantiate a new Long, Integer, Short or Byte
object from a primitive long, integer, short or byte argument, with more
efficient static method valueOf() (introduced in Java 5), which will
cache objects for values between -128 and 127 inclusive.

We can't use assertEquals(42, obj.i); in
gov.nasa.jpf.test.vm.reflection.ConstructorTest#testConstructorCallInteger
as both assertEquals (Object, Object) and assertEquals (int, int) in
TestJPF match (Ambiguous method call)

Issue: javapathfinder#47
gayanW added a commit to gayanW/jpf-core that referenced this issue May 27, 2018
Replace attempts to instantiate a new Long, Integer, Short or Byte
object from a primitive long, integer, short or byte argument, with more
efficient static method valueOf() (introduced in Java 5), which will
cache objects for values between -128 and 127 inclusive.

We can't use assertEquals(42, obj.i); in
gov.nasa.jpf.test.vm.reflection.ConstructorTest#testConstructorCallInteger
as both assertEquals (Object, Object) and assertEquals (int, int) in
TestJPF match (Ambiguous method call)

Issue: javapathfinder#47
gayanW added a commit to gayanW/jpf-core that referenced this issue May 27, 2018
This is a fixup for the commit ddd3c52

Issue: javapathfinder#47
@cyrille-artho
Copy link
Member

This type of warning has now been eliminated for entire jpf-core.
Other warnings remain (to be resolved in other issues).

gayanW added a commit to gayanW/jpf-core that referenced this issue May 31, 2018
Double (double) is deprecated. It is suggested that we use the static
factory #valueOf(double), as it is likely to yield significantly better space
and time performance.

This is a fixup for issue: javapathfinder#47
This is a follow-up to the PR: javapathfinder#59
gayanW added a commit to gayanW/jpf-core that referenced this issue May 31, 2018
Double (double) is deprecated. It is suggested that we use the static
factory #valueOf(double), as it is likely to yield significantly better space
and time performance.

This is a fixup for issue: javapathfinder#47
This is a follow-up to the PR: javapathfinder#59
gayanW added a commit to gayanW/jpf-core that referenced this issue May 31, 2018
Double (double) is deprecated. It is suggested that we use the static
factory #valueOf(double), as it is likely to yield significantly better space
and time performance.

This is a fixup for issue: javapathfinder#47
This is a follow-up to the PR: javapathfinder#59
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

No branches or pull requests

2 participants