Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ValueBinding not catching converter exception
ValueBinding not catching converter exception [message #1770903] Fri, 18 August 2017 15:05
Xavipen Mising name is currently offline Xavipen Mising nameFriend
Messages: 57
Registered: March 2011
Member
Hi,

I am developing an e4 application. In the application i have implemented a simple DateConverter.

public Object convert(Object fromObject){
   if (fromObject != null && fromObject.toString().trim().length() == 0){
       return null;
   }

   for (DateFormat f : formats){
       try{
            return f.parse(fromObject.toString());
       }catch (ParseException e){
           // Ignore
       }
   }

   throw new RuntimeException(message);
}


I have added the converter to the update strategy in the data-dinding and it is being called.

If the string is not parsable a RuntimeException will be thrown. ValueBinding should catch the exception and a decorator field should appear to indicated an error in the input.

However the exception is not catch and ends in the console log.

I have checked the ValueBinding source code and i see that in the execution of the doUpdate method there is a try and catch block that should have catch the RuntimeException ( verison 1.6.0 of org.eclipse.core.databinding)

	private void doUpdate(final IObservableValue source,
			final IObservableValue destination,
			final UpdateValueStrategy updateValueStrategy,
			final boolean explicit, final boolean validateOnly) {

		final int policy = updateValueStrategy.getUpdatePolicy();
		if (policy == UpdateValueStrategy.POLICY_NEVER)
			return;
		if (policy == UpdateValueStrategy.POLICY_ON_REQUEST && !explicit)
			return;

		source.getRealm().exec(new Runnable() {
			@Override
			public void run() {
				boolean destinationRealmReached = false;
				final MultiStatus multiStatus = BindingStatus.ok();
				try {
					// Get value
					Object value = source.getValue();

					// Validate after get
					IStatus status = updateValueStrategy
							.validateAfterGet(value);
					if (!mergeStatus(multiStatus, status))
						return;

					// Convert value
					final Object convertedValue = updateValueStrategy
							.convert(value);

					// Validate after convert
					status = updateValueStrategy
							.validateAfterConvert(convertedValue);
					if (!mergeStatus(multiStatus, status))
						return;
					if (policy == UpdateValueStrategy.POLICY_CONVERT
							&& !explicit)
						return;

					// Validate before set
					status = updateValueStrategy
							.validateBeforeSet(convertedValue);
					if (!mergeStatus(multiStatus, status))
						return;
					if (validateOnly)
						return;

					// Set value
					destinationRealmReached = true;
					destination.getRealm().exec(new Runnable() {
						@Override
						public void run() {
							if (destination == target) {
								updatingTarget = true;
							} else {
								updatingModel = true;
							}
							try {
								IStatus setterStatus = updateValueStrategy
										.doSet(destination, convertedValue);

								mergeStatus(multiStatus, setterStatus);
							} finally {
								if (destination == target) {
									updatingTarget = false;
								} else {
									updatingModel = false;
								}
								setValidationStatus(multiStatus);
							}
						}
					});
				} catch (Exception ex) {
					// This check is necessary as in 3.2.2 Status
					// doesn't accept a null message (bug 177264).
					String message = (ex.getMessage() != null) ? ex
							.getMessage() : ""; //$NON-NLS-1$

					mergeStatus(multiStatus, new Status(IStatus.ERROR,
							Policy.JFACE_DATABINDING, IStatus.ERROR, message,
							ex));
				} finally {
					if (!destinationRealmReached) {
						setValidationStatus(multiStatus);
					}

				}
			}
		});
	}


Am I missing something or is this a bug?
Previous Topic:Any reason why the "org.eclipse.jface.preference.PreferenceStore" class has no "remo
Next Topic:adding wizardPages and get the result dynamically
Goto Forum:
  


Current Time: Thu Sep 20 03:40:54 GMT 2018

Powered by FUDForum. Page generated in 0.04792 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top