You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
scala: error while loading Vector$1, class file ... is broken #7455
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.
@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.
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.
@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.
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] ?
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>
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).
@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:
privateclassItr 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/previousreturn cursor != elementCount;
}
public E next() {
synchronized (Vector.this) {
checkForComodification();
int i = cursor;
if (i >= elementCount)
thrownewNoSuchElementException();
cursor = i +1;
return elementData(lastRet = i);
}
}
public void remove() {
if (lastRet ==-1)
thrownewIllegalStateException();
synchronized (Vector.this) {
checkForComodification();
Vector.this.remove(lastRet);
expectedModCount = modCount;
}
cursor = lastRet;
lastRet =-1;
}
final void checkForComodification() {
if (modCount != expectedModCount)
thrownewConcurrentModificationException();
}
}
Decompiled:
classjava.util.Vector$Itrextends java.lang.Object implements java.util.Iterator{
int cursor;
int lastRet;
int expectedModCount;
final java.util.Vectorthis$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"classjava.util.Vector$1extends java.lang.Object implements java.util.Enumeration{
int count;
final java.util.Vectorthis$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=30: aload_0
1: aload_1
2: invokespecial #1; //Method "<init>":(Ljava/util/Vector;)V5:returnLineNumberTable:
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 classjava.util.Vectorextends 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);
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.
@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.
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?
@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(finalVector<?> listData) {
which triggers loading of Vector.class.
You might have more luck by wrapping, rather than inheriting from JList.
Activity
scabug commentedon 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:
scabug commentedon May 4, 2013
@retronym said:
To help us to troubleshoot, could you could please add
-Ydebugto 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?
scabug commentedon 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.
scabug commentedon 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.
scabug commentedon 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.)
scabug commentedon 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.
scabug commentedon 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.
scabug commentedon May 15, 2013
@retronym said:
I still can't figure out how to reproduce this.
scabug commentedon May 15, 2013
@paulp said:
Me neither, but I notice:
And here's Mr. E:
What is this all about? Why won't it infer (or even allow) Vector[String] ?
This has a weirdly familiar feel. You get one bite at the apple, then it's over.
scabug commentedon May 15, 2013
@retronym said:
I can't repro:
scabug commentedon May 15, 2013
@paulp said:
Interesting, it's 100% reliable for me with both java6 and java7. I wonder the difference.
scabug commentedon May 15, 2013
@paulp said:
Oh, it's trunk vs. 2.10.1.
scabug commentedon May 15, 2013
@paulp said:
That's an undesirable development because it probably means it's my doing.
scabug commentedon May 15, 2013
@paulp said:
Yep. Regressed in 9e101a3de8 .
scabug commentedon 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).
4 remaining items
scabug commentedon 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.
At the stack trace above, it is enumerating the members of the type:
Decompiled:
For reasons unknown to me,
ItracceptsVector$1as a constructor parameter.That's considered to be part of the API by SBT. The type ref
java.util.Vector$1is 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?
What constructor is being called?
scabug commentedon 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.
scabug commentedon Jul 18, 2013
@retronym said:
scala/scala#2750
scabug commentedon Jul 28, 2013
@gkossakowski said:
Fixed by scala/scala#2750
scabug commentedon 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.
scabug commentedon 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?
scabug commentedon Apr 8, 2014
Samuel Halliday (fommil) said:
we need to compile with java 7
scabug commentedon Apr 8, 2014
@retronym said:
This particular bug isn't directly connected to Swing, BTW.
From my pull-request comment:
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.
scabug commentedon 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?
scabug commentedon Apr 8, 2014
@retronym said:
The problem is when scalac reads the class file
Vector.class. If a Scala class extendsJList, 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:which triggers loading of
Vector.class.You might have more luck by wrapping, rather than inheriting from JList.
scabug commentedon Apr 8, 2014
Samuel Halliday (fommil) said:
thanks, yeah I think that's the way to go