New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@strictfp annotation causes ClassFormatError for abstract classes and traits #7954
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7954?orig=1
|
@retronym said: https://github.com/retronym/scala/compare/scala:2.10.x...ticket%2F7954?expand=1 I expect there are still some holes (value classes, for example), so I need to spend some more time testing this before submitting the patch. |
Still present in 2.12.7! Using the prescribed workaround. |
(Just getting my toes wet again.) The JVM accepts `ACC_STRICT` as a modifier flag on non-abstract methods only. Java itself accepts `strictfp` on both methods (in which case it applies to the method) and classes (in which case it applies to all methods within the class, as well as nested and inner classes thereof.) Scala has somewhat more ways of nesting methods and classes than Java, so I've extrapolated the rule to be: methods nested inside of a class/module/method definition marked `@strictfp` are strict. I also fixed the interaction with value classes: when a method body on a value class was moved to the companion, its `@strictfp` attribute wasn't moved along with it. The test case covers nested/inner/local classes and methods, as well as extension methods. I'm leaving specialization to the existing specialization+strictfp tests. Fixes scala/bug#7954.
The @Strictfp annotation is intended to standardize floating-point behavior across platforms, which I need for an application I'm developing. It can be applied to classes and concrete methods. Unfortunately, it currently fails when applied to abstract classes and traits. The attached .scala file demonstrates the problem. At runtime it fails with the error "java.lang.ClassFormatError: Method g in class A has illegal modifiers: 0xC01" or
"java.lang.ClassFormatError: Method f in class C has illegal modifiers: 0xC01". It appears that the Scala compiler is attempting to apply @Strictfp to abstract methods, which doesn't make sense and causes the JVM to throw an exception.
This bug can be worked around by applying @Strictfp to methods instead of classes. However, that would require applying it to every single concrete method, which would be very tedious, and it would be easy to miss some of them, which wouldn't cause any immediately obvious problems but might produce subtly different results on different platforms.
This bug occurs both when running the code in SBT and when compiling using scalac.
The text was updated successfully, but these errors were encountered: