1 2 Previous Next 16 Replies Latest reply on Nov 28, 2009 8:25 PM by seto.kaibaseto.gmail.com

    Scala is NOT mature enough for Weld

      Scala is not mature enough for Weld (or any other reflection related operation). Turns out that one of the feature that make scala so interesting (closures) is also a source of incompatibility (the internal anonymous class files that generate are invalid)


      So, if for example, I have a code like this (inside any method in a class):


      val classNames = Conversions.convertList(names).reduceLeft[String] { (acc, n) =>
              acc + ", " + n
      }
      



      That generates an inner class that makes Java reflection unusable:


      java.lang.IncompatibleClassChangeError: com.googlecode.solder.dwr.WeldContainer and com.googlecode.solder.dwr.WeldContainer$$anonfun$getClasses$1 disagree on InnerClasses attribute
           at java.lang.Class.getDeclaringClass(Native Method)
           at java.lang.Class.getEnclosingClass(Class.java:1085)
           at java.lang.Class.getSimpleBinaryName(Class.java:1220)
           at java.lang.Class.getSimpleName(Class.java:1112)
           at org.jboss.weld.util.Names.typeToString(Names.java:251)
           at org.jboss.weld.util.Names.classToString(Names.java:263)
           at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:151)
           at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:133)
           at org.jboss.weld.resources.ClassTransformer$2.call(ClassTransformer.java:72)
           at org.jboss.weld.resources.ClassTransformer$2.call(ClassTransformer.java:68)
           at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
           at java.util.concurrent.FutureTask.run(FutureTask.java:138)
           at org.jboss.weld.util.collections.ConcurrentCache.putIfAbsent(ConcurrentCache.java:125)
           at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:67)
           at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:59)
           at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:86)
           at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:134)
           at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)
           at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:158)
           at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
           at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
           at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
           at org.apache.catalina.core.StandardService.start(StandardService.java:516)
           at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
           at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
           at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      



      Apparently this is a known problem since 2008-08-03 (16 months so far) and AFAIK they are not in a hurry to fix it.


      I guess that means I am going to have to start removing Scala from my Weld project. I am sad about this because Scala is IMO a really beautiful language, that feels much cleaner than Java, but if the .class files that it generates are not compatible with the rest of Java... it is just useless for me.


      One more thing... this is clearly a Scala bug, but... Is there any chance a workaround for this could be created in Weld? (Perhaps a way to tell Weld to ignore InnerClasses? or to just skip the corrupt ones? )

        • 1. Re: Scala is NOT mature enough for Weld
          asookazian
          • 2. Re: Scala is NOT mature enough for Weld

            Arbi Sookazian wrote on Nov 23, 2009 17:02:


            closures are added to jdk 7... http://www.infoq.com/news/2009/11/jdk7-simple-closures


            Yes, but the syntax is so ugly when compared with Scala :'(.

            • 3. Re: Scala is NOT mature enough for Weld
              asookazian

              Francisco Peredo wrote on Nov 23, 2009 15:19:


              One more thing... this is clearly a Scala bug, but... Is there any chance a workaround for this could be created in Weld? (Perhaps a way to tell Weld to ignore InnerClasses? or to just skip the corrupt ones? )


              How many JEE projects will actually use Weld and Scala?  I doubt there will be a workaround for this problem...

              • 4. Re: Scala is NOT mature enough for Weld

                Arbi Sookazian wrote on Nov 23, 2009 17:25:


                How many JEE projects will actually use Weld and Scala?  I doubt there will be a workaround for this problem...


                Maybe not many... certainly is unlikely that workaround comes from the Weld side... it is after all not a problem caused by Weld, but I guess it does not hurt to ask... ;-)


                • 5. Re: Scala is NOT mature enough for Weld

                  I am also hoping that some of the members of this community log in to the Scala bug tracker and vote to get this bug fixed by them... please?...

                  • 6. Re: Scala is NOT mature enough for Weld
                    asookazian

                    done, now you owe me an annotation-less, xml-less programming language that uses OODBMS exclusively.  thx.

                    • 7. Re: Scala is NOT mature enough for Weld

                      Thanks! How about an annotation-less, xml-less programming language that uses TRDBMS exclusively? ;-). It is all I can do for the moment...

                      • 8. Re: Scala is NOT mature enough for Weld
                        nickarls

                        OT but industry adoption of OODBMS is like a working fusion power plant, it's always 50 years away ;-)

                        • 9. Re: Scala is NOT mature enough for Weld
                          asookazian

                          we live in a world of objects (OOP) and entities and relations (E/R diagrams).


                          very similar concepts.  thus, hbm2ddl and hbm2java.  it would alleviate the OR mismatch but not sure how good of a solution OODBMS is in practice in terms of performance (heard it's better with InterSystems Cache) and data replication, reporting, ETL, management, etc.


                          it would mean no more sprocs and triggers.


                          ted neward is a big proponent of OODBMS... http://www.theserverside.com/news/thread.tss?thread_id=45523


                          he's also a big proponent of Scala, btw...

                          • 10. Re: Scala is NOT mature enough for Weld
                            swd847

                            If you are really keen you could register a java.lang.instrument.ClassFileTransformer with the JVM and fix the classes as they get loaded. I have no idea how difficult this would be, but it may be as simple as just adding an entry to the InnerClasses attribute of some class files.

                            • 11. Re: Scala is NOT mature enough for Weld

                              Stuart Douglas wrote on Nov 23, 2009 21:55:


                              If you are really keen you could register a java.lang.instrument.ClassFileTransformer with the JVM and fix the classes as they get loaded.


                              Interesting...



                              I have no idea how difficult this would be, but it may be as simple as just adding an entry to the InnerClasses attribute of some class files.


                              But perhaps too complex... do you have any links to examples of similar stuff?

                              • 12. Re: Scala is NOT mature enough for Weld

                                Arbi Sookazian wrote on Nov 23, 2009 20:31:


                                we live in a world of objects (OOP) and entities and relations (E/R diagrams).


                                Yes but the difference between those 2 approaches is way older than software development... and integrating them correctly is might require a very different approach to what is commonly done...



                                very similar concepts.  thus, hbm2ddl and hbm2java.


                                IMO as similar (and easy to mix) as water and oil...;-)




                                it would alleviate the OR mismatch but not sure how good of a solution OODBMS is in practice in terms of performance (heard it's better with InterSystems Cache) and data replication, reporting, ETL, management, etc.

                                it would mean no more sprocs and triggers.


                                Not sure that would be good in all cases...



                                ted neward is a big proponent of OODBMS... http://www.theserverside.com/news/thread.tss?thread_id=45523


                                Smart guys also make mistakes... ;-)



                                he's also a big proponent of Scala, btw...


                                I would prefer to use Scala to create a fully relational DSL... of course we could argue for hours if ScalaQL is an ORM, or if it is the implementation of a true relational language...

                                • 13. Re: Scala is NOT mature enough for Weld
                                  swd847

                                  From the JVM spec:





                                  If a class has members that are classes or interfaces, its constant_pool table (and hence its InnerClasses attribute) must refer to each such member, even if that member is not otherwise mentioned by the class. These rules imply that a nested class or interface member will have InnerClasses information for each enclosing class and for each immediate member.



                                  so it looks like the scala compiler is not following these rules. The transformer approach I mentioned will not really work because you need access to all the class information at once to make the correct transformaton. You could possibly add a build time step, but that is a lot of stuffing around to work around a compiler bug.

                                  • 14. Re: Scala is NOT mature enough for Weld
                                    seto.kaibaseto.gmail.com

                                    it seems that it has been fixed in the latest version.

                                    1 2 Previous Next