Passing a block to JButton.new results in NPE
---------------------------------------------

                 Key: JRUBY-4087
                 URL: http://jira.codehaus.org/browse/JRUBY-4087
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
    Affects Versions: JRuby 1.4.0RC1
            Reporter: Charles Oliver Nutter
            Assignee: Charles Oliver Nutter


The following code produces an NPE:

{noformat}
include Java
import javax.swing.JButton
import javax.swing.JFrame

class JButton
 def initialize(name, &block)
   super(name)
   # Not using the block yet, but will later.
 end
end

class GUI < JFrame
 def initialize
   super('Title')
   ok_button = JButton.new('OK') { puts 'pressed OK' }
   content_pane.add(ok_button)
   pack
   self.default_close_operation = JFrame::EXIT_ON_CLOSE
 end
end

GUI.new.visible = true
{noformat}

It has been bisected back to c306f7f4b19162a83c1fa8f3b983e7e6c70083d9 as the 
original culprit. Note that the block passed to JButton.new is getting 
converted to an Icon instance and that causes the blowup. Here's the trace:

{noformat}
Swing$ jruby gui.rb
pressed OK
org/jruby/javasupport/JavaUtil.java:922:in `convertRubyToJavaInt':
java.lang.NullPointerException: null (NativeException)
       from org/jruby/gen/org/jruby/gen/InterfaceImpl271097958.gen:13:in
`getIconWidth'
       from javax/swing/SwingUtilities.java:890:in `layoutCompoundLabelImpl'
       from javax/swing/SwingUtilities.java:817:in `layoutCompoundLabel'
       from javax/swing/plaf/basic/BasicGraphicsUtils.java:262:in
`getPreferredButtonSize'
       from apple/laf/CUIAquaButton.java:450:in `getPreferredSize'
       from javax/swing/JComponent.java:1624:in `getPreferredSize'
       from java/awt/BorderLayout.java:690:in `preferredLayoutSize'
       from java/awt/Container.java:1558:in `preferredSize'
        ... 10 levels...
       from gui.rb:15:in `initialize'
       from gui.rb:22:in `new_proxy'
       from gui.rb:22
Swing$ jruby -v
jruby 1.4.0RC1 (ruby 1.8.7 patchlevel 174) (2009-09-30 80c263b) (Java
HotSpot(TM) Client VM 1.5.0_19) [i386-java]
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to