bug icon indicating copy to clipboard operation
bug copied to clipboard

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

Open scabug opened this issue 12 years ago • 21 comments

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.

scabug avatar Jan 23 '13 16:01 scabug

Imported From: https://issues.scala-lang.org/browse/SI-7014?orig=1 Reporter: Francois Armand (fanf) Affected Versions: 2.10.0, 2.10.2 See #7551

scabug avatar Jan 23 '13 16:01 scabug

Sebastian Meßmer (smessmer) said: same bug here. It's only a warning, but it's a disturbing one with a lot of output.

scabug avatar Feb 12 '13 20:02 scabug

Mariusz Sakowski (sakfa) said: Same thing here, major issue for me because Play Framework 2.0 gets confused when displaying normal compilation errors (displays this warning instead)

scabug avatar Apr 24 '13 10:04 scabug

Francois Armand (fanf) said: Since Scala 2.10.2, that bug simply terminate the build, so basically, I can't use Scala 2.10.2 on my project. I would qualify that one as blocker now - I'm stuck with Scala 2.10.1.

scabug avatar Jun 15 '13 10:06 scabug

@adriaanm said: sorry to hear it -- looking into it test files here: https://github.com/adriaanm/scala/tree/ticket-7014

scabug avatar Jun 15 '13 16:06 scabug

@gkossakowski said: Assigning to Adriaan who seemed to look into this. Feel free to unassign if you don't plan to work on this ticket.

scabug avatar Jun 18 '13 19:06 scabug

Francois Armand (fanf) said (edited on Jul 16, 2013 11:47:37 AM UTC): I just got eaten with the update to Scala-IDE 3.0.1 which uses Scala 2.10.2, and so is not usable on our project. So, that bug is starting to be really annoying.

All in all, I prefered the past behaviour, with hundreds of assert error lines in the log. Our build output were crap, but actually could build the project...

scabug avatar Jul 16 '13 11:07 scabug

Sonnenschein (sonnenschein) said: I've also voted for this issue to be resolved.

For the time being, I decided to package my single layer dealing with LDAP into a separate JAR which I than use as an unmanaged library. Since the rest doesn't need a dependency to UnboundID-SDK, I can keep out the annoying noise from the rest.

Peter

scabug avatar Jul 16 '13 11:07 scabug

Jun Yamog (jkyamog) said: Same here. We are using unboundid in our play app. So eclipse is reporting SBT is crashing. We haven't upgraded our play project, so command line compiling is still working.

scabug avatar Aug 12 '13 04:08 scabug

@adriaanm said: 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.

scabug avatar Aug 13 '13 19:08 scabug

@adriaanm said: 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.

scabug avatar Aug 13 '13 22:08 scabug

@adriaanm said (edited on Aug 13, 2013 10:18:44 PM UTC): Fix for crasher: https://github.com/scala/scala/pull/2829 (Don't close on merging.)

scabug avatar Aug 13 '13 22:08 scabug

@retronym said: See also #7551 / https://github.com/retronym/scala/compare/ticket;7551

commit b545e410e072600b1dc77c6b8536eb3c22cd657a
Author: Jason Zaugg <[email protected]>
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?

scabug avatar Aug 14 '13 06:08 scabug

Francois Armand (fanf) said: I can confirm that the workaround allows to build our project again, and avoid displaying horrible debug information on the stdout.

Thanks!

scabug avatar Sep 06 '13 15:09 scabug

Hendy Irawan (ceefour) said: +1 for this

scabug avatar Dec 28 '14 06:12 scabug

Does anyone know how to mute this class of warnings? Using a protoc based library that I cannot change and it is very noisy, with dozens of warnings.

everson avatar Sep 11 '24 04:09 everson

can you post a minimized reproducer?

lrytz avatar Sep 11 '24 12:09 lrytz

@lrytz https://github.com/everson/scala-7014-issue

Note that this is literally just reproducing OP's problem. The issue I am currently facing is of similar class, but depending on a library from another team internal to my company.

I had to remove ThisBuild / scalacOptions := Seq(..."-Xfatal-warnings") in order to move on, but I would hope to ignore just this class of exception, but keep using fatal-warnings, if possible.

Additionally, the code has dozens of instances of this issue, becoming very annoying.

everson avatar Sep 11 '24 17:09 everson

@everson are you familiar with -Wconf and/or @nowarn?

SethTisue avatar Sep 15 '24 19:09 SethTisue

Rigth, -Wconf:msg=scala/bug#7014:s for example.

lrytz avatar Sep 16 '24 14:09 lrytz

Sorry it took this long to respond. I wasn't familiar. Thank you both @SethTisue @lrytz!

everson avatar Oct 18 '24 03:10 everson