Giter VIP home page Giter VIP logo

Comments (5)

enebo avatar enebo commented on August 24, 2024

ouch...so we are storing our proxies as constants, but $ is invalid as a constant name. Perhaps we can mangle the name somehow (perhaps risk very unlikely collision of using _ in place of $ ... or dollar)?

from jmx.

7er avatar 7er commented on August 24, 2024

Yep, that is my understanding too. Some mangling seems to be in order. You already have a method in the MBeans module that does some mangling already if the class name starts with a lowercase letter. Both dollar and _ sounds good to me and would fix the problem. Maybe dollar would make it pretty obvious what has happended?

I'll see if I can submit a patch for this tomorrow

from jmx.

enebo avatar enebo commented on August 24, 2024

Great...I guess go for 'dollar' in the patch (we can easily change this if a better idea comes along).

from jmx.

7er avatar 7er commented on August 24, 2024

In jmx.rb there is a one line change commented below

  module MBeans
    ##
    # Create modules in this namespace for each package in the Java fully
    # qualified name and return the deepest module along with the Java class
    # name back to the caller.
    def self.parent_for(java_class_fqn)
      java_class_fqn.split(".").inject(MBeans) do |parent, segment|
        # const_defined? will crash later if we don't remove $
        segment.gsub!('$', 'Dollar') if segment =~ /\$/
        # Note: We are boned if java class name is lower cased
        return [parent, segment] if segment =~ /^[A-Z]/

        segment.capitalize!
        unless parent.const_defined? segment
          parent.const_set segment, Module.new
        else 
          parent.const_get segment
        end
      end

    end
  end

I created to 2 test cases to guide the patch, put them somewhere if they seem useful

  def test_that_mbeans_parent_for_handles_classes_with_dollar_sign
    bean_module, class_name = JMX::MBeans.parent_for("evil.dollar.Pre$Middle$Post")
    assert_equal(JMX::MBeans::Evil::Dollar, bean_module)
    assert_equal("PreDollarMiddleDollarPost", class_name)
  end

  def test_mbeans_parent_for
    bean_module, class_name = JMX::MBeans.parent_for("com.example.JavaClass")
    assert_equal(JMX::MBeans::Com::Example, bean_module)
    assert_equal("JavaClass", class_name)
  end

from jmx.

enebo avatar enebo commented on August 24, 2024

Applied this one-liner and also added these tests to jmx_mangling_test.rb. I put out a 0.8 with this change as well. Thanks for the patch and tests!

from jmx.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.