Monday, October 23, 2006

Pardon our Progress: BindSpec and provisional APIs

A couple of people have run into issues lately attempting to use the provisional APIs in the latest version of Data Binding. They receive an exception along the lines of...

Exception in thread "main" org.eclipse.jface.internal.databinding.provisional.BindingException: No binding found for target: org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue, model: org.eclipse.jface.databinding.observable.value.WritableValue

at org.eclipse.jface.internal.databinding.provisional.DataBindingContext.bind(DataBindingContext.java:170)

at org.eclipse.jface.internal.databinding.provisional.DataBindingContext.bind(DataBindingContext.java:228)

The issue is that the incorrect BindSpec has been passed to DataBindingContext.bind(...). But how can that be? Shouldn't the API enforce the correct type? Yes, well most of the time is should...

The signature for bind(...) is as follows...

public Binding bind(Object targetDescription,Object modelDescription, org.eclipse.jface.databinding.BindSpec bindSpec)


The method expects an instance of org.eclipse.jface.databinding.BindSpec. This is the 1.0 BindSpec. The problem is that internally if bind(...) doesn't receive an instance of org.eclipse.jface.internal.databinding.provisional.BindSpec, the provisional BindSpec, it won't create the Binding. The reason for this confusion is that we're trying to keep the provisional APIs working while refactoring to the 1.0 APIs. So even though the signature of the bind(...) method accepts org.eclipse.jface.databinding.BindSpec don't pass this type, pass org.eclipse.jface.internal.databinding.provisional.BindSpec instead.

So let's recap, when using the provisional DataBindingContext...

org.eclipse.jface.databinding.BindSpec == bad

org.eclipse.jface.internal.databinding.provisional.BindSpec == good

For more information see bug 161498.

No comments: