-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Defensive Copies in Persistent Classes
PostPosted: Fri Jan 07, 2005 6:07 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
I don't seem to be able to do

Code:
public Date getDate() {
    return (Date) date.clone();
}

without causing an exception.

Is this expected behavior?

Is there any documentation that explains why this is not possible?

Is there a technique to allow defensive copies in persistent classes?

Thanks for your help.

Andreas[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 08, 2005 9:37 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
I found the issue. I hadn't taken care of possible null values.

The correct way to implement a defensive copy would have been

Code:
    public Date getDate() {
        if ( date == null ) return null;

        return (Date) date.clone();
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.