Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6188067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:09:59+00:00 2026-05-24T02:09:59+00:00

We have a chunk of code something like this // semi-pseudo code def result

  • 0

We have a chunk of code something like this

// semi-pseudo code
def result = someList.find { condition == true }

(someList may be null, but that is ok in groovy as null.find{…} works fine.)

This line of code is running in an action of a grails controller and deployed in production to a server. After a period of time (sometimes hours, sometimes longer) the above line of code will start throwing a NullPointerException — and once it starts throwing the NPE it always throws the NPE.

Through debugging we’ve proven that it works fine even when someList is null (up until we get the seemingly random first NPE)… also through debugging we were able to get a more detail stacktrace that indicated there error was in Groovy’s MetaClassRegistryImpl.java line 214.

stack trace

I’ve googled every combination I can think of to see if there are any known Groovy bugs but found nothing of value.

(It is using Grails 1.3.7, thus Groovy 1.7.8)

A JMeter script was setup to run through a series of site interactions that makes this problem semi-repeatable. The script will iterate through 50-100 series and then the error starts appearing – once the error appears it is always in error until the application is redeployed to the server (Glassfish).

Tracing through the groovy code it looks something like this:

//AbstractCallSite.java
public Object call(Object receiver, Object arg1) throws Throwable {
    return call(receiver, ArrayUtil.createArray(arg1));
}

//PerInstancePojoMetaClassSite.java
public Object call(Object receiver, Object[] args) throws Throwable {
    if (info.hasPerInstanceMetaClasses()) {
      try {
          return InvokerHelper.getMetaClass(receiver).invokeMethod(receiver, name, args);
      } catch (GroovyRuntimeException gre) {
          throw ScriptBytecodeAdapter.unwrap(gre);
      }
    } else {
      return CallSiteArray.defaultCall(this, receiver, args);
    }
}


//InvokerHelper.java
public static MetaClass getMetaClass(Object object) {
    if (object instanceof GroovyObject)
        return ((GroovyObject) object).getMetaClass();
    else
        return ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object);
}

//MetaClassRegistryImpl.java
public MetaClass getMetaClass(Object obj) {
    return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj);
}

So it appears the NPE is on the obj.getClass() — if that’s the case I’m a little baffled how it ever works when someList is null (but that is a separate topic).

FWIW, we are not doing any class or instance level meta-class coding of our own on someList.

Is there a bug in Groovy or what could we possibly be doing wrong to cause a (random) NPE deep in Groovy code?

UPDATE—

The observation is that someList is being set to a ‘java null’ instead of a ‘groovy null’ (NullObject). The object is coming from a map (flow context) via a flow in a controller action…

class SomeController {

    def someActionFlow = {
        action {

            def someList = flow.someList

        }
    }
}

The case in question is when flow.someList has never been set it should always be null (groovy null). flow is just a map so it is the same as doing flow.get('someList')

The above code works fine for an unknown number of iterations and then starts returning ‘java nulls’ instead of ‘groovy nulls’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:09:59+00:00Added an answer on May 24, 2026 at 2:09 am

    I’m going to hazard a guess that it’s dependent on how someList is created. That is, if it’s created in Groovy as

    def someList = null
    

    Then Groovy assigns the NullObject to the variable. However, if the value is returned from some other Java component as a real Java null, then it will throw the NPE. Going further, there might be some optimization in Groovy/Java/JVM where callsite caching is causing it to always return NPE.

    Then again, this is just a wild guess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have the following chunk of code: <div id=container> <someelement>This is any
Ok so i have this chunk of code <p id=number_of_stations class=text left><?php $_GET['count'] !=
I have a structure, that contain string. Something like that: struct Chunk { int
I have a chunk of code where it appears that a variable is changing
Imagine I have a chunk of initialisation code at the top of a stored
I have this chunk on jQuery and currently its living in my index.html.erb and
I have a chunk of code where sometimes I need to create a new
This chunk of code doesnt seem to be doing its job. line=(ImageView)findViewById(R.id.imageView1); RelativeLayout.LayoutParams params==(RelativeLayout.LayoutParams)line.getLayoutParams();
This may be a n00b topic but, anyways, I have been having a rather
I have a large chunk of legacy php code that I need to interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.