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: [deprecation] getPackage(String) in ClassLoader has been deprecated #71

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

Comments

@gayanW
Copy link
Collaborator

gayanW commented May 31, 2018

Deprecation warning 'getPackage(String) in ClassLoader has been deprecated' when build with JDK 9 and later:

[javac] /home/travis/build/javapathfinder/jpf-core/src/tests/gov/nasa/jpf/test/java/net/URLClassLoaderTest.java:68: warning: [deprecation] getPackage(String) in ClassLoader has been deprecated
[javac] 	protected Package getPackage(String name) {
[javac] 	                  ^
[javac] /home/travis/build/javapathfinder/jpf-core/src/tests/gov/nasa/jpf/test/java/net/URLClassLoaderTest.java:69: warning: [deprecation] getPackage(String) in ClassLoader has been deprecated
[javac]       return super.getPackage(name);
[javac]                   ^

@Override
protected Package getPackage(String name) {
return super.getPackage(name);
}

Travis log:
https://travis-ci.org/javapathfinder/jpf-core/builds/385707808#L2456-L2461

References:
cr.openjdk.java.net/~iris/se/10/latestSpec/api/java/lang/ClassLoader.html#getPackage(java.lang.String)

@gayanW
Copy link
Collaborator Author

gayanW commented May 31, 2018

Simplest solution would be just to annotate the override method with @SuppressWarnings("deprecation")

The overridden method is being called in here:

@Test
public void testGetPackage() throws ClassNotFoundException, MalformedURLException {
movePkgOut();
if(verifyNoPropertyViolation()) {
URL[] urls = { new URL(dirUrl) };
TestClassLoader cl = new TestClassLoader(urls);
assertNotNull(cl.getPackage("java.lang"));
assertNull(cl.getPackage("non_existing_package"));
assertNull(cl.getPackage("classloader_specific_tests"));
String cname = pkg + ".Class1";
cl.loadClass(cname);
assertNotNull(cl.getPackage("classloader_specific_tests"));
}
movePkgBack();
}

Another possible solution would be to refactor cl.getPackage to use the method ClassLoader#getDefinedPackage instead. But as the name suggests the test is written specially for getPackage.

@cyrille-artho
Copy link
Member

Perhaps the test still passes when using getDefinedPackage. In that case, changing the method is the best way (note that getDefinedPackage was introduced in Java 9).

@gayanW
Copy link
Collaborator Author

gayanW commented Jun 5, 2018

Thanks for the info. Is it okay that we keep the test name as testGetPackage as we no longer be calling getPackage but getDefinedPackage.

@cyrille-artho
Copy link
Member

cyrille-artho commented Jun 5, 2018 via email

gayanW added a commit to gayanW/jpf-core that referenced this issue Jun 7, 2018
ClassLoader.getPackage(String) is deprecated. This refactors
URLClassLoaderTest to use ClassLoader.getDefinedPackage(String) instead.

gov.nasa.jpf.test.java.net.URLClassLoaderTest.TestClassLoader is only
used within gov.nasa.jpf.test.java.net.URLClassLoaderTest.
gov.nasa.jpf.test.java.net.URLClassLoaderTest.TestClassLoader#getPackage
is being removed as it is no longer being used once the test being
refactored.

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