Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. AbstractCallSite.call() has thrown a NullPointerException
    Apache Groovy
    6
    13
    2
  2. NullPointerException thrown on NullObject
    Apache Groovy
    34
    86
    38

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.NullPointerException: Cannot invoke method getPrincipalName() on null object
    at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
89 frames hidden

Solution

Mohd Salauddin3 months ago

NullObject.invokeMethod() has thrown a NullPointerException This is the exception from NullObject Class in Groovy. Whenever we call any method in groovy on null object , we get "Cannot invoke method " name of th method " on null object"

whenenver we reference any object in groovy to null ( def sampleObject = null ) , it becomes the object of NullObject Class and if we try to call any method on that (sampleObject), groovy will call invokeMethod() method on null object and thows NullPointerException

One Simple Solution to this is , using ?, For Example , sampleObject?.methodName() ; This is will not throw NullPointerException , It only calls method, if the object is not null.

External results for this pattern (10)

  1. jk1via GitHub3 days ago
    Cannot invoke method getArtifacts() on null object
    Show stack trace
  2. onusgitvia GitHub5 days ago
    Failed to capture snapshot of input files for task ':react-native-push-notification:compileDebugAidl' property 'importDirs' during up-to-date check.
    Show stack trace
  3. Eric Hovia Google Groups2 weeks ago
    Cannot invoke method getAt() on null object
    Show stack trace
  4. Steve Storckvia Google Groups2 weeks ago
    Cannot invoke method getBean() on null object
    Show stack trace
  5. Laurent Kempévia Google Groups2 weeks ago
    Cannot invoke method getName() on null object
    Show stack trace
  6. seilc1via GitHub2 weeks ago
    Cannot invoke method size() on null object
    Show stack trace
  7. smartbinbinvia GitHub1 month ago
    A problem occurred configuring project ':library'.
    Show stack trace
  8. wkingvia GitHub1 month ago
    Cannot invoke method isInQueue() on null object
    Show stack trace
  9. mrkhanakiavia GitHub1 month ago
    Failed to capture snapshot of input files for task ':react-native-device-info:compileDebugAidl' property 'importDirs' during up-to-date check.
    Show stack trace
  10. schwichtivia GitHub1 month ago
    java.lang.NullPointerException: Cannot invoke method inE() on null object
    Show stack trace