uqbar-project / arena

MMVC framework
http://arena.uqbar-project.org/
4 stars 2 forks source link

Ugly exception when the class of the Table items is not @Observable #19

Closed fdodino closed 8 years ago

fdodino commented 9 years ago

If you have a window with a model object that is @Observable, and create a table bound to a list property which holds objects of type "B", let say. If that class B doesn't have the @Observable annotation, then when you run the application it will log the following ugly exception, because it tries to register a listener into an instance of B class, which was not weaved, and therefore doesn't have the observable methods.

org.eclipse.core.databinding - 0 - Could not attach listener to uqbar.examples.burros.model.Caballo@1682598
java.lang.NoSuchMethodException: uqbar.examples.burros.model.Caballo.addPropertyChangeListener(java.beans.PropertyChangeListener)
    at java.lang.Class.getMethod(Class.java:1605)
    at org.eclipse.core.internal.databinding.beans.ListenerSupport.processListener(ListenerSupport.java:177)
    at org.eclipse.core.internal.databinding.beans.ListenerSupport.hookListener(ListenerSupport.java:72)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.hookListener(JavaBeanObservableMap.java:86)
    at org.eclipse.core.databinding.observable.map.ComputedObservableMap.init(ComputedObservableMap.java:114)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.<init>(JavaBeanObservableMap.java:81)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.<init>(JavaBeanObservableMap.java:63)
    at org.eclipse.core.databinding.beans.BeansObservables.observeMap(BeansObservables.java:109)
    at org.eclipse.core.databinding.beans.BeansObservables.observeMaps(BeansObservables.java:171)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceLabelProviderBuilder.createLabelProvider(JFaceLabelProviderBuilder.java:41)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceTableItemsBindingBuilder.build(JFaceTableItemsBindingBuilder.java:33)
    at org.uqbar.lacar.ui.model.bindings.Binding.execute(Binding.java:79)
    at org.uqbar.arena.widgets.Control.showOn(Control.java:137)
    at org.uqbar.arena.widgets.Panel.showOn(Panel.java:121)
    at org.uqbar.arena.windows.Window.showOn(Window.java:189)
    at org.uqbar.arena.windows.Window.showOn(Window.java:1)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder.createWindowContents(JFaceWindowBuilder.java:104)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder$2.createContents(JFaceWindowBuilder.java:215)
    at org.eclipse.jface.window.Window.create(Window.java:431)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder.open(JFaceWindowBuilder.java:71)
    at org.uqbar.arena.windows.Window.open(Window.java:137)
    at org.uqbar.arena.Application.run(Application.java:70)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
    at org.uqbar.lacar.ui.impl.jface.JFaceApplicationBuilder.run(JFaceApplicationBuilder.java:25)
    at org.uqbar.arena.Application.start(Application.java:51)
    at uqbar.examples.burros.ui.arena.BurrosApplication.main(BurrosApplication.java:30)
org.eclipse.core.databinding - 0 - Could not attach listener to uqbar.examples.burros.model.Caballo@7c3885
java.lang.NoSuchMethodException: uqbar.examples.burros.model.Caballo.addPropertyChangeListener(java.beans.PropertyChangeListener)
    at java.lang.Class.getMethod(Class.java:1605)
    at org.eclipse.core.internal.databinding.beans.ListenerSupport.processListener(ListenerSupport.java:177)
    at org.eclipse.core.internal.databinding.beans.ListenerSupport.hookListener(ListenerSupport.java:72)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.hookListener(JavaBeanObservableMap.java:86)
    at org.eclipse.core.databinding.observable.map.ComputedObservableMap.init(ComputedObservableMap.java:114)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.<init>(JavaBeanObservableMap.java:81)
    at org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap.<init>(JavaBeanObservableMap.java:63)
    at org.eclipse.core.databinding.beans.BeansObservables.observeMap(BeansObservables.java:109)
    at org.eclipse.core.databinding.beans.BeansObservables.observeMaps(BeansObservables.java:171)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceLabelProviderBuilder.createLabelProvider(JFaceLabelProviderBuilder.java:41)
    at org.uqbar.lacar.ui.impl.jface.tables.JFaceTableItemsBindingBuilder.build(JFaceTableItemsBindingBuilder.java:33)
    at org.uqbar.lacar.ui.model.bindings.Binding.execute(Binding.java:79)
    at org.uqbar.arena.widgets.Control.showOn(Control.java:137)
    at org.uqbar.arena.widgets.Panel.showOn(Panel.java:121)
    at org.uqbar.arena.windows.Window.showOn(Window.java:189)
    at org.uqbar.arena.windows.Window.showOn(Window.java:1)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder.createWindowContents(JFaceWindowBuilder.java:104)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder$2.createContents(JFaceWindowBuilder.java:215)
    at org.eclipse.jface.window.Window.create(Window.java:431)
    at org.uqbar.lacar.ui.impl.jface.windows.JFaceWindowBuilder.open(JFaceWindowBuilder.java:71)
    at org.uqbar.arena.windows.Window.open(Window.java:137)
    at org.uqbar.arena.Application.run(Application.java:70)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
    at org.uqbar.lacar.ui.impl.jface.JFaceApplicationBuilder.run(JFaceApplicationBuilder.java:25)
    at org.uqbar.arena.Application.start(Application.java:51)
    at uqbar.examples.burros.ui.arena.BurrosApplication.main(BurrosApplication.java:30)
fdodino commented 8 years ago

Added a validation in constructor of Table class:

    public Table(Container container, Class<R> itemType) {
        super(container);
        if (!itemType.isAnnotationPresent(org.uqbar.commons.utils.Observable.class)) {
            throw new ArenaException("La clase " + itemType.getName() + " debe tener la annotation @Observable");
        }

So now, instead of that ugly error you get this message:

Exception in thread "main" org.uqbar.arena.ArenaException: La clase org.uqbar.ejemplosWidgets.appModel.Provincia debe tener la annotation @Observable

Side effect: app used to work before, but you could see that ugly stack trace. Now app crahes (maybe it's better this way).