Bug 262284 - [DataBinding] Properties should verify the source object is the expected type before constructing observables
Summary: [DataBinding] Properties should verify the source object is the expected type...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-24 10:55 EST by Matthew Hall CLA
Modified: 2019-09-06 15:30 EDT (History)
2 users (show)

See Also:


Attachments
Patch (15.22 KB, patch)
2009-03-16 13:54 EDT, Matthew Hall CLA
no flags Details | Diff
mylyn/context/zip (20.27 KB, application/octet-stream)
2009-03-16 13:54 EDT, Matthew Hall CLA
no flags Details
Patch (90.15 KB, patch)
2009-03-16 17:08 EDT, Matthew Hall CLA
no flags Details | Diff
mylyn/context/zip (31.46 KB, application/octet-stream)
2009-03-16 17:08 EDT, Matthew Hall CLA
no flags Details
Patch (90.73 KB, patch)
2009-03-16 17:11 EDT, Matthew Hall CLA
no flags Details | Diff
mylyn/context/zip (31.85 KB, application/octet-stream)
2009-03-16 17:11 EDT, Matthew Hall CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Hall CLA 2009-01-24 10:55:15 EST
Currently an observable can be constructed from a property and the source object will not be consulted or even verified to be the correct type until listeners are registered or an accessor / mutator is called on the observable.  Ideally properties should assert that source objects are the correct type (or null) before constructing observables.
Comment 1 Matthew Hall CLA 2009-03-16 13:54:53 EDT
Created attachment 128961 [details]
Patch

Boris, there is a test that throws an exception with this patch (testGetValueThrowsExceptionThrownByBean).  I'm using property.getValue() as a sniff test at runtime to ensure that the property source is the right type for the property.

I'm not sure if we should revise the test or take a different approach.  I was in the middle of revising properties to override observe(Realm, Object) and cast the Object to the expected type before calling the super implementation.  However I had to do this on every single property class and doing the test once in the observable seemed a better approach.

Thoughts?
Comment 2 Matthew Hall CLA 2009-03-16 13:54:58 EDT
Created attachment 128962 [details]
mylyn/context/zip
Comment 3 Matthew Hall CLA 2009-03-16 15:16:32 EDT
Thinking about this more, I think that property.getValue() is not a good test since for these two conditions:
A) object is the wrong type
B) property getter throws exception

A implies B but B does not imply A.  With B you could be rethrowing an exception thrown from the property source itself.  I guess this will have to be done the ugly way.
Comment 4 Matthew Hall CLA 2009-03-16 17:08:45 EDT
Created attachment 128999 [details]
Patch

Added methods to Simple<Value|List|Set|Map>Property:

/**
 * Returns the type of source object this property may be used with.
 * 
 * @return the type of source object this property may be used with.
 */
public Object getSourceType();

/**
 * Throws an exception if the source object is not the correct type.
 */
protected void checkSourceType(Object source);
Comment 5 Matthew Hall CLA 2009-03-16 17:08:59 EDT
Created attachment 129000 [details]
mylyn/context/zip
Comment 6 Matthew Hall CLA 2009-03-16 17:11:46 EDT
Created attachment 129001 [details]
Patch

updated javadoc comments
Comment 7 Matthew Hall CLA 2009-03-16 17:11:55 EDT
Created attachment 129002 [details]
mylyn/context/zip
Comment 8 Matthew Hall CLA 2009-03-16 17:12:56 EDT
This patch introduces new API so it has to wait until 3.6
Comment 9 Mike Wilson CLA 2009-05-05 12:46:33 EDT
Changing Version tag to something more believable. Note that this is not a statement about when the enhancement request will be addressed (the Target Milestone field is used for that); the Version tag should be set to the version of Eclipse you were using when you saw the need for the enhancement.
Comment 10 Paul Webster CLA 2010-06-09 08:17:49 EDT
Removed from 3.6.  Owners can re-assess.

PW
Comment 11 Eclipse Webmaster CLA 2019-09-06 15:30:12 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.