Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt 1.3.0 will break the plugin #80

Open
eed3si9n opened this issue Aug 19, 2019 · 0 comments
Open

sbt 1.3.0 will break the plugin #80

eed3si9n opened this issue Aug 19, 2019 · 0 comments

Comments

@eed3si9n
Copy link

[info] [error] java.lang.IllegalArgumentException: argument type mismatch
[info] [error]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info] [error]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info] [error]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info] [error]  at java.lang.reflect.Method.invoke(Method.java:498)
[info] [error]  at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror3.jinvokeraw(JavaMirrors.scala:408)
[info] [error]  at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.jinvoke(JavaMirrors.scala:354)
[info] [error]  at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror.apply(JavaMirrors.scala:370)
[info] [error]  at com.lucidchart.sbt.scalafmt.CachePlatform$.fileInfo(Platform.scala:24)
[info] [error]  at com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin$autoImport$.$anonfun$scalafmtCoreSettings$12(ScalafmtCorePlugin.scala:113)
[info] [error]  at scala.collection.immutable.Map$EmptyMap$.getOrElse(Map.scala:104)
[info] [error]  at com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin$autoImport$.$anonfun$scalafmtCoreSettings$11(ScalafmtCorePlugin.scala:113)
[info] [error]  at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
[info] [error]  at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
[info] [error]  at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
[info] [error]  at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
[info] [error]  at scala.collection.TraversableLike.map(TraversableLike.scala:237)
[info] [error]  at scala.collection.TraversableLike.map$(TraversableLike.scala:230)
[info] [error]  at scala.collection.AbstractTraversable.map(Traversable.scala:108)
[info] [error]  at com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin$autoImport$.$anonfun$scalafmtCoreSettings$4(ScalafmtCorePlugin.scala:111)
[info] [error]  at com.lucidchart.sbt.scalafmt.ScalafmtCorePlugin$autoImport$.$anonfun$scalafmtCoreSettings$4$adapted(ScalafmtCorePlugin.scala:88)
[info] [error]  at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[info] [error]  at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[info] [error]  at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[info] [error]  at sbt.Execute.$anonfun$submit$2(Execute.scala:280)
[info] [error]  at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[info] [error]  at sbt.Execute.work(Execute.scala:289)
[info] [error]  at sbt.Execute.$anonfun$submit$1(Execute.scala:280)
[info] [error]  at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[info] [error]  at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[info] [error]  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[info] [error]  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[info] [error]  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[info] [error]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[info] [error]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[info] [error]  at java.lang.Thread.run(Thread.java:748)
[info] [error] (Compile / scalafmt / scalafmt) java.lang.IllegalArgumentException: argument type mismatch

notes

In sbt 1.2.8, sbt.util.FileHashModified is private

private final case class FileHashModified(file: File, hash: List[Byte], lastModified: Long)
    extends HashModifiedFileInfo

There's a code in the plugin to break the privacy by using reflection:

https://github.com/lucidsoftware/neo-sbt-scalafmt/blob/e8aaaed6bc2dfb284bdb667e452f2520151eef26/sbt-scalafmt/src/main/scala-2.12/com/lucidchart/sbt/scalafmt/Platform.scala

  private[this] val fileHashModified = {
    val module = mirror.reflectModule(mirror.staticModule("sbt.util.FileHashModified"))
    mirror.reflect(module.instance).reflectMethod(module.symbol.info.decl(universe.TermName("apply")).asMethod)
  }

  def fileInfo(file: File, hash: List[Byte], lastModified: Long) =
    fileHashModified(file, hash, lastModified.asInstanceOf[AnyRef]).asInstanceOf[HashModifiedFileInfo]

In sbt 1.3.0, we are taking advantage of the privacy to change the class implementation as follows:

https://github.com/sbt/util/blob/v1.3.0-M9/util-cache/src/main/scala/sbt/util/FileInfo.scala#L40-L41

private final case class FileHashModified(file: File, hashArray: Array[Byte], lastModified: Long)
    extends HashModifiedFileInfo
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Aug 19, 2019
The test fails because the plugin is using reflection to access a private class, and we changed it - lucidsoftware/neo-sbt-scalafmt#80
eed3si9n referenced this issue in scala/community-build Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant