Permalink
Browse files

JRUBY-4754: NotImplementedError: the MD5() function is unimplemented …

…on this machine
  • Loading branch information...
1 parent 9e1d154 commit c31f18485ea0fcff6d68a59fd3ba89b5417857b6 @enebo enebo committed Apr 26, 2010
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/org/jruby/RubyDigest.java
@@ -405,16 +405,30 @@ public DigestBase(Ruby runtime, RubyClass type) {
if(type == runtime.fastGetModule("Digest").fastGetClass("Base")) {
throw runtime.newNotImplementedError("Digest::Base is an abstract class");
}
- if(!type.hasInternalVariable("metadata")) {
+
+ Metadata metadata = getMetadata(type);
+ if(metadata == null) {
throw runtime.newNotImplementedError("the " + type + "() function is unimplemented on this machine");
}
+
try {
- setAlgorithm((Metadata)type.getInternalVariable("metadata"));
+ setAlgorithm(metadata);
} catch(NoSuchAlgorithmException e) {
throw runtime.newNotImplementedError("the " + type + "() function is unimplemented on this machine");
}
}
+
+ // if subclass extends particular digest we need to walk to find it...we should rearchitect digest to avoid walking type systems
+ private Metadata getMetadata(RubyModule type) {
+ for (RubyModule current = type; current != null; current = current.getSuperClass()) {
+ Metadata metadata = (Metadata) current.getInternalVariable("metadata");
+
+ if (metadata != null) return metadata;
+ }
+
+ return null;
+ }
@JRubyMethod(optional = 1, frame = true)
public IRubyObject initialize(IRubyObject[] args, Block unusedBlock) {

0 comments on commit c31f184

Please sign in to comment.