简体   繁体   中英

Grails/Groovy compiler error mystery

This line of code:

def exists = (existingIndRecs.find{ existant -> existant.uniqueId == incomingRecord.uniqueId}​​​​​ ? true : false)

is causing this error upon compilation:

/FileImportService.groovy: 184: expecting ')', found '​​​​​' @ line 184, column 100.
Id == incomingRecord.uniqueId}​​​​​ ? tr
                             ^

1 error

If I comment this line out the rest of the 776 lines of code in the file compile just fine. I tried this line in the Groovy web console and no problems there. Strange.

You must be having some special characters in your source code. When I bring up groovyConsole and type this:

class Record {
  int uniqueId;
  Record(int uniqueId) { this.uniqueId = uniqueId; }
}
def existingIndRecs = [new Record(1), new Record(2)]
def incomingRecord = new Record(1)
def exists = (existingIndRecs.find{ existant -> existant.uniqueId == incomingRecord.uniqueId} ? true : false)

it works. When I replace the last line with yours (visually identical), it fails with

expecting ')', found '​​​​​' at line: 7, column: 94

I did a hexdump diff and see the following:

$ diff -u 1.hex 2.hex
--- 1.hex   2014-07-13 19:32:02.343929086 -0400
+++ 2.hex   2014-07-13 19:32:05.419928970 -0400
@@ -3,7 +3,6 @@
 00000020  6e 64 7b 20 65 78 69 73  74 61 6e 74 20 2d 3e 20  |nd{ existant -> |
 00000030  65 78 69 73 74 61 6e 74  2e 75 6e 69 71 75 65 49  |existant.uniqueI|
 00000040  64 20 3d 3d 20 69 6e 63  6f 6d 69 6e 67 52 65 63  |d == incomingRec|
-00000050  6f 72 64 2e 75 6e 69 71  75 65 49 64 7d e2 80 8b  |ord.uniqueId}...|
-00000060  e2 80 8b e2 80 8b e2 80  8b e2 80 8b 20 3f 20 74  |............ ? t|
-00000070  72 75 65 20 3a 20 66 61  6c 73 65 29 0a           |rue : false).|
-0000007d
+00000050  6f 72 64 2e 75 6e 69 71  75 65 49 64 7d 20 3f 20  |ord.uniqueId} ? |
+00000060  74 72 75 65 20 3a 20 66  61 6c 73 65 29 0a        |true : false).|
+0000006e

Google says e2 80 8b is "zero-width space", whatever this means.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM