JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-3957

Not possible to 'rescue' exception caused by illegal argument involving a static field

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.4
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: None
    • Labels:
      None
    • Environment:
      java 1.6.0_10, ubuntu 8.10
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      If you try to assign a java String to a java static field of type Integer an IllegalArgumentException is raised. However if you wrap that code in begin/rescue, the rescue block is never executed and basically your program crashes.

      Example:

      If you have the following java class:

      package com.mycompany
      
      public class SomeClass {
        public static Integer staticIntegerField = null;
      }
      

      and then try and run the ruby code below, the rescue block will not get called.

      def this_will_crash
        Java::com.mycompany.SomeClass.staticIntegerField = Java::java.lang.String.new("blah")
      rescue Exception => ex
        # this will not get executed
        puts "Phew. I caught the error"
      end
      

      Additional Notes

      I've attached a test case patch.

        Activity

        Hide
        Andrew Davey added a comment -

        Dammit. Forgot to hit preview.

        The example was supposed to look like:

        Example:

        If you have the following java class:

        package com.mycompany
        
        public class SomeClass {
          public static Integer staticIntegerField = null;
        }
        

        and then try and run the ruby code below, the rescue block will not get called.

        def this_will_crash
          Java::com.mycompany.SomeClass.staticIntegerField = Java::java.lang.String.new("blah")
        rescue Exception => ex
          # this will not get executed
          puts "Phew. I caught the error"
        end
        
        Show
        Andrew Davey added a comment - Dammit. Forgot to hit preview. The example was supposed to look like: Example: If you have the following java class: package com.mycompany public class SomeClass { public static Integer staticIntegerField = null ; } and then try and run the ruby code below, the rescue block will not get called. def this_will_crash Java::com.mycompany.SomeClass.staticIntegerField = Java::java.lang. String . new ( "blah" ) rescue Exception => ex # this will not get executed puts "Phew. I caught the error" end
        Hide
        Charles Oliver Nutter added a comment -

        Needs a spec, but it's working in 1.4.

        Show
        Charles Oliver Nutter added a comment - Needs a spec, but it's working in 1.4.
        Hide
        Charles Oliver Nutter added a comment -

        On second this, this should probably be raising a normal Ruby error like TypeError, rather than just failing over to the Java error. I've made this fix in 007b8e9, but this still needs a spec. Since a missing spec will not block 1.5, I'm punting off that release.

        Show
        Charles Oliver Nutter added a comment - On second this, this should probably be raising a normal Ruby error like TypeError, rather than just failing over to the Java error. I've made this fix in 007b8e9, but this still needs a spec. Since a missing spec will not block 1.5, I'm punting off that release.
        Hide
        Charles Oliver Nutter added a comment -

        For JRuby 1.7, we now propagate the actual error, and for JRuby 1.6 we made rescue of Object or Exception also rescue Java errors.

        Show
        Charles Oliver Nutter added a comment - For JRuby 1.7, we now propagate the actual error, and for JRuby 1.6 we made rescue of Object or Exception also rescue Java errors.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Andrew Davey
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: