92

I'm adding the Joda Time repository to SBT with

libraryDependencies ++= Seq(
  "joda-time"         % "joda-time"           % "2.1"
)

Then I merrily use it like this:

 val ymd = org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd")
  ymd.parseDateTime("20121212")

But, when I compile the project in SBT, I get a nasty:

[warn] Class org.joda.convert.FromString not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in /home/jack/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.1.jar(org/joda/time/DateTime.class)
[error] error while loading DateTime, class file '/home/jack/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.1.jar(org/joda/time/DateTime.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool tag 10 at byte 42)

I tried the 2.0 version of joda-time, but get the same error.

Jack
  • 16,506
  • 19
  • 100
  • 167

2 Answers2

177

Add this dependency:

"org.joda" % "joda-convert" % "1.8.1"

It's an optional dependency of joda-time. I had to add it in my own project for the scala compiler to accept working with the joda-time jar.

Your issue seems to be the same.

Version is as at time of editing, latest versions can be found here

dr jerry
  • 9,768
  • 24
  • 79
  • 122
David Pierre
  • 9,459
  • 4
  • 40
  • 32
  • 61
    For the future, the reason it isn't optional for Scala is that Java compiler can load a class with missing annotations, and Scala doesn't. I've had same issue, e.g., with Guava and JSR-305. – Alexey Romanov Dec 13 '12 at 12:01
  • worked for me 12 Feb 2013, `"joda-time" % "joda-time" % "2.1"` and `"org.joda" % "joda-convert" % "1.2"` – Dustin Getz Feb 12 '13 at 22:51
  • 9
    it's unacceptable that a library doesn't work because someone thought it would be pragmatic to keep certain libraries separate. Especially java's defacto time library. – Hassan Syed Nov 21 '13 at 01:24
  • I am not sure 100%, but this dependency affects jodatime behavior. I have one project with dozen dependecies, but without `joda-convert` so toString for Datetime is `yyyy-mm-ddThh-mm-ss`. I have created simple project with `jodatime` and `joda-convert` dependeices, so in it I have `yyyy-mm-ddThh-mm-ss.000Z`. – Cherry Jun 26 '15 at 11:18
  • @AlexeyRomanov Can you elaborate more what "Java compiler can load a class with missing annotations" means? – user2829759 Oct 12 '16 at 05:11
  • 5
    @user2829759 Let's say you have a dependency `a.jar` which contains a `@B class A`, where annotation `@B` comes from `b.jar`. In Java, you can use `A` in your code if you have `a.jar` without `b.jar` on the build path; in Scala, you can't. – Alexey Romanov Oct 12 '16 at 15:15
1

I was running into a similar issue:

[warn] Class net.jcip.annotations.NotThreadSafe not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in ~/.ivy2-p2/cache/org.opensaml/xmltooling/jars/xmltooling-1.3.4.jar(org/opensaml/xml/util/IDIndex.class)
[error] error while loading AttributeMap, class file '~/.ivy2-p2/cache/org.opensaml/xmltooling/jars/xmltooling-1.3.4.jar(org/opensaml/xml/util/AttributeMap.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool index: 0 at pos: 12058)

Explicitly adding a dependency jcip-annotations-1.0.jar resolved the issue.

Qben
  • 2,617
  • 2
  • 24
  • 36
mn2013
  • 11
  • 1