Uploaded image for project: 'Log Tool'
  1. Log Tool
  2. LOGTOOL-134

Incompatible type error with @Cause and ctors with unusual exception types

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Minor
    • 3.0.0.Final
    • 2.1.0.Final
    • None
    • Workaround Exists
    • Hide

      Use the Signature annotation like this:

          @Message(id = 442, value = "Unexpected Error")
          @Signature(String.class)
          EJBException unexpectedError(@Cause Throwable cause);
      
      Show
      Use the Signature annotation like this: @Message(id = 442, value = "Unexpected Error" ) @Signature( String .class) EJBException unexpectedError(@Cause Throwable cause);

    Description

      Incorrect generated code can be generated if an exception constructor's "cause" parameter is a subtype of Throwable (say, Exception) instead of being Throwable itself, and a @Cause parameter exists whose type is a superclass of that type (say, Throwable).

      The compilation errors can look something like this:

      2018-04-02 12:37:40 [ERROR] /home/david/src/java/wildfly/ejb3/target/generated-sources/annotations/org/jboss/as/ejb3/logging/EjbLogger_$logger.java:[3340,112] incompatible types: java.lang.Throwable cannot be converted to java.lang.Exception
      2018-04-02 12:37:40 [ERROR] /home/david/src/java/wildfly/ejb3/target/generated-sources/annotations/org/jboss/as/ejb3/logging/EjbLogger_$logger.java:[3479,164] incompatible types: java.lang.Error cannot be converted to java.lang.Exception
      

      If the @Cause method parameter type is not assignable to the exception's cause parameter type, then the initCause strategy should be used instead.

      Attachments

        Activity

          People

            jperkins-rhn James Perkins
            dlloyd@redhat.com David Lloyd
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: