Scala Programming Language
  1. Scala Programming Language
  2. SI-7014

Support forward reference from annotation argument to member of the annotated class.

    Details

      Description

      With Scalac 2.10, the use of any objects, class or method annotaded with the com.unboundid.util.ThreadSafetyLevel leads to java.lang.AssertionError.

      For example, the following file Test.scala:

      import com.unboundid.ldap.sdk.Entry
      
      object Test extends App {
        
        val foo = new Entry("plop")
        
      }
      

      Leads to :

      % scalac -classpath ./lib/unboundid-ldapsdk-2.3.1.jar src/Test.scala
      warning: Caught: java.lang.AssertionError: assertion failed: 
           while compiling: src/Test.scala
              during phase: global=typer, atPhase=parser
           library version: version 2.10.0
          compiler version: version 2.10.0
        reconstructed args: -classpath ./lib/unboundid-ldapsdk-2.3.1.jar
      
        last tree to typer: Ident(Entry)
                    symbol: <none> (flags: )
         symbol definition: <none>
             symbol owners: 
            context owners: value foo -> object Test -> package <empty>
      
      == Enclosing template or block ==
      
      Template( // val <local Test>: <notype> in object Test
        "App" // parents
        ValDef(
          private
          "_"
          <tpt>
          <empty>
        )
        // 2 statements
        DefDef( // def <init>: <?> in object Test
          <method>
          "<init>"
          []
          List(Nil)
          <tpt>
          Block(
            Apply(
              super."<init>"
              Nil
            )
            ()
          )
        )
        ValDef( // private[this] val foo: <?> in object Test
          private <local> <locked>
          "foo"
          <tpt>
          Apply(
            new Entry."<init>"
            "plop"
          )
        )
      )
      
      com.unboundid.util.ThreadSafetyLevel while parsing annotations in ./lib/unboundid-ldapsdk-2.3.1.jar(com/unboundid/util/ThreadSafetyLevel.class)
      one warning found
      

      ThreadSafety.java source here: http://ldap-sdk.svn.sourceforge.net/viewvc/ldap-sdk/trunk/src/com/unboundid/util/ThreadSafety.java?revision=410&view=markup

      Link to unboundid-ldapsdk-2.3.1.jar: https://www.unboundid.com/products/ldap-sdk/files/unboundid-ldapsdk-2.3.1-se.zip

      That seems to be linked to the following comment: https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala#L1033

      // We want to be robust when annotations are unavailable, so the very least
      // we can do is warn the user about the exception
      // There was a reference to ticket 1135, but that is outdated: a reference to a class not on
      // the classpath would not end up here. A class not found is signaled
      // with a `FatalError` exception, handled above. Here you'd end up after a NPE (for example),
      // and that should never be swallowed silently.

        Issue Links

          Activity

          Hide
          Adriaan Moors added a comment -

          Looks like RUNTIME retention annotations aren't supported: https://github.com/scala/scala/blob/2.10.x/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala#L911

          Not sure what we can do for this in 2.10, as this is now a maintenance release. Happy to take PRs.
          I'll still see if I can avoid the crash and continue with a dummy or something.

          Show
          Adriaan Moors added a comment - Looks like RUNTIME retention annotations aren't supported: https://github.com/scala/scala/blob/2.10.x/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala#L911 Not sure what we can do for this in 2.10, as this is now a maintenance release. Happy to take PRs. I'll still see if I can avoid the crash and continue with a dummy or something.
          Hide
          Adriaan Moors added a comment -

          I jumped to conclusions: the problem is the forward reference from the annotation argument to a member of the annotated class. We won't be able to fix this for 2.10.3, but I'll submit a PR that turns the crash into a warning. You should be able to compile normally, I assume.

          Show
          Adriaan Moors added a comment - I jumped to conclusions: the problem is the forward reference from the annotation argument to a member of the annotated class. We won't be able to fix this for 2.10.3, but I'll submit a PR that turns the crash into a warning. You should be able to compile normally, I assume.
          Hide
          Adriaan Moors added a comment - - edited

          Fix for crasher: https://github.com/scala/scala/pull/2829
          (Don't close on merging.)

          Show
          Adriaan Moors added a comment - - edited Fix for crasher: https://github.com/scala/scala/pull/2829 (Don't close on merging.)
          Hide
          Jason Zaugg added a comment -

          See also SI-7551 / https://github.com/retronym/scala/compare/ticket;7551

          commit b545e410e072600b1dc77c6b8536eb3c22cd657a
          Author: Jason Zaugg <jzaugg@gmail.com>
          Date: Tue Jun 4 09:32:36 2013 +0200

          WIP SI-7551 Ignore class file parser cycles in annotations

          But should we be parsing runtime visible annotations other than
          ScalaSignature at all?

          Show
          Jason Zaugg added a comment - See also SI-7551 / https://github.com/retronym/scala/compare/ticket;7551 commit b545e410e072600b1dc77c6b8536eb3c22cd657a Author: Jason Zaugg <jzaugg@gmail.com> Date: Tue Jun 4 09:32:36 2013 +0200 WIP SI-7551 Ignore class file parser cycles in annotations But should we be parsing runtime visible annotations other than ScalaSignature at all?
          Hide
          Francois Armand added a comment -

          I can confirm that the workaround allows to build our project again, and avoid displaying horrible debug information on the stdout.

          Thanks!

          Show
          Francois Armand added a comment - I can confirm that the workaround allows to build our project again, and avoid displaying horrible debug information on the stdout. Thanks!

            People

            • Assignee:
              Unassigned
              Reporter:
              Francois Armand
            • Votes:
              7 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

              • Created:
                Updated:

                Development