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 6358617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:24:41+00:00 2026-05-24T23:24:41+00:00

I am trying to build a microsimulation model with Groovy, but I am stuck

  • 0

I am trying to build a microsimulation model with Groovy, but I am stuck with a problem that I traced back to Groovy’s handling of null values in Groovy Bean constructors.

In short, the constructor method that Groovy offers

new Person(nrLegs:calculationResult1, nrArms:calculationResult2)

throws an IllegalArgumentException if one of the calculation results is null, which is how I thought missing survey data would be best represented.

This is what seems strange to me: If I define a variable double age; without value, it is set to null, obviously.

double testDouble;
assert testDouble == null; // no Problem

If I do the same with Groovy beans, it has a value of 0.0, e.g:

class Person {
double age;
int nrLegs, nrArms;
}

then

Person testPerson = new Person(nrArms:calculationResult1) 
assert testPerson.age == null; // Assertion failed. testPerson.age == 0.0

Furthermore, I cannot set properties to null using the Groovy syntax:

Person testPerson = new Person(nrArms:calculationResult1) 
testPerson.age = null; // IllegalArgumentException

This seems to be exactly the same problem as above.

Why would Groovy forbid me to assign null values?

Thanks for your help!

Edit: for reference, here are the entire Person class and the StackTrace.

  • 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-24T23:24:42+00:00Added an answer on May 24, 2026 at 11:24 pm

    The problem is that you’re trying to assign null to a bean property of int type.

    int is a primitive type. It’s not an object, and so is not nullable : it has to have a value. These are the same rules as for Java – the primitive types are int, float, boolean, double, char… . On object creation, a primitive property is initialized to 0, 0.0, false, etc.

    If you need to represent ‘no data’, then it’s probably best to edit the class definition so that the bean property uses the corresponding object wrapper type – in this caseInteger – which can then be set to null.

    If you’re unable to edit the class, then common work arounds are to use some kind of marker value – e.g. -1, or Integer.MIN_VALUE, or somesuch. But then logic that manipulates the Person class needs to understand the significance of the marker value

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

Sidebar

Related Questions

Im trying to build a small frame that displays an image. My problem is
I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
Im trying to build a query that will fetch all changed rows from a
I'm trying build a regex that will replace any characters not of the format:
Trying to build a plugin effect that will some what look better than this
im trying to build a form+attachment that needs to be send to email. Im
Im trying to build a form which uses AJAX but its failing to execute
Trying to build a dynamic gallery that is loaded via AJAX. I'm trying to
Trying to build my android project with Buildr (Apache), but can't find any info
Im trying to build a form that calculates a total price based on a

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.