roskenet/springboot-javafx-support

View cannot be loaded if the name is only 'View'

Opened this issue · 1 comments

While writing a One Page JavaFX application, I noticed that a View named 'View' can not be loaded. The application then crashes with a IllegalStateException.

Stacktrace:

java.lang.IllegalStateException: Cannot load 
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:161) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.ensureFxmlLoaderInitialized(AbstractFxmlView.java:176) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.getView(AbstractFxmlView.java:188) ~[springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showView(AbstractJavaFxApplicationSupport.java:202) [springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.showInitialView(AbstractJavaFxApplicationSupport.java:177) [springboot-javafx-support-1.4.0.jar:na]
	at de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport.lambda$start$4(AbstractJavaFxApplicationSupport.java:144) [springboot-javafx-support-1.4.0.jar:na]
	at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) ~[jfxrt.jar:na]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_131]
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) ~[jfxrt.jar:na]
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) ~[jfxrt.jar:na]
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) ~[jfxrt.jar:na]
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) ~[jfxrt.jar:na]
	at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_131]
Caused by: java.lang.IllegalStateException: Location is not set.
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) ~[jfxrt.jar:na]
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) ~[jfxrt.jar:na]
	at de.felixroske.jfxsupport.AbstractFxmlView.loadSynchronously(AbstractFxmlView.java:159) ~[springboot-javafx-support-1.4.0.jar:na]
	... 12 common frames omitted

Cause:
The AbstractFxmlView tries to resolve the fxml path by itself if its not set by the annotation and thereby cuts 'View' out of the path. The path of a view called 'View' then will point to the parent directory.

private static String stripEnding(final String clazz) {

	if (!clazz.endsWith("view")) {
		return clazz;
	}

	return clazz.substring(0, clazz.lastIndexOf("view"));
}

This is true.
Will add a check, that the resulting substring should never be stripped down until it's empty.