0

Reference: a test case from the official documentation. Currently, I use 3.5 json4s

object JsonLoader {
 def parseJsonConfig[T: Manifest](filename: String): T = {
  implicit lazy val formats: DefaultFormats = new DefaultFormats {
     override val strictOptionParsing: Boolean = true
    }

  val inputStream = getClass.getResourceAsStream(filename)
  val lines = try {
   Source.fromInputStream(new BufferedInputStream(inputStream)).getLines.mkString
  } catch {
   case _: Exception => throw new Exception("config file not found")
  }
  parse(lines, useBigDecimalForDouble = false).extract[T]
 }
}

Exception in thread "main" java.lang.AbstractMethodError
 at org.json4s.DefaultFormats$class.$init$(Formats.scala:329)
 at jp.co.yahoo.k2.i2i.optimizer.util.JsonLoader$$anon$1.<init>(JsonLoader.scala:16)
 at jp.co.yahoo.k2.i2i.optimizer.util.JsonLoader$.parseJsonConfig(JsonLoader.scala:16)

Some people encountered the same problem, but they were referencing previous versions. Any thoughts and advice are appreciated.

Daniel Chepenko
  • 2,229
  • 7
  • 30
  • 56
  • BEWARE: Json4s is [vulnerable under DoS/DoW attacks](https://github.com/json4s/json4s/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+denial)! – Andriy Plokhotnyuk Jun 02 '20 at 07:29

1 Answers1

0

From java docs.

Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

Which means that code was compiled with one version of library json4s, which changed with breaking compatibility compared to your current runtime version of the library. The breaking point is a change in org.json4s.DefaultFormats.

This usually happens when there are multiple dependencies including transient dependencies (dependency of a dependency) with different requirements on version. In this cases, build tools pick the highest version.

The best approach to debug this is to generate a dependency tree (this depends on the build tool you're using), and check the evictions of json4s library.

Ivan Stanislavciuc
  • 7,140
  • 15
  • 18