IndexOutOfBoundException and PropertyModel
Hi all, I'm wondering why the PropertyModel sends an IndexOutOfBoundException when I use an expression such as myList.0.name and that the 0 element doesn't exist, whereas it doesn't sends a NullPointerException when I user person.name with a null person. Is it a wanted behavior or not (or a mistake from me) thank you -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17315359.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
The person.name check getPerson().setName() , getName(). If the person is null you will get a nullpointer. If you do get( 0 ) on a list and the null doens't exists then you will get a IndexOutOfBoundException. Just try with a normal list and an object. The list is probably initialized like with hibernate you will get an empty list. But doens't contains any elements. -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17316645.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
Well, if the person is null I don't get a NPE (to check, I took a wicket page, added an attribute A to it, displayed A.B with a Label + PropertyModel, but never setted the attribute A = I never got the NPE) What I meant in my first post, is since I don't get a NPE in that case, I was thinking that Wicket shouldn't throw a IOOBE in the case of an inexisting position in my List: according to me Wicket should handle it. Am i wrong ? Mathias P.W Nilsson wrote: The person.name check getPerson().setName() , getName(). If the person is null you will get a nullpointer. If you do get( 0 ) on a list and the null doens't exists then you will get a IndexOutOfBoundException. Just try with a normal list and an object. The list is probably initialized like with hibernate you will get an empty list. But doens't contains any elements. -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17316664.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
What I meant in my first post, is since I don't get a NPE in that case, I was thinking that Wicket shouldn't throw a IOOBE in the case of an inexisting position in my List: according to me Wicket should handle it. Am i wrong ? Yes, you are wrong. It's bad practice to refer to a location in a list if you're not sure the entry exists. Wicket probably *does* take care of the situation where your List is null. regards, Wouter -- Wouter Huijnink Func. Internet Integration W http://www.func.nl T +31 20 423 F +31 20 4223500 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
I don't know if I got it right. Is the A null? Are you just doing A a; or A a = null; ? If you do this I don't understand why you don't get an exception. The PropertyModel extends AbstractPropertyModel and when setting the property model it does a super. In the AbstractPropertyModel it checks if the object is null and throws a IllegalArgumentException. Is a really null? -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17316687.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
Well, i'm just doing A a; But I put a trace on the getA() and a is really null. Can you make a try ? Mathias P.W Nilsson wrote: I don't know if I got it right. Is the A null? Are you just doing A a; or A a = null; ? If you do this I don't understand why you don't get an exception. The PropertyModel extends AbstractPropertyModel and when setting the property model it does a super. In the AbstractPropertyModel it checks if the object is null and throws a IllegalArgumentException. Is a really null? -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17322053.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
I agree with you, my problem is on the fact that Wicket seems to me inconsistent because of the 2 behaviors: if I have the IOOBE I should have the NPE. Wouter Huijnink wrote: Yes, you are wrong. It's bad practice to refer to a location in a list if you're not sure the entry exists. Wicket probably *does* take care of the situation where your List is null. regards, Wouter -- Wouter Huijnink Func. Internet Integration W http://www.func.nl T +31 20 423 F +31 20 4223500 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17322161.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IndexOutOfBoundException and PropertyModel
I think a good practice is to always take care of null objects and list your self. You never know when or if the implementation might change. -- View this message in context: http://www.nabble.com/IndexOutOfBoundException-and-PropertyModel-tp17315359p17330046.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]