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

warning: Reflection is internal proprietary API and may be removed #81

Closed
gayanW opened this issue Jun 7, 2018 · 2 comments
Closed

Comments

@gayanW
Copy link
Collaborator

gayanW commented Jun 7, 2018

Deprecation warning

'Reflection is internal proprietary API and may be removed in a future release' 

when build with JDK 9 and later:

[javac] /home/travis/build/javapathfinder/jpf-core/src/tests/gov/nasa/jpf/test/vm/reflection/ReflectionTest.java:34: warning: Reflection is internal proprietary API and may be removed in a future release
[javac]       Class<?> callerCls = sun.reflect.Reflection.getCallerClass(0); // that would be getCallerClass()
[javac]                                       ^

Travis log:
https://travis-ci.org/javapathfinder/jpf-core/builds/389306467#L2485-L2508

References:
https://www.logicbig.com/tutorials/core-java-tutorial/java-9-changes/stack-walker-caller.html

@gayanW
Copy link
Collaborator Author

gayanW commented Jun 7, 2018

If we are to use the StackWalker instead of calling sun.reflect.Reflection.getCallerClass, I think it will make sense to refactor the name of the test class from 'gov.nasa.jpf.test.vm.reflection.ReflectionTest' to 'gov.nasa.jpf.test.java.lang.StackWalkerTest'

For your reference:

public class ReflectionTest extends TestJPF {
static class MyClass {
void bar(){
foo();
}
// compilation will cause a warning about internal proprietary API that cannot be suppressed, but we have to test this
// since it is still used by standard libs
void foo (){
Class<?> callerCls = sun.reflect.Reflection.getCallerClass(0); // that would be getCallerClass()
System.out.println("-- getCallerClass(0) = " + callerCls);
assertTrue(callerCls.getName().equals("sun.reflect.Reflection"));

@cyrille-artho
Copy link
Member

Yes, please update the class name for consistency.

gayanW added a commit to gayanW/jpf-core that referenced this issue Jun 13, 2018
sun.reflect.Reflection#getCallerClass is an internal API and is marked
for removal. This uses StackWalker to walk the stack and obtain the
caller class with StackWalker.StackFrame.getDeclaringClass instead.

The class is also being renamed from
'gov.nasa.jpf.test.vm.reflection.ReflectionTest' to
'gov.nasa.jpf.test.java.lang.StackWalkerTest' for consistency.

Fixes: javapathfinder#81
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