Frege / frege-native-gen

Frege code generator for Java classes
17 stars 9 forks source link

fix issue of classFor. (causes ExceptionInInitializerError) #2

Closed cytb closed 10 years ago

cytb commented 10 years ago

When I used native-gen to the eclipse-jdt jars (AST Parsers), following error occured:

Exception in thread "main" java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:259) at frege.nativegen.java.Lang.eval(Lang.java:831) ...

"ExceptionInInitializerError" is raised when the static initializer failed. And above dump is caused by Class.forName in function classFor.

According to http://stackoverflow.com/a/7099453, the method "java.lang.Class.forName" calls static initializer 'clinit' on loading the classes, and the native-gen uses 'java.lang.Class' object only for metainfo, thus, I think this behavior won't be necessary. In contrast, the "java.lang.ClassLoader.loadClass" doesn't call 'clinit', and I suppose it will be better.

Thank you for reading this.

mmhelloworld commented 10 years ago

Thank you so much for fixing this and for the details!

I am really interested on how you are using Frege with eclipse-jdt. If you don't mind, could you please share it with Frege mailing list?

cytb commented 10 years ago

I'm grateful for your advice. I have updated and pushed to my repo. Well... I'm sorry for sending pull-request without creating new branch.

I am really interested on how you are using Frege with eclipse-jdt. If you don't mind, could you please share it with Frege mailing list?

Sure. but cannot now. I haven't done almost. I'll use Frege with ASTParser classes in Eclipse-JDT jars to transrate Java7/8 to 5 (or 6). All I had done is attempt to extract and export the classes in eclipse-jdt jars, and a few others. and failed with org.eclipse.jdt.internal.core.ClasspathEntry. (might not be needed).

mmhelloworld commented 10 years ago

Thank you!