0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ゼロ幅スペースを含むGroovyコードによるMissingMethodException

Last updated at Posted at 2019-11-17

現象

Hello.groovy
println("Hello World!")

こういう風に見えるプログラムを実行すると

groovy.lang.MissingMethodException: No signature of method: Hello.println​() is applicable for argument types: (java.lang.String) values: [Hello World!]
Possible solutions: println(), println(), println(java.lang.Object), println(java.lang.Object), println(java.io.PrintWriter), print(java.lang.Object)

などと言われてしまいました。

原因

どうもどっかのドキュメントからメソッド名をコピペした結果ゼロ幅スペースが入ったみたいで、xxdでバイナリ表示させると

00000000: 7072 696e 746c 6ee2 808b 2822 4865 6c6c  println...("Hell
00000010: 6f20 576f 726c 6421 2229 0a              o World!").

printlnの直後にe2 80 8bがあります。
ソースにバグがあるのは間違いないにしても、これでMissingMethodExceptionというのは分かりにくいですね。

余談

ちなみに上のソースをコピペすると、ちゃんとゼロ幅スペースが入っているので実行するとMissingMethodExceptionで失敗します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?