Skip to content
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

Closed
scabug opened this issue Nov 6, 2013 · 4 comments
Closed
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 6, 2013

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.

@scabug
Copy link
Author

scabug commented Nov 6, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7954?orig=1
Reporter: Nathan Stoddard (nstoddard)
Affected Versions: 2.10.3
See #2511
Attachments:

  • Main.scala (created on Nov 6, 2013 7:20:32 PM UTC, 357 bytes)

@scabug
Copy link
Author

scabug commented Nov 9, 2013

@retronym said:
Here's a branch that fixes this problem, including applying the strictfp annotation to the implementation class containing code in traits, and applying it to methods defined in nested classes or anoymous functions.

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.

@denisrosset
Copy link

Still present in 2.12.7! Using the prescribed workaround.

@SethTisue SethTisue added this to the Backlog milestone Oct 16, 2018
hrhino added a commit to hrhino/scala that referenced this issue Oct 22, 2018
(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.
@lrytz lrytz modified the milestones: Backlog, 2.12.8 Oct 26, 2018
@lrytz lrytz closed this as completed Oct 26, 2018
@lrytz
Copy link
Member

lrytz commented Oct 26, 2018

scala/scala#7356

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants