Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scanLabeledControl logic issue #11348

Closed
2 tasks done
InAnYan opened this issue Jun 3, 2024 · 2 comments · Fixed by #11349
Closed
2 tasks done

scanLabeledControl logic issue #11348

InAnYan opened this issue Jun 3, 2024 · 2 comments · Fixed by #11349

Comments

@InAnYan
Copy link
Member

InAnYan commented Jun 3, 2024

JabRef version

5.13 (latest release)

Operating system

Windows

Details on version and operating system

No response

Checked with the latest development build (copy version output from About dialog)

  • I made a backup of my libraries before testing the latest development version.
  • I have tested the latest development version and the problem persists

Steps to reproduce the behaviour

  1. I've made a custom properties tab. It contains Label's, CheckBox'es, TextField's, TextArea's, and... Text's.
  2. I've got a runtime error (details are in the appendix)

Appendix

...

Log File
java.lang.IllegalStateException: Cannot load org.jabref.gui.preferences.preferencesdialog
	at afterburner.fx/com.airhacks.afterburner.views.ViewLoader.load(ViewLoader.java:174)
	at [email protected]/org.jabref.gui.preferences.PreferencesDialogView.<init>(PreferencesDialogView.java:53)
	at [email protected]/org.jabref.gui.preferences.ShowPreferencesAction.execute(ShowPreferencesAction.java:26)
	at [email protected]/org.jabref.gui.actions.JabRefAction.lambda$new$3(JabRefAction.java:40)
	at [email protected]/org.controlsfx.control.action.Action.handle(Action.java:423)
	at [email protected]/org.controlsfx.control.action.Action.handle(Action.java:64)
	at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
	at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
	at [email protected]/javafx.scene.control.MenuItem.fire(MenuItem.java:459)
	at [email protected]/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1415)
	at [email protected]/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createChildren$12(ContextMenuContent.java:1368)
	at [email protected]/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
	at [email protected]/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
	at [email protected]/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
	at [email protected]/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at [email protected]/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at [email protected]/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at [email protected]/javafx.event.Event.fireEvent(Event.java:198)
	at [email protected]/javafx.scene.Scene$MouseHandler.process(Scene.java:3985)
	at [email protected]/javafx.scene.Scene.processMouseEvent(Scene.java:1891)
	at [email protected]/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2709)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
	at [email protected]/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:430)
	at [email protected]/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
	at [email protected]/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
	at [email protected]/com.sun.glass.ui.View.notifyMouse(View.java:937)
	at [email protected]/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
	at [email protected]/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$10(GtkApplication.java:264)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: javafx.fxml.LoadException: 
/home/ruslan/Projects/JabRef/build/resources/main/org/jabref/gui/preferences/PreferencesDialog.fxml

	at [email protected]/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2727)
	at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2697)
	at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2568)
	at [email protected]/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2536)
	at afterburner.fx/com.airhacks.afterburner.views.ViewLoader.load(ViewLoader.java:172)
	... 46 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:109)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:72)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at [email protected]/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:270)
	at [email protected]/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
	at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2693)
	... 49 more
Caused by: java.lang.ClassCastException: class javafx.scene.text.Text cannot be cast to class javafx.scene.Parent (javafx.scene.text.Text and javafx.scene.Parent are in module [email protected] of loader 'app')
	at [email protected]/org.jabref.gui.preferences.PreferencesSearchHandler.scanLabeledControls(PreferencesSearchHandler.java:94)
	at [email protected]/org.jabref.gui.preferences.PreferencesSearchHandler.scanLabeledControls(PreferencesSearchHandler.java:94)
	at [email protected]/org.jabref.gui.preferences.PreferencesSearchHandler.getPrefsTabLabelMap(PreferencesSearchHandler.java:81)
	at [email protected]/org.jabref.gui.preferences.PreferencesSearchHandler.<init>(PreferencesSearchHandler.java:27)
	at [email protected]/org.jabref.gui.preferences.PreferencesDialogView.initialize(PreferencesDialogView.java:85)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	... 56 more
@InAnYan
Copy link
Member Author

InAnYan commented Jun 3, 2024

The problem lies here:

    private static void scanLabeledControls(Parent parent, ArrayListMultimap<PreferencesTab, Labeled> prefsTabLabelMap, PreferencesTab preferencesTab) {
        for (Node child : parent.getChildrenUnmodifiable()) {
            if (!(child instanceof Labeled)) {
                scanLabeledControls((Parent) child, prefsTabLabelMap, preferencesTab);
            } else {
                Labeled labeled = (Labeled) child;
                if (!labeled.getText().isEmpty()) {
                    prefsTabLabelMap.put(preferencesTab, labeled);
                }
            }
        }
    }

In this code there are two branches for a child:

  1. If a child is Labeled: add it to prefsTabLabelMap.
  2. If it's not, then TREAT IT AS A PARENT, and look into other children.

So, if you have only Labeled and Parent controls in your preferences tab, then it's all good.

But, in my case I've added Text control. (Don't ask me why, maybe I really shouldn't do it).

What change I propose: make 3 branches:

  1. If the child is Labeled: add it to prefsTabLabelMap.
  2. If it's a Parent: look into it's children.
  3. Otherwise, ignore

@InAnYan InAnYan changed the title scanLabelledControl logic issue scanLabeledControl logic issue Jun 3, 2024
@InAnYan
Copy link
Member Author

InAnYan commented Jun 3, 2024

I've made the changes and now the error disappeared.

I'm not really sure how to test this properly, but I'll make the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant