Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -2874,7 +2874,7 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti

if ( p < length && path.charAt(p) == ':' ) {
if ( ++p < length && path.charAt(p) != ':' ) {
throw newRaiseException(undefinedExceptionClass, str(this, "undefined class/module ", ids(this, path)));
throw classPathUndefinedException(path, undefinedExceptionClass, p);
}
pbeg = ++p;
}
Expand All @@ -2883,7 +2883,7 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti
IRubyObject cc = flexibleSearch || isJavaPackageOrJavaClassProxyType(clazz) ?
clazz.getConstant(context, str) : clazz.getConstantAt(context, str);

if (!flexibleSearch && cc == null) return null;
if (cc == null) throw classPathUndefinedException(path, undefinedExceptionClass, p);

if (!(cc instanceof RubyModule mod)) {
throw typeError(context, str(this, ids(this, path), " does not refer to class/module"));
Expand All @@ -2894,6 +2894,10 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti
return clazz;
}

private RaiseException classPathUndefinedException(String path, RubyClass undefinedExceptionClass, int p) {
return newRaiseException(undefinedExceptionClass, str(this, "undefined class/module ", ids(this, path.substring(0, p))));
}

private static boolean isJavaPackageOrJavaClassProxyType(final RubyModule type) {
return type instanceof JavaPackage || ClassUtils.isJavaClassProxyType(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public static RubyModule getModuleFromPath(ThreadContext context, String path) {
public static RubyClass getClassFromPath(ThreadContext context, String path) {
Ruby runtime = context.runtime;
final RubyModule value = runtime.getClassFromPath(path, runtime.getArgumentError(), false);
if (value == null) throw argumentError(context, "undefined class/module " + path);
if ( ! value.isClass() ) throw argumentError(context, path + " does not refer class");
return (RubyClass) value;
}
Expand Down