Re: Lambda Expressions and JavaCompiler problem

Jeroen Frijters <[email protected]>
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <[email protected]>
Hi Alessandro,

Are you using the most recent IKVM snapshot?

Regards,
Jeroen

> -----Original Message-----
> From: Alessandro Montanari [mailto:[email protected]]
> Sent: Monday, July 7, 2014 9:43
> To: [email protected]
> Subject: [Ikvm-developers] Lambda Expressions and JavaCompiler problem
> 
> Hi,
> we are using IKVM to provide the .NET version of the tuProlog engine
> (http://apice.unibo.it/xwiki/bin/view/Tuprolog/).
> In the recent weeks we added support for lambdas expressions into the
> java version, so the user can write his own lambda ((s1,s2) ->
> s1.indexOf(s2) for example) and use it inside a prolog program.
> 
> In practice what we are doing in java is the following:
> 1 - at runtime we build the string of a class that contains the user's
> lambda, for example:
> public class MyLambda {
>      public java.util.function.BiFunction<String, String, Integer>
> getFunction() {
>       return <here the user's lambda>;
>      }
> }
> 2 - we use the class javax.tools.JavaCompiler to compile the class on
> the fly;
> 3 - we instantiate the class and then we use the function returned by
> the method "getFunction()".
> 
> In order to make it run on IKVM we added the following line before the
> retrieving of the JavaCompiler:
> ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("IKVM.OpenJDK
> .Tools"));
> jc = ToolProvider.getSystemJavaCompiler();
> 
> Now the problem is that when we try to excute what I described above
> with a user's lambda we get this error:
> An exception has occurred in the compiler (1.8.0-internal). Please file
> a bug at the Java Developer Connection
> (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade
> for duplicates. Include your program and the following diagnostic in
> your report.  Thank you.
> java.lang.ClassCastException: Unable to cast object of type
> 'java.util.PropertyResourceBundle' to type
> 'sun.util.resources.OpenListResourceBundle'.
>         at
> sun.util.resources.LocaleData.getCurrencyNames(LocaleData.java:84)
>         at
> sun.util.locale.provider.LocaleResources.getCurrencyName(LocaleResources
> .java:216)
>         at
> sun.util.locale.provider.CurrencyNameProviderImpl.getString(CurrencyName
> ProviderImpl.java:122)
>         at
> sun.util.locale.provider.CurrencyNameProviderImpl.getSymbol(CurrencyName
> ProviderImpl.java:90)
>         at
> java.util.Currency$CurrencyNameGetter.getObject(Currency.java:647)
>         at
> java.util.Currency$CurrencyNameGetter.getObject(Currency.java:625)
>         at
> sun.util.locale.provider.LocaleServiceProviderPool.getLocalizedObjectImp
> l(LocaleServiceProviderPool.java:281)
>         at
> sun.util.locale.provider.LocaleServiceProviderPool.getLocalizedObject(Lo
> caleServiceProviderPool.java:265)
>         at java.util.Currency.getSymbol(Currency.java:505)
>         at
> java.text.DecimalFormatSymbols.initialize(DecimalFormatSymbols.java:648)
>         at
> java.text.DecimalFormatSymbols.<init>(DecimalFormatSymbols.java:113)
>         at
> sun.util.locale.provider.DecimalFormatSymbolsProviderImpl.getInstance
> (DecimalFormatSymbolsProviderImpl.java:85)
>         at
> java.text.DecimalFormatSymbols.getInstance(DecimalFormatSymbols.java:181
> )
>         at java.util.Formatter.getZero(Formatter.java:2283)
>         at java.util.Formatter.<init>(Formatter.java:1892)
>         at java.util.Formatter.<init>(Formatter.java:1914)
>         at java.lang.StringHelper.format(StringHelper.java:2534)
>         at
> com.sun.tools.javac.comp.DeferredAttr$DeferredTypeMap.<init>(DeferredAtt
> r.java:677)
>         at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3789)
>         at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3583)
>         at
> com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3494)
>         at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3468)
>         at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3455)
>         at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1815)
>         at
> com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:14
> 59)
>         at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:597)
>         at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:645)
>         at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1596)
>         at
> com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java
> :1290)
>         at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:597)
>         at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:665)
>         at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:680)
>         at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1127)
>         at
> com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:903)
>         at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:597)
>         at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:665)
>         at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1020)
>         at
> com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:772)
>         at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:597)
>         at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:665)
>         at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4308)
>         at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4217)
>         at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4149)
>         at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4124)
>         at
> com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1252)
>         at
> com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:904)
>         at
> com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:864)
>         at com.sun.tools.javac.main.Main.compile(Main.java:530)
>         at
> com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
>         at
> com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
>         at
> alice.util.proxyGenerator.Generator.compile(Generator.java:58)
>         at alice.util.proxyGenerator.Generator.make(Generator.java:48)
>         at alice.tuprolog.lib.OOLibrary.new_lambda_3(OOLibrary.java:287)
>         at java.lang.reflect.Method.invoke(Method.java:472)
>         at
> alice.tuprolog.PrimitiveInfo.evalAsPredicate(PrimitiveInfo.java:123)
>         at
> alice.tuprolog.StateGoalEvaluation.doJob(StateGoalEvaluation.java:42)
>         at alice.tuprolog.Engine.run(Engine.java:78)
>         at alice.tuprolog.EngineRunner.solve(EngineRunner.java:179)
>         at alice.tuprolog.EngineManager.solve(EngineManager.java:227)
>         at alice.tuprolog.Prolog.solve(Prolog.java:435)
>         at alice.tuprolog.Prolog.solve(Prolog.java:455)
>         at alice.tuprologx.ide.EngineThread.run(EngineThread.java:52)
> Compile failed:
> public class MyLambdaFunction1 {
>   public java.util.function.BiFunction<String,String,Integer>
> getFunction() {
>                 return (s1,s2) -> s1.indexOf(s2);
>   }
> }
> 
> Does anybody have any idea?
> 
> Thank you,
> Alessandro
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.