Skip to content

Commit c54c163

Browse files
committed
Improve error from path search during Marshal.load
Fixes one failure from DRb tests in ruby/drb#36
1 parent 3165c38 commit c54c163

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

core/src/main/java/org/jruby/Ruby.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,7 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti
28622862
var context = getCurrentContext();
28632863

28642864
if (path.length() == 0 || path.charAt(0) == '#') {
2865-
throw typeError(context, str(this, "can't retrieve anonymous class ", ids(this, path)));
2865+
throw argumentError(context, str(this, "can't retrieve anonymous class ", ids(this, path)));
28662866
}
28672867

28682868
RubyModule clazz = getObject();
@@ -2874,17 +2874,19 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti
28742874

28752875
if ( p < length && path.charAt(p) == ':' ) {
28762876
if ( ++p < length && path.charAt(p) != ':' ) {
2877-
throw newRaiseException(undefinedExceptionClass, str(this, "undefined class/module ", ids(this, path)));
2877+
throw classPathUndefinedException(path, undefinedExceptionClass, p);
28782878
}
28792879
pbeg = ++p;
28802880
}
28812881

28822882
// FIXME: JI depends on const_missing getting called from Marshal.load (ruby objests do not). We should marshal JI objects differently so we do not differentiate here.
28832883
IRubyObject cc = flexibleSearch || isJavaPackageOrJavaClassProxyType(clazz) ?
2884-
clazz.getConstant(context, str) : clazz.getConstantAt(context, str);
2884+
clazz.constantTableFetch(str) : clazz.getConstantAt(context, str);
28852885

28862886
if (!flexibleSearch && cc == null) return null;
28872887

2888+
if (cc == null) throw classPathUndefinedException(path, undefinedExceptionClass, p);
2889+
28882890
if (!(cc instanceof RubyModule mod)) {
28892891
throw typeError(context, str(this, ids(this, path), " does not refer to class/module"));
28902892
}
@@ -2894,6 +2896,10 @@ public RubyModule getClassFromPath(final String path, RubyClass undefinedExcepti
28942896
return clazz;
28952897
}
28962898

2899+
private RaiseException classPathUndefinedException(String path, RubyClass undefinedExceptionClass, int p) {
2900+
return newRaiseException(undefinedExceptionClass, str(this, "undefined class/module ", ids(this, path.substring(0, p))));
2901+
}
2902+
28972903
private static boolean isJavaPackageOrJavaClassProxyType(final RubyModule type) {
28982904
return type instanceof JavaPackage || ClassUtils.isJavaClassProxyType(type);
28992905
}

core/src/main/java/org/jruby/runtime/marshal/MarshalLoader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public static RubyModule getModuleFromPath(ThreadContext context, String path) {
147147

148148
public static RubyClass getClassFromPath(ThreadContext context, String path) {
149149
Ruby runtime = context.runtime;
150-
final RubyModule value = runtime.getClassFromPath(path, runtime.getArgumentError(), false);
151-
if (value == null) throw argumentError(context, "undefined class/module " + path);
150+
final RubyModule value = runtime.getClassFromPath(path, runtime.getArgumentError(), true);
152151
if ( ! value.isClass() ) throw argumentError(context, path + " does not refer class");
153152
return (RubyClass) value;
154153
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy