Skip to content
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

scala: error while loading Vector$1, class file ... is broken #7455

Closed
scabug opened this issue May 4, 2013 · 30 comments
Closed

scala: error while loading Vector$1, class file ... is broken #7455

scabug opened this issue May 4, 2013 · 30 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 4, 2013

scala: error while loading Vector$1, class file 'C:\Program Files\Java\jdk1.7.0_21\jre\lib\rt.jar(java/util/Vector$1.class)' is broken
(class java.util.NoSuchElementException/key not found: E)

I am not using scala-swing, but I am using Swing components directly. My code compiles OK in Scala 2.9.3. I don't know how to find any useful log information. I have 80,000 LOC so it will be extremely difficult to narrow down where the problem is.

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7455?orig=1
Reporter: Rick Mugridge (rickmugridge)
Affected Versions: 2.10.1, 2.11.0-M2
Other Milestones: 2.11.0-M6
See #7482
Attachments:

Loading

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

@retronym said:
To help us to troubleshoot, could you could please add -Ydebug to your compilation options. You will get a ton of output, but the part before the crash will be helpful.

Could you also try to compile against JDK 1.6?

Loading

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

Rick Mugridge (rickmugridge) said:
OK, will do.

I have compiled successfully against jdk1.6. But I need to uses jdk1.7 because I'm about to use Javafx and that's not compile-consistent across 6 and 7.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

@paulp said:
It's a safe bet he's using something which treats java.util.Vector as a raw type. That E is its type parameter.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

Rick Mugridge (rickmugridge) said:
Here's the last part:

Information:scala: [running phase inliner on 14 compilation units]
Information:scala: [running phase inlineExceptionHandlers on 14 compilation units]
Information:scala: [running phase closelim on 14 compilation units]
Information:scala: [running phase dce on 14 compilation units]
Information:scala: [running phase jvm on icode]
Information:scala: [running phase parser on 35 compilation units]
Information:scala: [running phase namer on 35 compilation units]
Information:scala: [running phase packageobjects on 35 compilation units]
Information:scala: [running phase typer on 35 compilation units]
Information:scala: [running phase patmat on 35 compilation units]
Information:scala: [running phase superaccessors on 35 compilation units]
Information:scala: [running phase extmethods on 35 compilation units]
Information:scala: [running phase pickler on 35 compilation units]
Information:scala: [running phase refchecks on 35 compilation units]
Information:scala: [running phase uncurry on 35 compilation units]
Information:scala: [running phase tailcalls on 35 compilation units]
Information:scala: [running phase specialize on 35 compilation units]
Information:scala: [running phase explicitouter on 35 compilation units]
Information:scala: [running phase erasure on 35 compilation units]
Information:scala: [running phase posterasure on 35 compilation units]
Information:scala: [running phase lazyvals on 35 compilation units]
Information:scala: [running phase lambdalift on 35 compilation units]
Information:scala: [running phase constructors on 35 compilation units]
Information:scala: [running phase flatten on 35 compilation units]
Information:scala: [running phase mixin on 35 compilation units]
Information:scala: [running phase cleanup on 35 compilation units]
Information:scala: [running phase icode on 35 compilation units]
Information:scala: [running phase inliner on 35 compilation units]
Information:scala: [running phase inlineExceptionHandlers on 35 compilation units]
Information:scala: [running phase closelim on 35 compilation units]
Information:scala: [running phase dce on 35 compilation units]
Information:scala: [running phase parser on 719 compilation units]
Information:scala: [running phase namer on 719 compilation units]
Information:scala: [running phase packageobjects on 719 compilation units]
Information:scala: [running phase typer on 719 compilation units]
Information:scala: [running phase patmat on 719 compilation units]
Information:scala: [running phase superaccessors on 719 compilation units]
Information:scala: [running phase extmethods on 719 compilation units]
Information:scala: [running phase pickler on 719 compilation units]
Information:Compilation completed with 1 error and 392 warnings in 57 sec
Information:1 error
Information:392 warnings
Error:scala: error while loading Vector$1, class file 'C:\Program Files\Java\jdk1.7.0_07\jre\lib\rt.jar(java/util/Vector$1.class)' is broken
(class java.util.NoSuchElementException/key not found: E)

(Note: in IntelliJ, I have 3 modules that are compiled.)

Loading

@scabug
Copy link
Author

@scabug scabug commented May 4, 2013

Rick Mugridge (rickmugridge) said:
I have 23 jars on my classpath, the oldest from 2010 (jmock-2.6.0-RC2.jar, although that uses generics).

It's odd, though, that the compiler is OK with jdk1.6.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 5, 2013

@paulp said:
I see by inspection that the jdk itself still uses Vector as a raw type all over the place, even in current 1.8. We're probably going to have to get this situation under better control. Here are some files which (according to barely spot-checked grep, this isn't a scientific survey) use Vector as a raw type.

java/awt/CardLayout.java
java/awt/font/LineBreakMeasurer.java
java/awt/geom/Area.java
java/awt/image/MemoryImageSource.java
java/awt/image/renderable/ParameterBlock.java
java/awt/image/renderable/RenderableImageOp.java
java/awt/image/renderable/RenderableImageProducer.java
java/awt/print/Book.java
javax/accessibility/AccessibleRelationSet.java
javax/accessibility/AccessibleStateSet.java
javax/imageio/spi/IIORegistry.java
javax/print/MimeType.java
javax/print/attribute/SetOfIntegerSyntax.java
javax/print/attribute/standard/MediaSize.java
javax/sound/sampled/AudioSystem.java
javax/swing/JComponent.java
javax/swing/KeyboardManager.java
javax/swing/plaf/basic/BasicDirectoryModel.java
javax/swing/plaf/multi/MultiButtonUI.java
javax/swing/plaf/multi/MultiColorChooserUI.java
javax/swing/plaf/multi/MultiComboBoxUI.java
javax/swing/plaf/multi/MultiDesktopIconUI.java
javax/swing/plaf/multi/MultiDesktopPaneUI.java
javax/swing/plaf/multi/MultiFileChooserUI.java
javax/swing/plaf/multi/MultiInternalFrameUI.java
javax/swing/plaf/multi/MultiLabelUI.java
javax/swing/plaf/multi/MultiListUI.java
javax/swing/plaf/multi/MultiMenuBarUI.java
javax/swing/plaf/multi/MultiMenuItemUI.java
javax/swing/plaf/multi/MultiOptionPaneUI.java
javax/swing/plaf/multi/MultiPanelUI.java
javax/swing/plaf/multi/MultiPopupMenuUI.java
javax/swing/plaf/multi/MultiProgressBarUI.java
javax/swing/plaf/multi/MultiRootPaneUI.java
javax/swing/plaf/multi/MultiScrollBarUI.java
javax/swing/plaf/multi/MultiScrollPaneUI.java
javax/swing/plaf/multi/MultiSeparatorUI.java
javax/swing/plaf/multi/MultiSliderUI.java
javax/swing/plaf/multi/MultiSpinnerUI.java
javax/swing/plaf/multi/MultiSplitPaneUI.java
javax/swing/plaf/multi/MultiTabbedPaneUI.java
javax/swing/plaf/multi/MultiTableHeaderUI.java
javax/swing/plaf/multi/MultiTableUI.java
javax/swing/plaf/multi/MultiTextUI.java
javax/swing/plaf/multi/MultiToolBarUI.java
javax/swing/plaf/multi/MultiToolTipUI.java
javax/swing/plaf/multi/MultiTreeUI.java
javax/swing/plaf/multi/MultiViewportUI.java
javax/swing/table/DefaultTableModel.java
javax/swing/text/GapContent.java
javax/swing/text/StringContent.java
javax/swing/text/html/HTMLDocument.java
javax/swing/text/html/StyleSheet.java
javax/swing/tree/DefaultMutableTreeNode.java
javax/xml/soap/MimeHeaders.java

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@retronym said:
I still can't figure out how to reproduce this.

scala> :javap -p javax.swing.tree.DefaultMutableTreeNode
Compiled from "DefaultMutableTreeNode.java"
public class javax.swing.tree.DefaultMutableTreeNode implements java.lang.Cloneable,javax.swing.tree.MutableTreeNode,java.io.Serializable {
  ...
  protected java.util.Vector children;
  ...
}

scala> (new javax.swing.tree.DefaultMutableTreeNode { def foo = children }).foo
res1: java.util.Vector[_] = null

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@paulp said:
Me neither, but I notice:

// java6
class java.util.Vector$1 extends java.lang.Object implements java.util.Enumeration
// java7
class java.util.Vector$1 extends java.lang.Object implements java.util.Enumeration<E>

And here's Mr. E:

scala> classOf[java.util.Vector[_]].getGenericInterfaces.head
res0: java.lang.reflect.Type = java.util.List<E>
// or for that matter
scala> classOf[java.util.Vector[String]].getGenericInterfaces.head
res1: java.lang.reflect.Type = java.util.List<E>

What is this all about? Why won't it infer (or even allow) Vector[String] ?

scala> val v = new java.util.Vector[String]
v: java.util.Vector[_] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String]
<console>:7: error: type mismatch;
 found   : java.util.Vector[?0] where type ?0
 required: java.util.Vector[String]
       val v: java.util.Vector[String] = new java.util.Vector[String]
                                         ^

This has a weirdly familiar feel. You get one bite at the apple, then it's over.

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
<console>:7: error: type mismatch;
 found   : Int(5)
 required: java.util.Collection[_ <: String]
       val v: java.util.Vector[String] = new java.util.Vector[String](5)
                                                                      ^

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@retronym said:
I can't repro:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home qbin/scala
Welcome to Scala version 2.10.2-20130511-121419-aa7568e816 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_17).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String](5)
v: java.util.Vector[String] = []

scala> val v = new java.util.Vector[String]
v: java.util.Vector[String] = []

scala> val v: java.util.Vector[String] = new java.util.Vector[String]
v: java.util.Vector[String] = []

scala> classOf[java.util.Vector[String]].getGenericInterfaces.head
res0: java.lang.reflect.Type = java.util.List<E>

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@paulp said:
Interesting, it's 100% reliable for me with both java6 and java7. I wonder the difference.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@paulp said:
Oh, it's trunk vs. 2.10.1.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@paulp said:
That's an undesirable development because it probably means it's my doing.

Loading

@scabug
Copy link
Author

@scabug scabug commented May 15, 2013

@paulp said:
Yep. Regressed in 9e101a3de8 .

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 4, 2013

Joel Galenson (jgalenson) said:
I can reliably reproduce a similar issue (JList$1 not Vector$1).

When I compile the attached file with scalac, it compiles correctly and runs. However, when I run "sbt compile" I get the following error:

[error] error while loading JList$1, class file '/opt/oracle-jdk-bin-1.7.0.25/jre/lib/rt.jar(javax/swing/JList$1.class)' is broken
[error] (key not found: E)

I'm using Scala 2.10.2, Java 1.7.0.25, sbt 0.12.4 (with its default configuration, which tries to compile with Scala 2.9.2, although that doesn't seem to make a difference).

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 16, 2013

@retronym said:
For the record, the raw type regression that Paul highlighted was fixed in scala/scala#2545

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

@retronym said:
Thanks Joel, that test case is really useful.

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

@retronym said (edited on Jul 17, 2013 12:44:03 AM UTC):
Strange, the problem does seems specific to compilation through SBT.

/code/scratch3 cat build.sbt
scalaVersion := "2.10.2"

% cat test.scala
import javax.swing.JList

class ScalaList(elems: Array[String]) extends JList[String](elems) { }

% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/ scalac-hash v2.10.2 /Users/jason/code/scratch3/test.scala
[info] v2.10.2 => /Users/jason/usr/scala-v2.10.2-0-g60d462e

% JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/ scalac-hash v2.10.2 /Users/jason/code/scratch3/test.scala
[info] v2.10.2 => /Users/jason/usr/scala-v2.10.2-0-g60d462e

% sbt -java-home $JAVA_HOME_170 -verbose compileDetected sbt version 0.13.0-RC2
Using /Users/jason/.sbt/0.13.0-RC2 as sbt dir, -sbt-dir to override.
# Executing command line:
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java
-Xms1536m
-Xmx1536m
-XX:MaxPermSize=384m
-XX:ReservedCodeCacheSize=192m
-Dsbt.global.base=/Users/jason/.sbt/0.13.0-RC2
-jar
/usr/local/bin/../Cellar/sbt/0.12.1/bin/.lib/0.13.0-RC2/sbt-launch.jar
compile

[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source to /Users/jason/code/scratch3/target/scala-2.10/classes...
[error] error while loading JList$1, class file '/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar(javax/swing/JList$1.class)' is broken
[error] (class java.util.NoSuchElementException/key not found: E)
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 2 s, completed Jul 17, 2013 10:41:04 AM

% sbt -java-home $JAVA_HOME_170 "export compile"
Detected sbt version 0.13.0-RC2
Using /Users/jason/.sbt/0.13.0-RC2 as sbt dir, -sbt-dir to override.
[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source to /Users/jason/code/scratch3/target/scala-2.10/classes...
[error] error while loading JList$1, class file '/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar(javax/swing/JList$1.class)' is broken
[error] (class java.util.NoSuchElementException/key not found: E)
[error] one error found
[error] (compile:compile) Compilation failed
scalac -classpath /Users/jason/code/scratch3/target/scala-2.10/classes -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/classes:/Users/jason/.sbt/0.13.0-RC2/boot/scala-2.10.2/lib/scala-library.jar /Users/jason/code/scratch3/test.scala
/code/scratch3 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/ scalac-hash v2.10.2 -classpath /Users/jason/code/scratch3/target/scala-2.10/classes -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/classes:/Users/jason/.sbt/0.13.0-RC2/boot/scala-2.10.2/lib/scala-library.jar /Users/jason/code/scratch3/test.scala
[info] v2.10.2 => /Users/jason/usr/scala-v2.10.2-0-g60d462e
/code/scratch3

I'll dig deeper.

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

Joel Galenson (jgalenson) said:
As one additional point, I also tried converting my original project (from which I extracted this test case) to use the Eclipse plugin via the sbteclipse tool. When I did that, compiling it with Eclipse gave the same error. I don't know how sbteclipse works, but a quick glance at the .project or .classpath files it created didn't reveal anything obviously wrong.

Note that I haven't tried this for the test case I attached here, so it could be something unrelated (although I doubt it).

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

@retronym said:
I can now see why this only crashes in SBT. SBT has a custom compiler phase to record the API fingerprint of each file.

pool-4-thread-1@4427, prio=5, in group 'main', status: 'RUNNING'
	  at scala.collection.MapLike$class.default(MapLike.scala:228)
	  at scala.collection.AbstractMap.default(Map.scala:59)
	  at scala.collection.MapLike$class.apply(MapLike.scala:141)
	  at scala.collection.AbstractMap.apply(Map.scala:59)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:771)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.processClassType$1(ClassfileParser.scala:708)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:728)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:816)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$parseAttribute$1(ClassfileParser.scala:837)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.parseAttributes(ClassfileParser.scala:1048)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:527)
	  at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:112)
	  at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:255)
	  at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:189)
	  at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.load(SymbolLoaders.scala:205)
	  at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1567)
	  at scala.reflect.internal.Types$NoArgsTypeRef.typeParams(Types.scala:2078)
	  at scala.reflect.internal.Types$NoArgsTypeRef.isHigherKinded(Types.scala:2077)
	  at scala.reflect.internal.Types$NoArgsTypeRef.normalizeImpl(Types.scala:2111)
	  at scala.reflect.internal.Types$TypeRef.normalize(Types.scala:2316)
	  at scala.reflect.internal.tpe.TypeMaps$ContainsCollector.traverse(TypeMaps.scala:959)
	  at scala.reflect.internal.tpe.TypeMaps$TypeTraverser.apply(TypeMaps.scala:301)
	  at scala.reflect.internal.tpe.TypeMaps$TypeMap.applyToSymbolInfo(TypeMaps.scala:219)
	  at scala.reflect.internal.tpe.TypeMaps$TypeMap.loop$1(TypeMaps.scala:228)
	  at scala.reflect.internal.tpe.TypeMaps$TypeMap.noChangeToSymbols(TypeMaps.scala:230)
	  at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:244)
	  at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:129)
	  at scala.reflect.internal.tpe.TypeMaps$ContainsCollector.traverse(TypeMaps.scala:962)
	  at scala.reflect.internal.tpe.TypeMaps$TypeCollector.collect(TypeMaps.scala:313)
	  at scala.reflect.internal.Types$Type.contains(Types.scala:779)
	  at scala.reflect.internal.Types$$anonfun$32.apply(Types.scala:3674)
	  at scala.reflect.internal.Types$$anonfun$32.apply(Types.scala:3674)
	  at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:259)
	  at scala.collection.immutable.List.foreach(List.scala:302)
	  at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:258)
	  at scala.collection.TraversableLike$class.filter(TraversableLike.scala:270)
	  at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
	  at scala.reflect.internal.Types$class.existentialAbstraction(Types.scala:3674)
	  at scala.reflect.internal.SymbolTable.existentialAbstraction(SymbolTable.scala:14)
	  at scala.reflect.internal.Types$Type.asSeenFrom(Types.scala:672)
	  at scala.reflect.internal.Types$Type.computeMemberType(Types.scala:706)
	  at scala.reflect.internal.Symbols$MethodSymbol.typeAsMemberOf(Symbols.scala:2749)
	  at scala.reflect.internal.Types$Type.memberType(Types.scala:697)
	  at scala.reflect.internal.Types$Type.scala$reflect$internal$Types$Type$$findMembersInternal$1(Types.scala:1025)
	  at scala.reflect.internal.Types$Type.findMembers(Types.scala:1047)
	  at scala.reflect.internal.Types$Type.membersBasedOnFlags(Types.scala:636)
	  at scala.reflect.internal.Types$Type.members(Types.scala:589)
	  at xsbt.API.xsbt$API$$mkStructure(API.scala:238)
	  at xsbt.API$$anonfun$structure$1.apply(API.scala:232)
	  at xsbt.API$$anonfun$structure$1.apply(API.scala:232)
	  at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:188)
	  at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:92)
	  at xsbt.API.structure(API.scala:232)
	  at xsbt.API.xsbt$API$$structure(API.scala:229)
	  at xsbt.API$$anonfun$xsbt$API$$mkClassLike$2.apply(API.scala:422)
	  at xsbt.API$$anonfun$xsbt$API$$mkClassLike$2.apply(API.scala:422)
	  at xsbt.Message$$anon$1.apply(Message.scala:8)
	  at xsbti.SafeLazy$$anonfun$apply$1.apply(SafeLazy.scala:8)
	  at xsbti.SafeLazy$Impl._t$lzycompute(SafeLazy.scala:20)
	  at xsbti.SafeLazy$Impl._t(SafeLazy.scala:18)
	  at xsbti.SafeLazy$Impl.get(SafeLazy.scala:24)
	  at xsbt.API$$anonfun$xsbt$API$$forceStructures$1.apply(API.scala:100)
	  at xsbt.API$$anonfun$xsbt$API$$forceStructures$1.apply(API.scala:100)
	  at scala.collection.immutable.List.foreach(List.scala:302)
	  at xsbt.API.xsbt$API$$forceStructures(API.scala:100)
	  at xsbt.API$ApiPhase.processScalaUnit(API.scala:48)
	  at xsbt.API$ApiPhase.processUnit(API.scala:38)
	  at xsbt.API$ApiPhase$$anonfun$run$1.apply(API.scala:34)
	  at xsbt.API$ApiPhase$$anonfun$run$1.apply(API.scala:34)
	  at scala.collection.Iterator$class.foreach(Iterator.scala:743)
	  at scala.collection.AbstractIterator.foreach(Iterator.scala:1174)
	  at xsbt.API$ApiPhase.run(API.scala:34)

At the stack trace above, it is enumerating the members of the type:

java.util.Vector[E]#Itr
        with java.util.ListIterator[E] {
  final private[package util] val this$0: java.util.Vector[_]
  private[package util] def <init>(x$2: Int): Vector.this.ListItr
  def hasPrevious(): Boolean
  def nextIndex(): Int
  def previousIndex(): Int
  def previous(): E
  def set(x$1: E): Unit
  def add(x$1: E): Unit
}
    private class Itr implements Iterator<E> {
        int cursor;       // index of next element to return
        int lastRet = -1; // index of last element returned; -1 if no such
        int expectedModCount = modCount;

        public boolean hasNext() {
            // Racy but within spec, since modifications are checked
            // within or after synchronization in next/previous
            return cursor != elementCount;
        }

        public E next() {
            synchronized (Vector.this) {
                checkForComodification();
                int i = cursor;
                if (i >= elementCount)
                    throw new NoSuchElementException();
                cursor = i + 1;
                return elementData(lastRet = i);
            }
        }

        public void remove() {
            if (lastRet == -1)
                throw new IllegalStateException();
            synchronized (Vector.this) {
                checkForComodification();
                Vector.this.remove(lastRet);
                expectedModCount = modCount;
            }
            cursor = lastRet;
            lastRet = -1;
        }

        final void checkForComodification() {
            if (modCount != expectedModCount)
                throw new ConcurrentModificationException();
        }
    }

Decompiled:

class java.util.Vector$Itr extends java.lang.Object implements java.util.Iterator{
    int cursor;
    int lastRet;
    int expectedModCount;
    final java.util.Vector this$0;
    public boolean hasNext();
    public java.lang.Object next();
    public void remove();
    final void checkForComodification();
    java.util.Vector$Itr(java.util.Vector, java.util.Vector$1);
}

javap -classpath /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar  'java.util.Vector$1'
Compiled from "Vector.java"
class java.util.Vector$1 extends java.lang.Object implements java.util.Enumeration{
    int count;
    final java.util.Vector this$0;
    java.util.Vector$1(java.util.Vector);
    public boolean hasMoreElements();
    public java.lang.Object nextElement();
}

For reasons unknown to me, Itr accepts Vector$1 as a constructor parameter.

That's considered to be part of the API by SBT. The type ref java.util.Vector$1 is normalized, which triggers its classfile to be read in order to see it has type parameters.

During classfile parsing, it encounters the signature: Ljava.lang.Object;Ljava.util.Enumeration<TE;>;

We expect a type parameter named 'E'. None is available.

Really strange. Is the bytecode for Vector* consistent?

java.util.Vector$Itr(java.util.Vector, java.util.Vector$1);
  Code:
   Stack=2, Locals=3, Args_size=3
   0:	aload_0
   1:	aload_1
   2:	invokespecial	#1; //Method "<init>":(Ljava/util/Vector;)V
   5:	return
  LineNumberTable:
   line 1120: 0


}

javap -classpath /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar -p 'java.util.Vector'
Compiled from "Vector.java"
public class java.util.Vector extends java.util.AbstractList implements java.util.List,java.util.RandomAccess,java.lang.Cloneable,java.io.Serializable{
    protected java.lang.Object[] elementData;
    protected int elementCount;
    protected int capacityIncrement;
    private static final long serialVersionUID;
    public java.util.Vector(int, int);
    public java.util.Vector(int);
    public java.util.Vector();
    public java.util.Vector(java.util.Collection);

What constructor is being called?

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

@retronym said:
Figured it out. Details in the commit message here: https://github.com/retronym/scala/compare/ticket/7455

That branch is against master. I think I'll target this for 2.10.3 as well as it seems low risk / high reward. Will submit a PR in a day or two.

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 18, 2013

Loading

@scabug
Copy link
Author

@scabug scabug commented Jul 28, 2013

Loading

@scabug scabug closed this Jul 28, 2013
@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

Samuel Halliday (fommil) said:
I realise that this has been fixed in recent releases, but I'm seeing this in 2.9.2 (and I note that this fix was released after 2.9.3).

The example ScalaList above fails to compile with Java 7 and scala 2.9.2 using the SBT 0.12.4 / zinc 0.2.5 compilers.

Is there a workaround that allows Scala classes to extend JList? I have tried to create an intermediate Java class to do the extensions, but I get the same problem.

We are unable to upgrade Scala due to third party dependencies on our binary releases.

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

@retronym said:
Can you compile with Java 6 and simply run with Java 7? Or do you need to use Java 7 APIs?

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

Samuel Halliday (fommil) said:
we need to compile with java 7

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

@retronym said:
This particular bug isn't directly connected to Swing, BTW.

From my pull-request comment:

This bug is often reported by Java 7 Swing users but is unrelated to scala-swing, raw types, or newly-generified Java standard library classes. It could pop up anytime. It is also usually only seen within SBT when its custom compiler phase captures API snapshots.

Given our limited resources, we typically don't backport bug fixes to maintainance releases unless they are deemed showstoppers, or if it needed by a customer with a Typesafe support contract. PIng me at jason.zaugg@typesafe.com if the latter is a possibility for you.

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

Samuel Halliday (fommil) said:
Hmm, maybe we need a patch fix to sbt then. Is there no way to trick SBT or the compiler into compiling this? Even with layers of java in between?

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

@retronym said:
The problem is when scalac reads the class file Vector.class. If a Scala class extends JList, even indirectly, SBT's custom compiler phase that extracts the API of all classes in your project will end up forcing the type of this constructor:

public JList(final Vector<?> listData) {

which triggers loading of Vector.class.

You might have more luck by wrapping, rather than inheriting from JList.

Loading

@scabug
Copy link
Author

@scabug scabug commented Apr 8, 2014

Samuel Halliday (fommil) said:
thanks, yeah I think that's the way to go

Loading

@scabug scabug added the critical label Apr 7, 2017
@scabug scabug added this to the 2.10.3-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants