jdk8?

3,279 views
Skip to first unread message

Curtis Stanford

unread,
Feb 10, 2013, 5:04:51 PM2/10/13
to scala...@googlegroups.com
I've been using Scala 2.10 with jdk8 EA quite successfully for a bit now but ran into a weird message trying to use the new LocalDateTime class from the java.time package:

scala: error while loading LocalDateTime, class file '/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar(java/time/LocalDateTime.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 223)

Any insights?

Curtis

Simon Ochsenreither

unread,
Feb 10, 2013, 6:19:07 PM2/10/13
to scala...@googlegroups.com
Didn't find anything suspicious when looking at the bytecode, but section is certainly Java 8-specific:

  InnerClasses:
       public static final #669= #668 of #674; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  BootstrapMethods:
    0: #428 invokestatic java/lang/invoke/LambdaMetafactory.metaFactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
      Method arguments:
        #429 invokeinterface java/time/temporal/TemporalQuery.queryFrom:(Ljava/time/temporal/TemporalAccessor;)Ljava/lang/Object;
        #430 invokestatic java/time/LocalDateTime.from:(Ljava/time/temporal/TemporalAccessor;)Ljava/time/LocalDateTime;
        #431 (Ljava/time/temporal/TemporalAccessor;)Ljava/time/LocalDateTime;


These are attributes, so theoretically those alone don't prevent execution on older versions, but if javac included this stuff in the class-file it quite certain that there is a usage of it in the code (which will be unknown to code working with older bytecode).
I guess that the Scala compiler needs to be updated to deal with the new features Oracle added to the Java bytecode.

Simon Ochsenreither

unread,
Feb 10, 2013, 6:30:30 PM2/10/13
to scala...@googlegroups.com
I think this code is the issue:

public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
    Objects.requireNonNull(formatter, "formatter");
    return formatter.parse(text, LocalDateTime::from);  // See the ::?
}

Jason Zaugg

unread,
Feb 10, 2013, 6:35:27 PM2/10/13
to Simon Ochsenreither, scala-user
scala/tools/nsc/symtab/classfile/ClassfileParser.scala will need to be updated to parse (well, just skip over) the new BootstrapMethod attribute [1]. What this added in JDK7 already? Perhaps it is only now being used in the standard library now that Java 8 exposes it at the language level.

I'm not sure if we have a ticket open for this already. Simon: could you lodge a ticket if you can't find a duplicate?

For now, we recommend that you compile against Java 6. You can run still the resulting code on Java 7/8. 

-jason

Curtis Stanford

unread,
Feb 10, 2013, 10:15:01 PM2/10/13
to scala...@googlegroups.com, Simon Ochsenreither
I'm trying to use the new JavaFX 8 that is part of jdk 8. Can I compile against 7 but use code compiled with 8? Doesn't seem likely...

Curtis Stanford

unread,
Feb 11, 2013, 11:44:54 AM2/11/13
to scala...@googlegroups.com, Simon Ochsenreither
For now, we recommend that you compile against Java 6. You can run still the resulting code on Java 7/8. 

-jason


Thanks Jason. I do think Scala needs to work against jdk8 sooner than later. The feature complete developer preview is imminent. 

Curtis Stanford

unread,
May 30, 2013, 1:29:26 PM5/30/13
to scala...@googlegroups.com
Each iteration of the jdk8 preview gets worse. It's to the point now that I may have to dump Scala for another language. With jdk8 build 91, the CharSequence and Arrays classes can't be loaded by the Scala compiler making it very difficult to compile anything at all. 

Compiling against java 6/7 is not an option as I need to use javafx 8 which is only available in jdk 8.

Simon Ochsenreither

unread,
May 30, 2013, 1:36:23 PM5/30/13
to scala...@googlegroups.com

Each iteration of the jdk8 preview gets worse.

Sure, Oracle is adding tons of default methods/lambda stuff to the library.
 
It's to the point now that I may have to dump Scala for another language.

I don't think you will find any language at this point which has implemented support for Java 8's features ahead of Java 8.

Did you try the 2.11 builds yet? Afaik they have already support for default methods, not sure about the lambda stuff.

Curtis Stanford

unread,
May 30, 2013, 1:58:26 PM5/30/13
to scala...@googlegroups.com
I haven't tried 2.11 yet. BTW, Kotlin works with jdk8

Russel Winder

unread,
May 30, 2013, 2:26:13 PM5/30/13
to Simon Ochsenreither, scala...@googlegroups.com
On Thu, 2013-05-30 at 10:36 -0700, Simon Ochsenreither wrote:
>
> > Each iteration of the jdk8 preview gets worse.
>
>
> Sure, Oracle is adding tons of default methods/lambda stuff to the library.

This is not the problem. The lambda expression based library is being
developed separately from the Oracle Java 8 builds. Using the official
Oracle Java 8 b91, trying to run sbt, I get:

error: error while loading CharSequence, class file '/home/users/russel/lib.Linux.x86_64/jdk1.8.0_b91_2013-05-23/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken
(bad constant pool tag 18 at byte 10)

Scala is claiming that there is a breakage in the class file of this
class.

> > It's to the point now that I may have to dump Scala for another language.

I am having to keep Java 7 around just to run Scala :-(

> I don't think you will find any language at this point which has
> implemented support for Java 8's features ahead of Java 8.

Java, Groovy, Kotlin, all fine with Java 8 b91. And they are fine using
the Lambda build b92.

> Did you try the 2.11 builds yet? Afaik they have already support for
> default methods, not sure about the lambda stuff.

I'll give it a go over the weekend…

--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc

Curtis Stanford

unread,
May 30, 2013, 3:38:33 PM5/30/13
to scala...@googlegroups.com, Simon Ochsenreither


On Thursday, May 30, 2013 12:26:13 PM UTC-6, Russel wrote:
This is not the problem. The lambda expression based library is being
developed separately from the Oracle Java 8 builds. Using the official
Oracle Java 8 b91, trying to run sbt, I get:

 
Agreed. Every message I get is about 'bad constant pool tag 18'. Tag 18 is the invokeDynamic tag which seems to have nothing to do with lambdas. Doesn't jdk 7 also have the invokeDynamic instruction? As far as I know, jdk 8 does not introduce any new VM instructions. Lambdas are implemented as a call to a SAM. 

I think this really needs to be fixed.

Curtis

Curtis Stanford

unread,
May 30, 2013, 3:49:08 PM5/30/13
to scala...@googlegroups.com, Simon Ochsenreither
Sweet. Looks like 2.10.2-RC1 fixes the problem (or at least patches it). There was a pull request to deal with the invokeDynamic tag in class file version 51 that works also for version 52 (jdk8). My project compiles again!

Jason Zaugg

unread,
May 30, 2013, 3:49:21 PM5/30/13
to Curtis Stanford, scala-user, Simon Ochsenreither
Support for reading Java classfiles containing invokedynamic instructions [1] is coming in the imminent Scala 2.10.2. It would be really helpful to us if you would try out 2.10.2-RC1 to confirm that it works for you.

-jason

Thomas Wolff

unread,
May 31, 2013, 7:36:46 AM5/31/13
to scala...@googlegroups.com, Curtis Stanford, Simon Ochsenreither


I think this really needs to be fixed.
Absolutely. I'm having the same problem, in a Windows environment.
[error] error while loading CharSequence, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/lang/CharSequence.class)' is broken
[error] (bad constant pool tag 18 at byte 10)


Support for reading Java classfiles containing invokedynamic instructions [1] is coming in the imminent Scala 2.10.2. It would be really helpful to us if you would try out 2.10.2-RC1 to confirm that it works for you.
No, neither 2.10.2 nor 2.11 helps here.
 

Jason Zaugg

unread,
May 31, 2013, 7:49:07 AM5/31/13
to Thomas Wolff, scala-user, Curtis Stanford, Simon Ochsenreither
Hi Thomas, 

Can you please provide a transcript that demonstrates the problem, and confirms which Scala version you are compiling with.

I can't see a way that 2.10.2-RC1 can issue that error message, which is issued at the end of this match [1], which now handles CONSTANT_INVOKEDYNAMIC (tag 18).

Thanks,

-jason

Russel Winder

unread,
May 31, 2013, 1:10:11 PM5/31/13
to Jason Zaugg, scala-user
On Thu, 2013-05-30 at 21:49 +0200, Jason Zaugg wrote:

> Support for reading Java classfiles containing invokedynamic instructions
> [1] is coming in the imminent Scala 2.10.2. It would be really helpful to
> us if you would try out 2.10.2-RC1 to confirm that it works for you.

No change to the SBT file seems to get rid of the problem. This probably
indicates a failing on my part…
signature.asc

Frank Fischer

unread,
Jul 27, 2013, 4:45:07 AM7/27/13
to scala...@googlegroups.com, Jason Zaugg
The following configuration works for me. A very recent
version of sbt is needed (v 0.13.0-M1 did not work).
And: this version has to be first (and only?) one that is started
(invoking an older version seems to lead to an error before build.properties takes effect).


sbt --version
sbt launcher version 0.13.0-RC3

scalac -version:
Scala compiler version 2.11.0-M4 -- Copyright 2002-2013, LAMP/EPFL

java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b97)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b39, mixed mode)




./build.sbt:
...
scalaVersion := "2.10.2"  
 ... 
org.scalastyle.sbt.ScalastylePlugin.Settings
...
libraryDependencies ++= Seq(
  "ch.qos.logback"                 %  "logback-classic"              % "1.0.13",
  "org.scalacheck"                 %  "scalacheck_2.10"              % "1.10.1",
  "org.scalatest"                  %  "scalatest_2.10.0"             % "2.0.M5"  % "test"
)



./project/build.properties:
sbt.version=0.13.0-RC3                                                                                                                                               


./project/plugins.sbt:
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
                                                                                                                                                                      
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.0-SNAPSHOT")             
                                                                                                                                                                      
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.1" from "https://oss.sonatype.org/content/repositories/releases/org/scalastyle/scalastyle-sbt-plugin_2.10_0.13.0-M1/0.3.1/scalastyle-sbt-plugin-0.3.1.jar")                

Frank


Am Freitag, 31. Mai 2013 19:10:11 UTC+2 schrieb Russel:
On Thu, 2013-05-30 at 21:49 +0200, Jason Zaugg wrote:

> Support for reading Java classfiles containing invokedynamic instructions
> [1] is coming in the imminent Scala 2.10.2. It would be really helpful to
> us if you would try out 2.10.2-RC1 to confirm that it works for you.

No change to the SBT file seems to get rid of the problem. This probably
indicates a failing on my part…

--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russ...@ekiga.net

Andreas V

unread,
Jul 29, 2013, 4:00:09 PM7/29/13
to scala...@googlegroups.com
Just wanted to note that I got this also right now trying to do a basic tutorial with Play (java) on Ubuntu 13.04 64 bit machine with oracle java 8 installed.

Andreas

unread,
Jul 29, 2013, 4:03:12 PM7/29/13
to scala...@googlegroups.com
Forgot to mention it was when doing "play eclipse" for a new play project.
Reply all
Reply to author
Forward
0 new messages