-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Lucas Cimon opened DATAMONGO-2119 and commented
Hi.
I created a PR providing an example here: https://github.com/spring-projects/spring-data-mongodb/pull/616/files
Here is the main code snippet:
@Query("{ 'key.lastname' : { '$regex' : ?#{[0].lastname} }")
Person findByPersonLastnameRegex(Person key);When ran, the test triggers the following stack trace:
java.lang.IllegalArgumentException: Dangling meta character '?' near index 0
?expr0
^ at org.springframework.data.mongodb.repository.query.StringBasedMongoQueryUnitTests.createQueryForMethod(StringBasedMongoQueryUnitTests.java:614)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQueryUnitTests.shouldAllowCombinationOfSpELAndRegex(StringBasedMongoQueryUnitTests.java:505)
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:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:79)
at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:85)
at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0
?expr0
^
at java.util.regex.Pattern.error(Pattern.java:1955)
at java.util.regex.Pattern.sequence(Pattern.java:2123)
at java.util.regex.Pattern.expr(Pattern.java:1996)
at java.util.regex.Pattern.compile(Pattern.java:1696)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1054)
at com.mongodb.util.JSONCallback.objectDone(JSONCallback.java:105)
at com.mongodb.util.JSONParser.parseObject(JSON.java:275)
at com.mongodb.util.JSONParser.parse(JSON.java:228)
at com.mongodb.util.JSONParser.parseObject(JSON.java:264)
at com.mongodb.util.JSONParser.parse(JSON.java:228)
at com.mongodb.util.JSONParser.parse(JSON.java:156)
at com.mongodb.util.JSON.parse(JSON.java:98)
at com.mongodb.util.JSON.parse(JSON.java:79)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQuery$ParameterBindingParser.parseAndCollectParameterBindingsFromQueryIntoBindings(StringBasedMongoQuery.java:228)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQuery.<init>(StringBasedMongoQuery.java:96)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQuery.<init>(StringBasedMongoQuery.java:75)
at org.springframework.data.mongodb.repository.query.StringBasedMongoQueryUnitTests.createQueryForMethod(StringBasedMongoQueryUnitTests.java:611)
... 28 moreIt seems to me that SpEL expression and the $regex filter are incompatible.
Is that right ?
The documentation implies this should work.
Regards
Affects: 2.0.11 (Kay SR11), 2.1.2 (Lovelace SR2)
Referenced from: pull request #621
Backported to: 2.1.3 (Lovelace SR3), 2.0.12 (Kay SR12)
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug