tags:

views:

135

answers:

1

Hi SO,

I searched the web for it but could not find any hint how to enforce srictfp in Scala. There are some people complaining about it but real solutions cannot be found. There is a bugtracker entry about it which is almost two years old. As it seems there is no elegant fix for it on the way I'm looking for workarounds.

My current Idea is to set the appropiate method flag ACC_STRICT in the generated bytecode by myself somehow but I have no Idea what would be the best solution to do so. A Scala Compiler Plugin comes to mind or just hacking flags in a hex editor. Maybe someone faced the same challenge and can tell me his or her solution?

-Malax

+3  A: 

You could add a post-processor in your build process that would add the strictfp modifier to the generated class (i.e. setting the ACC_STRICT flag as you say).

You can implement such a post-processor using Javassist for example. This could look like this:

CtClass clazz = ClassPool.getDefault().makeClass(
                    new FileInputStream("old/HelloWorld.class"));

CtMethod method = clazz.getDeclaredMethod("testMethod");

method.setModifiers(method.getModifiers() | Modifier.STRICT);

clazz.detach();
clazz.toBytecode(new DataOutputStream(new FileOutputStream(
    "new/HelloWorld.class")));

You would then have to find a way to configure which classes/method need to be modified this way.

Bruno
This looks promising and way easier than developing a Scala Compiler Plugin - i will try that and will trigger setting the `ACC_STRICT` flag if a given annotation is set. Should be a no-brainer. Thanks! :)
Malax