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

SpEL error #271

Closed
ghost opened this issue Apr 28, 2017 · 11 comments
Closed

SpEL error #271

ghost opened this issue Apr 28, 2017 · 11 comments

Comments

@ghost
Copy link

ghost commented Apr 28, 2017

I encounter this on the SimpleUserRepositoryTests of the SpEL test

2017-04-29 02:12:37.753  INFO 7124 --- [           main] o.s.t.c.transaction.TransactionContext   : Began transaction (1) for test context [DefaultTestContext@40f08448 testClass = SimpleUserRepositoryTests, testInstance = example.springdata.jpa.simple.SimpleUserRepositoryTests@35ef439e, testMethod = findByFirstnameOrLastnameUsingSpEL@SimpleUserRepositoryTests, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@276438c9 testClass = SimpleUserRepositoryTests, locations = '{}', classes = '{class example.springdata.jpa.simple.SimpleConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@754ba872, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6eebc39e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1ed4004b], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@ae202c6]; rollback [true]
2017-04-29 02:12:37.800  INFO 7124 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test context [DefaultTestContext@40f08448 testClass = SimpleUserRepositoryTests, testInstance = example.springdata.jpa.simple.SimpleUserRepositoryTests@35ef439e, testMethod = findByFirstnameOrLastnameUsingSpEL@SimpleUserRepositoryTests, testException = org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'firstname' cannot be found on null, mergedContextConfiguration = [MergedContextConfiguration@276438c9 testClass = SimpleUserRepositoryTests, locations = '{}', classes = '{class example.springdata.jpa.simple.SimpleConfiguration}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.SpringBootTestContextCustomizer@754ba872, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@6eebc39e, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1ed4004b], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]].

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'firstname' cannot be found on null

	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:220)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46)
	at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:375)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299)
	at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.evaluateExpression(SpelExpressionStringQueryParameterBinder.java:131)
	at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.potentiallyBindExpressionParameters(SpelExpressionStringQueryParameterBinder.java:89)
	at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.bind(SpelExpressionStringQueryParameterBinder.java:69)
	at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:161)
	at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:152)
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:81)
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190)
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:121)
	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:85)
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116)
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	at com.sun.proxy.$Proxy75.findByFirstnameOrLastname(Unknown Source)
	at example.springdata.jpa.simple.SimpleUserRepositoryTests.findByFirstnameOrLastnameUsingSpEL(SimpleUserRepositoryTests.java:207)
	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 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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

I don't know why ,but I encountered this, I didn't change anything of the master .
I got idea prompt that" identifier expected" blow the SpEL ,so I guess maybe the SpEL is wrong?

@schauder
Copy link
Contributor

schauder commented May 2, 2017

Trying this real quick, showed the following:

mvn clean install 

works just fine.

executing the test class in the IDE produced the failure mentioned above in findByFirstNameAndLastNameBySpEL and another one in findByFirstNameAndLastName with this caused by:

Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.

Might be that the parameter name information is missing in the class file or something, although maven and my IDE should use the same JDK.

@schauder
Copy link
Contributor

schauder commented May 2, 2017

@frankchang1990 can you provide details in what kind of environment you execute the test? (JDK, Maven vs IDE ..)

@schauder
Copy link
Contributor

schauder commented May 2, 2017

:-/ my test failures now disappeared, so I can't reproduce the error at all. Which reinforces my suspicion that this might be an artifact of the environment, possibly not using jdk8.

@chan71
Copy link
Contributor

chan71 commented May 3, 2017

@frankchang1990 i could reproduce your issue and the issue in findByFirstNameAndLastName that @schauder has mentioned. In addition I got another tests failing due to error 2 in findByFirstnameOrLastname() test.

Error 1:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'firstname' cannot be found on null

Error 2:
org.springframework.dao.InvalidDataAccessApiUsageException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.

The issue seems to be the missing annotation in SimpleUserRepository interface. I'm yet to find a proper explanation though.

@Query("select u from User u where u.firstname = :#{#user.firstname} or u.lastname = :#{#user.lastname}")
Iterable<User> findByFirstnameOrLastname(@Param("user") User user);

@chan71
Copy link
Contributor

chan71 commented May 3, 2017

@olivergierke I'm willing to contribute to this project. Please advice.

chan71 added a commit to chan71/spring-data-examples that referenced this issue May 3, 2017
@schauder
Copy link
Contributor

schauder commented May 4, 2017

Sorry, but I don't think this is a bug.

Make sure

  • you compile all the code with JDK 8.
  • execute it with JDK 8
  • don't set any options that exclude parameter name information

If the problem persists let us know about the exact configuration, so we can reproduce this issue.

@odrotbohm
Copy link
Member

As @schauder the project is set up as expected. We configure the compiler to include parameter name information using the -parameters option.

@chan71
Copy link
Contributor

chan71 commented May 4, 2017

@olivergierke I agree with your comment. However, 2 tests failed when run from my IDE. However, if I run the test from command line (path set to java 8) using maven (3.5), all tests get passed without errors.
>mvn -Dtest=SimpleUserRepositoryTests test

Failing environment uses:
IntelliJ Idea
Java compiler and Project JDK set to Java 1.8 (and I have only Java 8 in my machine)

@schauder
Copy link
Contributor

schauder commented May 4, 2017

@chan71 this makes it just even more obvious, that the issue is with the IDE and/or its configuration and not an issue of Spring Data.

@odrotbohm
Copy link
Member

Again, Jens is right. Make sure IntelliJ compiles with -parameters, too. 🙃

@chan71
Copy link
Contributor

chan71 commented May 4, 2017

@schauder my error disappeared from IntelliJ when I ran it again. I ran the tests from Maven Project (window) -> Spring Data JPA - Examples -> Lifecycle -> test before running SimpleUserRepositoryTests from the IDE.

chan71 added a commit to chan71/spring-data-examples that referenced this issue May 7, 2017
chan71 added a commit to chan71/spring-data-examples that referenced this issue May 7, 2017
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

3 participants