Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4260

Improve error message for GroovyCastException by including some cause info

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.3
    • Fix Version/s: 1.7.4
    • Component/s: None
    • Labels:
      None

      Description

      Due to ClassCastException not supporting a 'cause', Groovy's GroovyClassException also doesn't support a cause. This sometimes hides useful debugging information. It would be good to partially support a cause by at least adding on the cause message to the message generated by GCE. E.g. for this code:

      java.awt.Dimension origin = [0, 'zero']
      

      current message:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[0, zero]' with class 'java.util.ArrayList' to class 'java.awt.Dimension'
      

      better to have this:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[0, zero]' with class 'java.util.ArrayList' to class 'java.awt.Dimension' due to: Could not find matching constructor for: java.awt.Dimension(java.lang.Integer, java.lang.String)
      

      And for this code:

      class Person {
        private int age
        Person(String s) { age = s /*.toInteger() // BUG hidden */ }
      }
      def p = ['45'] as Person
      

      current message:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[45]' with class 'java.util.ArrayList' to class 'Person'
      

      better to have this:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[45]' with class 'java.util.ArrayList' to class 'Person' due to: Cannot cast object '45' with class 'java.lang.String' to class 'java.lang.Number'
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              paulk Paul King
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: