cancel
Showing results for 
Search instead for 
Did you mean: 

Null pointer Exception in searchRestrictionService

Former Member
0 Kudos

I am searching products with flexible query which is working fine on hac. While writing flexible query in my java class I want to disable all restriction and for that I am using following code

 public class abc 
 
 {
 @Resource
     private UserService userService;
 
 private SearchRestrictionService searchRestrictionService;
 public List<ProductModel> findProducts()
     {
        final String query = "select {p:name},{p.creationtime},from {Product! as p} ";
       userService.setCurrentUser(userService.getAdminUser());
            
 try
         {
             this.searchRestrictionService.disableSearchRestrictions();
         }
         catch (final NullPointerException e)
         {
             System.out.println("Problem in restriction");
             e.printStackTrace();
         }

} }

Above is a part of my code. On executing above code I am getting message in output as "Problem in restriction" as I have set this message for null pointer exception. Please suggest ho can i remove this exception from restriction property.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

@Resource was missing before searchRestrictionService variable declaration. It should be like this :-

 @Resource
 private SearchRestrictionService searchRestrictionService;

Answers (1)

Answers (1)

former_member708417
Participant
0 Kudos

searchRestrictionService is not injected into you abc class, due to that reason your getting NullPointerException.

As told please inject searchRestrictionService into you abc class. This will solve the NPE.