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
'class file is broken' error when extending Java static inner classes #2464
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2464?orig=1
|
@dragos said: |
@paulp said: I am going on a bytecode-tool-writing kick right now. Reconciling all the java and scala factors in the tricky interdependent attribute areas like InnerClasses is simply too hard. We're not going to get it right without validating the result. |
Brian Hsu (brianhsu) said: This is a code that use Google Mpas API in Android. In Google Maps API, MapView class has a static inner class witch extends from android.view.ViewGroup.LayoutParams which in turns another static inner class of ViewGroup. Here is the sample code: import android.os.Bundle
import android.widget.LinearLayout
import com.google.android.maps.MapActivity
import com.google.android.maps.MapView
class TestMap extends MapActivity
{
type F = MapView.LayoutParams // This will caused compiler crash
override def isRouteDisplayed () = false
override def onCreate(savedInstanceState: Bundle)
{
val mapView: MapView = null // This line also crash compiler
}
} When using the following commands to compile /opt/scala-svn/bin/scalac -cp android.jar:maps.jar Test.scala The compiler will complain error: error while loading MapView, Missing dependency 'class android.view.ViewGroup$$LayoutParams', required by /opt/android-sdk-update-manager/add-ons/google_apis-7_r01/libs/maps.jar(com/google/android/maps/MapView.class)
error: error while loading LayoutParams, Missing dependency 'class android.view.ViewGroup$$LayoutParams', required by /opt/android-sdk-update-manager/add-ons/google_apis-7_r01/libs/maps.jar(com/google/android/maps/MapView$$LayoutParams.class)
two errors found The scala compiler version is svn trunk at 2010-03-26 |
papamitra said: Maybe maps.jar (Google Maps API in Android) is broken. And, it writes in mkstubs's README.txt, The generated constructors are not proper. They do not invoke the matching super() before the generated throw exception. Any attempt to load such a class should trigger an error from the byte code verifier or the class loader. I replace MapView.class and MapController.class in maps.jar with the following files. http://gist.github.com/454723 And, work it. |
@paulp said:
Well that's an interesting thing to find out at this stage of the game. Thanks. But even if we exclude maps.jar from consideration there are other examples of the issue with no such excuse. |
@michelou said: Case 2 (from brianhsu) is fixed in rev22630. That case did in particular affect Android code (I had myself to disable Android examples such as MapsDemo, Wiktionary, Panoramio, WindWaves, see rev22631). |
Stefan Endrullis (xylo) said (edited on Feb 24, 2013 7:50:14 PM UTC): It's easy to reproduce. I bundled a tiny example project into the attached zip archive. To compile it just run The only Scala file included in the project is a one-liner: Obviously it's not even necessary to refer to the "broken" class directly in the Scala code in order to let the compiler fail. And there is unfortunately nothing I can do to work around this except to avoid the class org.vaadin.sasha.portallayout.PortalLayout in my project completely. Regards, |
Stefan Endrullis (xylo) said (edited on Apr 25, 2013 4:15:48 PM UTC): Scala seems to be no longer compatible with vaadin. That's very disappointing. :( |
@paulp said: Here's the code part: https://github.com/paulp/scala/tree/issue/2464 |
John Nestor (nestorpersist) said: If you have a fix I would be happy to try out your snapshot scala compiler with the fix on my project if you can make it available. |
@paulp said: |
Stefan Endrullis (xylo) said (edited on May 2, 2013 10:35:15 AM UTC): Compilation: |
Stefan Endrullis (xylo) said: |
@retronym said: With Paul's patch in place to change this from a crasher to a warning, we get: sym = {scala.reflect.internal.Symbols$TermSymbol@4573}"value EAGER"
sym.owner = {scala.reflect.internal.Symbols$ModuleClassSymbol@4580}"module class ClientWidget$LoadStyle"
sym.owner.owner = {scala.reflect.internal.Symbols$PackageClassSymbol@4582}"package ui"
sym.owner.owner.info.decl(this.global.newTermName("ClientWidget")).info.decls.toList(1).moduleClass
= {scala.reflect.internal.Symbols$ModuleClassSymbol@5792}"module class LoadStyle" I think the root bug is the existence of I haven't managed yet to distill the essence of Stefan's test case to something independent from those JARs. |
@retronym said (edited on Jun 6, 2013 4:02:06 PM UTC):
package org.vaadin.sasha.portallayout;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.vaadin.sasha.portallayout.client.ui.VPortalLayout;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.Component;
import com.vaadin.ui.ClientWidget.LoadStyle;
/**
* Layout that presents its contents in a portal style.
* @author p4elkin
*/
@SuppressWarnings("serial")
@ClientWidget(value = VPortalLayout.class, loadStyle = LoadStyle.EAGER)
public class PortalLayout extends AbstractLayout {
I tried to compile a stripped down version of that class: package test;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.ClientWidget.LoadStyle;
@ClientWidget(value = com.vaadin.terminal.gwt.client.Paintable.class, loadStyle = LoadStyle.EAGER)
public abstract class PortalLayout extends AbstractLayout {
}
The JAR file containing the class in question contains: META-INF:
rebel.xml
The repository doesn't have an Ant/Maven build or the like. Not sure what Java compiler generated that bytecode, nor which tools had their way with it. (This is all GWT related, maybe that gets involved.) The JVM spec offers:
Long story short, I'll submit Paul's patch to make us resilient against such bytecode. |
@retronym said: |
Hassan Sultan (hassan.sultan) said: |
The Scala compiler gives an erroneous 'class file broken' error when trying to use classes that inherit from static Java inner classes. This is particularly a problem when integrating with Java code generated by the [http://incubator.apache.org/thrift/ Apache Thrift] compiler. Below are the files and steps needed to reproduce the problem.
!ClassOne.java:
!ClassTwo.java:
!ScalaClasses.scala:
Bug.scala:
And the following compilation sequence:
The compilation of Bug.scala will fail with the following error on 2.7.5:
And this error on 2.8.0-b20090919135825:
The text was updated successfully, but these errors were encountered: