Results 1 to 4 of 4

Thread: AbstractValueModel

  1. #1
    Join Date
    Aug 2004
    Location
    Switzerland
    Posts
    32

    Default AbstractValueModel

    Hi,

    today i run in following problem with the AbstractValueModel:

    Code:
    ValueHolder  valueHolder = new ValueHolder(new Object());
    valueHolder.set( new Object());
    this code will throw a NullPointerException because the method set(Object o) calls fireValueChanged() and the used listeners List is not instanciated. The List member is only instanciated if a ValueListener is registered.

    Code:
    &#91;ERROR&#93; ApplicationAdvisor - null <java.lang.NullPointerException>java.lang.NullPointerException
    	at org.springframework.rules.values.AbstractValueModel.fireValueChanged&#40;AbstractValueModel.java&#58;63&#41;
    	at org.springframework.rules.values.ValueHolder.set&#40;ValueHolder.java&#58;40&#41;
    For the listeners i would sugest an eager instanciation, but I checked the CVS History and it was eager until the check in on 18.08.04!

    Now, why it was changes to "lazy"? And what is the best solution to this problem?

    - Back to eager instanciation?
    - Check if not null on fireValueChanged?
    - ...

    siu
    Claudio

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Indeed a bug. I still think lazy is what we want, as there can be a lot of these value model objects, and potentially some without value listeners. Will fix promptly.

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Well, maybe that case isn't so common after all, as otherwise my tests would've caught it. Hmm... I guess in generally I've been favoring lazy instantiation where possible in a Swing environment to help get the best possible performance.

  4. #4
    Join Date
    Aug 2004
    Location
    Switzerland
    Posts
    32

    Default

    Keith,

    in general i like the eager instanciation, because it is more "bug-save".
    But in this case, i'm with you as there can be alot of ValueModel without listeners!

    Thanks for the quick reply
    Claudio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •