java/src/json/ext/GeneratorMethods.java in json_pure-1.5.3 vs java/src/json/ext/GeneratorMethods.java in json_pure-1.5.4

- old
+ new

@@ -1,13 +1,14 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ package json.ext; +import java.lang.ref.WeakReference; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyBoolean; import org.jruby.RubyFixnum; import org.jruby.RubyFloat; @@ -22,11 +23,11 @@ import org.jruby.util.ByteList; /** * A class that populates the * <code>Json::Ext::Generator::GeneratorMethods</code> module. - * + * * @author mernen */ class GeneratorMethods { /** * Populates the given module with all modules and their methods @@ -43,13 +44,13 @@ defineMethods(module, "NilClass", RbNil.class); defineMethods(module, "Object", RbObject.class); defineMethods(module, "String", RbString.class); defineMethods(module, "TrueClass", RbTrue.class); - info.stringExtendModule = module.defineModuleUnder("String") - .defineModuleUnder("Extend"); - info.stringExtendModule.defineAnnotatedMethods(StringExtend.class); + info.stringExtendModule = new WeakReference<RubyModule>(module.defineModuleUnder("String") + .defineModuleUnder("Extend")); + info.stringExtendModule.get().defineAnnotatedMethods(StringExtend.class); } /** * Convenience method for defining methods on a submodule. * @param parentModule @@ -138,11 +139,11 @@ RubyString self) { Ruby runtime = context.getRuntime(); RubyHash result = RubyHash.newHash(runtime); IRubyObject createId = RuntimeInfo.forRuntime(runtime) - .jsonModule.callMethod(context, "create_id"); + .jsonModule.get().callMethod(context, "create_id"); result.op_aset(context, createId, self.getMetaClass().to_s()); ByteList bl = self.getByteList(); byte[] uBytes = bl.unsafeBytes(); RubyArray array = runtime.newArray(bl.length()); @@ -156,10 +157,10 @@ @JRubyMethod(required=1, module=true) public static IRubyObject included(ThreadContext context, IRubyObject vSelf, IRubyObject module) { RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime()); - return module.callMethod(context, "extend", info.stringExtendModule); + return module.callMethod(context, "extend", info.stringExtendModule.get()); } } public static class StringExtend { /**