Skip to content

Commit

Permalink
[refactor] getPackage is deprecated but can not be fixed atm
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Sep 21, 2023
1 parent 632b1f7 commit 5934f23
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/javasupport/JavaPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand All @@ -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());
}
Expand All @@ -291,7 +297,7 @@ public IRubyObject sealed_p(ThreadContext context) {
@SuppressWarnings("unchecked")
public <T> T toJava(Class<T> target) {
if ( target.isAssignableFrom( Package.class ) ) {
return target.cast(Package.getPackage(packageName));
return target.cast(getPackage());
}
return super.toJava(target);
}
Expand Down

0 comments on commit 5934f23

Please sign in to comment.