diff --git a/core/src/main/java/org/jruby/javasupport/JavaPackage.java b/core/src/main/java/org/jruby/javasupport/JavaPackage.java index 5d8649d9614..4378042474b 100644 --- a/core/src/main/java/org/jruby/javasupport/JavaPackage.java +++ b/core/src/main/java/org/jruby/javasupport/JavaPackage.java @@ -272,7 +272,13 @@ static RaiseException packageMethodArgumentMismatch(final Ruby runtime, final Ru public final boolean isAvailable() { // may be null if no package information is available from the archive or codebase - return Package.getPackage(packageName) != null; + return getPackage() != null; + } + + @SuppressWarnings("deprecation") + private Package getPackage() { + // NOTE: can not switch to getRuntime().getJRubyClassLoader().getDefinedPackage(packageName) as it's Java 9+ + return Package.getPackage(packageName); } @JRubyMethod(name = "available?") @@ -282,7 +288,7 @@ public IRubyObject available_p(ThreadContext context) { @JRubyMethod(name = "sealed?") public IRubyObject sealed_p(ThreadContext context) { - final Package pkg = Package.getPackage(packageName); + final Package pkg = getPackage(); if ( pkg == null ) return context.nil; return RubyBoolean.newBoolean(context, pkg.isSealed()); } @@ -291,7 +297,7 @@ public IRubyObject sealed_p(ThreadContext context) { @SuppressWarnings("unchecked") public T toJava(Class target) { if ( target.isAssignableFrom( Package.class ) ) { - return target.cast(Package.getPackage(packageName)); + return target.cast(getPackage()); } return super.toJava(target); }