SpelEvaluationException: EL1007E: (pos 43): Field or property 'group' could not be found at zero

I have a SPRING METHOD Security fully configured for my web application. (with PRE / POST annotations).

However, recently I ran into some strange problem. Follow these steps:

  • POJOS Summary

    // User Class public class User { int id; String name; // getters and setters } // Group Class public class Group { int id; String name; // getters and setters } // GroupMembership class public class GroupMembership { private int id; private User user; private Group group; // getters and setters } 
  • PreAuthorise filter by method.

     @PreAuthorize("canIEditGroupProfile(#membership.group.id)") public int updateGroupMembership(GroupMembership membership) throws GroupsServiceException; 

When passing through a fully populated GroupMembership object (corresponding user and group compositions), the security filter generates the following exception:

 errorMessage: "Failed to evaluate expression canIEditGroupProfile(#membership.group.id)'" 

When digging into the exception:

Reason found:

 org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 33): Field or property 'group' cannot be found on null 

Please indicate pointers to the same.

+6
source share
3 answers

getter / setters seems fine ... also there is no null case.

However, an interesting observation; this gives me an error:

 @PreAuthorize("canIEditGroupProfile(#membership.group.id)") public int updateGroupMembership(GroupMembership membership) throws GroupsServiceException; 

This works great:

 @PreAuthorize("canIEditGroupProfile(#groupmembership.group.id)") public int updateGroupMembership(GroupMembership groupmembership) throws GroupsServiceException; 

Further, I noticed that the parameter name was a mismatch in the first case (for example, Service and ServiceImpl had different parameter names).

Now, while maintaining uniformity, the problem seems to be fixed.

+4
source

As @zeroflagL asked: Do you compile without debugging information? This is probably the same problem as spring @Cacheable with Ehcache, spel find null for the actual object and spring @Cacheable with the SpEL key: always evaluate to null - check your POM configuration (or Eclipse or something else) for your configuration debugging, for example <debug>false</debug> in maven-compiler-plugin .

0
source

I have the same problem in my Spring Boot application. It turned out that I was compiling without my debugging symbol information, as mentioned in the comment above. I would like to note that I could solve the problem in two ways:

1. (My favorite): Just include this in your pom.xml -> plugins

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerArgument>-parameters</compilerArgument> <testCompilerArgument>-parameters</testCompilerArgument> </configuration> </plugin> 
  1. If you use Java 1.8 and Eclipse as the IDE, go to Project Properties β†’ Java Compile β†’ check "Store information about the method parameters (can be used with reflection)".

I found this link really interesting to learn more about this issue.

Hope this helps!

0
source

All Articles