play-swagger icon indicating copy to clipboard operation
play-swagger copied to clipboard

scala.ScalaReflectionException: class Boolean not found

Open oripwk opened this issue 7 years ago • 9 comments

When going through the tutorial with Play 2.6.5 and Scala 2.12.3, sbt run results in the following stack trace:

[error] (run-main-0) scala.ScalaReflectionException: class Boolean not found.
scala.ScalaReflectionException: class Boolean not found.
        at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:122)
        at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:22)
        at com.iheart.playSwagger.DefinitionGenerator.definition(DefinitionGenerator.scala:44)
        at com.iheart.playSwagger.DefinitionGenerator.allReferredDefs$1(DefinitionGenerator.scala:57)
        at com.iheart.playSwagger.DefinitionGenerator.$anonfun$allDefinitions$8(DefinitionGenerator.scala:71)
        at scala.collection.LinearSeqOptimized.foldLeft(LinearSeqOptimized.scala:122)
        at scala.collection.LinearSeqOptimized.foldLeft$(LinearSeqOptimized.scala:118)
        at scala.collection.immutable.List.foldLeft(List.scala:86)
        at com.iheart.playSwagger.DefinitionGenerator.allDefinitions(DefinitionGenerator.scala:70)
        at com.iheart.playSwagger.SwaggerSpecGenerator.generateWithBase(SwaggerSpecGenerator.scala:137)
        at com.iheart.playSwagger.SwaggerSpecGenerator.generateFromRoutes(SwaggerSpecGenerator.scala:119)
        at com.iheart.playSwagger.SwaggerSpecGenerator.$anonfun$generateFromRoutesFile$16(SwaggerSpecGenerator.scala:99)
        at scala.util.Success.flatMap(Try.scala:247)
        at com.iheart.playSwagger.SwaggerSpecGenerator.generateFromRoutesFile(SwaggerSpecGenerator.scala:98)
        at com.iheart.playSwagger.SwaggerSpecGenerator.generate(SwaggerSpecGenerator.scala:43)
        at com.iheart.playSwagger.SwaggerSpecRunner$.swaggerJson(SwaggerSpecRunner.scala:23)
        at com.iheart.playSwagger.SwaggerSpecRunner$.delayedEndpoint$com$iheart$playSwagger$SwaggerSpecRunner$1(SwaggerSpecRunner.scala:26)
        at com.iheart.playSwagger.SwaggerSpecRunner$delayedInit$body.apply(SwaggerSpecRunner.scala:7)
        at scala.Function0.apply$mcV$sp(Function0.scala:34)
        at scala.Function0.apply$mcV$sp$(Function0.scala:34)
        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
        at scala.App.$anonfun$main$1$adapted(App.scala:76)
        at scala.collection.immutable.List.foreach(List.scala:389)
        at scala.App.main(App.scala:76)
        at scala.App.main$(App.scala:74)
        at com.iheart.playSwagger.SwaggerSpecRunner$.main(SwaggerSpecRunner.scala:7)
        at com.iheart.playSwagger.SwaggerSpecRunner.main(SwaggerSpecRunner.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sbt.Run.invokeMain(Run.scala:67)
        at sbt.Run.run0(Run.scala:61)
        at sbt.Run.sbt$Run$$execute$1(Run.scala:51)
        at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:55)
        at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
        at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
        at sbt.Logger$$anon$4.apply(Logger.scala:84)
        at sbt.TrapExit$App.run(TrapExit.scala:248)
        at java.lang.Thread.run(Thread.java:748)
java.lang.RuntimeException: Nonzero exit code: 1
        at scala.sys.package$.error(package.scala:27)
        at sbt.BuildCommon$$anonfun$toError$1.apply(Defaults.scala:2201)
        at sbt.BuildCommon$$anonfun$toError$1.apply(Defaults.scala:2201)
        at scala.Option.foreach(Option.scala:236)
        at sbt.BuildCommon$class.toError(Defaults.scala:2201)
        at sbt.package$.toError(package.scala:4)
        at com.iheart.sbtPlaySwagger.SwaggerPlugin$$anonfun$projectSettings$9.apply(SwaggerPlugin.scala:41)
        at com.iheart.sbtPlaySwagger.SwaggerPlugin$$anonfun$projectSettings$9.apply(SwaggerPlugin.scala:34)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)
[error] (*:swagger) Nonzero exit code: 1
[error] Total time: 25 s, completed Sep 21, 2017 7:02:05 PM

After some investigation, it seems that it's caused by a query parameter in the routes file, which is of type Boolean:

PUT     /api/v1/config/bypass     org.oripwk.controller.ConfigController.bypass(bypass: Boolean)

When I remove this specific endpoint and run sbt run it then yells about class String not found about a similar endpoint, but with String instead of Boolean.

oripwk avatar Sep 21 '17 16:09 oripwk

Its likely that you don't have this line in you build.sbt swaggerDomainNameSpaces := Seq("models") We should change it so that without this settings, play swagger shouldn't try to reflect on any class to get definitions.

kailuowang avatar Sep 23 '17 03:09 kailuowang

Yes, it was the problem indeed. Thanks.

oripwk avatar Sep 25 '17 18:09 oripwk

@oripwk glad that solves the problem, but there is still a bug here. The error you get is rather confusing. We should address this in the library.

kailuowang avatar Sep 25 '17 18:09 kailuowang

I have the same problem but with String not found (like here: #168)

in build.sbt there is swaggerDomainNameSpaces := Seq("models") but still get the error

[error] (run-main-0) scala.ScalaReflectionException: class String not found.

I'm using play 2.6.5 with scala 2.12 and the version of the plugin is 0.6.2-PLAY2.6

schub avatar Oct 02 '17 18:10 schub

Any news here? I'm using the plugin for some time and never had problems. This issue popped up after upgrading my app to playframework 2.6. Is there anything I can provide in order to make it easier to find the error here? Please help!

schub avatar Oct 11 '17 13:10 schub

sorry for the late response. I suspect it's still something wrong with the build.sbt. Maybe you have another swaggerDomainNameSpaces overriding it?

kailuowang avatar Oct 11 '17 13:10 kailuowang

swaggerDomainNameSpaces is only defined once. But I found the error and it might be helpful for others. I have a multi-module-project where the play app is one module. I had the swaggerDomainNameSpaces defined in the root build.sbt. I added it to the modules build.sbt and now everything works like expected. So, was my fault... Thanks anyway for your help :)

BTW: awesome plugin

schub avatar Oct 11 '17 13:10 schub

ah, good info, yeah the settings on the root module don't apply to its depending modules. Thanks for the update.

kailuowang avatar Oct 11 '17 14:10 kailuowang

I'm facing this issue. This is the setup

  • module-library (no custom plugin). Prefix api.models
  • module-with-play (PlayScala and SwaggerPlugin). Prefix models
  • module-with-play depends on module-library

When I add api.models to the swaggerDomainNameSpaces if fails with ScalaReflectionException as a class in the module-library project can not be found. The class is actually a type for an Enumeration like

object SomeEnum {
  type SomeEnum = Value
  ...
}

alejandrod-f avatar Aug 15 '21 19:08 alejandrod-f