julianpeeters / sbt-avrohugger

sbt plugin for generating Scala sources for Apache Avro schemas and protocols.
Apache License 2.0
133 stars 50 forks source link

Regression RC20+ null pointer when generating from avsc #79

Closed Reeebuuk closed 4 years ago

Reeebuuk commented 4 years ago

This avsc file can normally be compiled with RC9 but from RC20 onwards I'm getting null pointer.

{
  "type" : "record",
  "name" : "UnderlyingToProductLinkRemovedAvro",
  "namespace" : "com.ingenuiq.note.underlyings.info.events",
  "fields" : [ {
    "name" : "underlyingId",
    "type" : {
      "type" : "record",
      "name" : "UnderlyingIdAvro",
      "namespace" : "com.ingenuiq.common",
      "fields" : [ {
        "name" : "id",
        "type" : "string"
      } ]
    }
  }, {
    "name" : "productId",
    "type" : {
      "type" : "record",
      "name" : "ProductIdAvro",
      "namespace" : "com.ingenuiq.common",
      "fields" : [ {
        "name" : "id",
        "type" : "string"
      } ]
    }
  }, {
    "name" : "metadata",
    "type" : {
      "type" : "record",
      "name" : "PersistentEventMetadataAvro",
      "namespace" : "com.ingenuiq.common",
      "fields" : [ {
        "name" : "correlationId",
        "type" : "string"
      }, {
        "name" : "created",
        "type" : "long"
      } ]
    }
  } ]
}

Exception is

[info] Compiling AVSC /Users/reee/IdeaProjects/product-api/src/main/resources/avro/avsc/UnderlyingToProductLinkRemovedAvro.avsc to /Users/reee/IdeaProjects/product-api/target/scala-2.13/src_managed/main/compiled_avro
[error] java.lang.NullPointerException
[error]         at org.apache.avro.util.internal.Accessor.defaultValue(Accessor.java:105)
[error]         at avrohugger.matchers.DefaultValueMatcher$.getDefaultValue(DefaultValueMatcher.scala:114)
[error]         at avrohugger.format.specific.trees.SpecificCaseClassTree$.$anonfun$toCaseClassDef$1(SpecificCaseClassTree.scala:41)
[error]         at scala.collection.immutable.List.map(List.scala:286)
[error]         at avrohugger.format.specific.trees.SpecificCaseClassTree$.toCaseClassDef(SpecificCaseClassTree.scala:34)
[error]         at avrohugger.format.specific.avrohuggers.SpecificSchemahugger$.toTrees(SpecificSchemahugger.scala:34)
[error]         at avrohugger.format.specific.SpecificScalaTreehugger$.asScalaCodeString(SpecificScalaTreehugger.scala:51)
[error]         at avrohugger.format.abstractions.SourceFormat.getScalaCompilationUnit(SourceFormat.scala:168)
[error]         at avrohugger.format.abstractions.SourceFormat.getScalaCompilationUnit$(SourceFormat.scala:152)
[error]         at avrohugger.format.SpecificRecord$.getScalaCompilationUnit(SpecificRecord.scala:21)
[error]         at avrohugger.format.SpecificRecord$.asCompilationUnits(SpecificRecord.scala:102)
[error]         at avrohugger.format.SpecificRecord$.compile(SpecificRecord.scala:202)
[error]         at avrohugger.generators.FileGenerator$.$anonfun$schemaToFile$1(FileGenerator.scala:35)
[error]         at avrohugger.generators.FileGenerator$.$anonfun$schemaToFile$1$adapted(FileGenerator.scala:32)
[error]         at scala.collection.immutable.List.foreach(List.scala:392)
[error]         at avrohugger.generators.FileGenerator$.schemaToFile(FileGenerator.scala:32)
[error]         at avrohugger.generators.FileGenerator$.$anonfun$fileToFile$1(FileGenerator.scala:87)
[error]         at avrohugger.generators.FileGenerator$.$anonfun$fileToFile$1$adapted(FileGenerator.scala:85)
[error]         at scala.collection.immutable.List.foreach(List.scala:392)
[error]         at avrohugger.generators.FileGenerator$.fileToFile(FileGenerator.scala:85)
[error]         at avrohugger.Generator.fileToFile(Generator.scala:76)
[error]         at sbtavrohugger.FileWriter$.$anonfun$generateCaseClasses$4(FileWriter.scala:26)
[error]         at sbtavrohugger.FileWriter$.$anonfun$generateCaseClasses$4$adapted(FileWriter.scala:24)
[error]         at scala.collection.LinearSeqOptimized.foreach(LinearSeqOptimized.scala:75)
[error]         at scala.collection.LinearSeqOptimized.foreach$(LinearSeqOptimized.scala:72)
[error]         at scala.collection.mutable.MutableList.foreach(MutableList.scala:33)
[error]         at sbtavrohugger.FileWriter$.generateCaseClasses(FileWriter.scala:24)
[error]         at sbtavrohugger.SbtAvrohugger$.$anonfun$specificAvroSettings$8(SbtAvrohugger.scala:168)
[error]         at sbt.util.FileFunction$.$anonfun$cached$1(FileFunction.scala:73)
[error]         at sbt.util.FileFunction$.$anonfun$cached$4(FileFunction.scala:146)
[error]         at sbt.util.Difference.apply(Tracked.scala:323)
[error]         at sbt.util.Difference.apply(Tracked.scala:303)
[error]         at sbt.util.FileFunction$.$anonfun$cached$3(FileFunction.scala:142)
[error]         at sbt.util.Difference.apply(Tracked.scala:323)
[error]         at sbt.util.Difference.apply(Tracked.scala:298)
[error]         at sbt.util.FileFunction$.$anonfun$cached$2(FileFunction.scala:141)
[error]         at sbtavrohugger.SbtAvrohugger$.$anonfun$specificAvroSettings$7(SbtAvrohugger.scala:170)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[error]         at sbt.Execute.work(Execute.scala:290)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]         at java.base/java.lang.Thread.run(Thread.java:830)
[error] (Compile / avroScalaGenerateSpecific) java.lang.NullPointerException

settings:

 avroScalaSpecificCustomTypes in Compile := {
      avrohugger.format.SpecificRecord.defaultTypes.copy(
        protocol = ScalaADT,
        array    = ScalaList,
        timestampMillis = JavaTimeInstant
      )
    }

would really like the decimal setting :)

Reeebuuk commented 4 years ago

My bad, had avro-tools set to 1.8.2 in plugins which caused this issue.