-
Notifications
You must be signed in to change notification settings - Fork 221
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
When loading of FXML file fails, in some cases the error is not shown to the user #403
Changes from 2 commits
9082abd
f6d2a68
5dbfb50
0a862e5
4a71738
a46ca9f
974ee34
b47bc49
0f173a8
0d6789e
656f1f5
812c4bd
a548ba3
c9673f1
6b3e9d1
e5c304b
af9f842
acccc10
70468ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2017 Gluon and/or its affiliates. | ||
* Copyright (c) 2017, 2021, Gluon and/or its affiliates. | ||
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. | ||
* All rights reserved. Use is subject to license terms. | ||
* | ||
|
@@ -95,10 +95,27 @@ public void load(String fxmlText) throws java.io.IOException { | |
is.reset(); | ||
setSceneGraphRoot(fxmlLoader.load(is)); | ||
} catch (RuntimeException | IOException x) { | ||
if (x.getCause().getClass() == XMLStreamException.class) { | ||
handleUnsupportedCharset(x); | ||
} else | ||
throw new IOException(x); | ||
handleFxmlLoadingError(x); | ||
} | ||
} | ||
|
||
private void handleFxmlLoadingError(Exception x) throws IOException { | ||
if (x.getCause() != null) { | ||
handleKnownCauses(x); | ||
} else { | ||
handleUnknownAndMissingCauses(x); | ||
} | ||
} | ||
|
||
private void handleUnknownAndMissingCauses(Exception x) throws IOException { | ||
throw new IOException(x); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume throwing this is fine as it will be caught by the SB general exception handler? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is handled in a proper way. The issue is shown to the user and a dump of the FXML file into a temp dir is performed. There is a proper exception handling downstream. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
|
||
private void handleKnownCauses(Exception x) throws IOException { | ||
if (x.getCause().getClass() == XMLStreamException.class) { | ||
handleUnsupportedCharset(x); | ||
} else { | ||
handleUnknownAndMissingCauses(x); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2021, Gluon and/or its affiliates. | ||
* All rights reserved. Use is subject to license terms. | ||
* | ||
* This file is available and licensed under the following license: | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the distribution. | ||
* - Neither the name of Oracle Corporation and Gluon nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.oracle.javafx.scenebuilder.kit.fxom; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import org.junit.Test; | ||
|
||
public class FXOMDocumentTest { | ||
@Test | ||
public void that_IOexception_is_thrown_in_case_FXMLLoader_error() throws Exception { | ||
URL resource = getClass().getResource("BrokenByUserData.fxml"); | ||
String fxmlText = FXOMDocument.readContentFromURL(resource); | ||
Throwable t = assertThrows(IOException.class, () -> new FXOMDocument(fxmlText, resource, null, null)); | ||
String message = t.getMessage(); | ||
assertTrue(message.startsWith("javafx.fxml.LoadException:")); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a few more test cases to assert both known and unknown causes when loading a FXML? May be also assert a case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, of course. This is a good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Oliver-Loeffler, Are you going to add some more test cases to move this PR forward? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there will be an update with more tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @abhinayagarwal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also now a case for a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abhinayagarwal Eventually it worked and now I have a case where the XMLStreamException is provoked and handled. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.TableColumn?> | ||
<?import javafx.scene.control.TableView?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.VBox?> | ||
|
||
<VBox prefWidth="940.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.a2l.extenso.kitdev.controllers.MethodFilesController"> | ||
Oliver-Loeffler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<userData> | ||
<fx:reference source="controller"/> | ||
</userData> | ||
<children> | ||
<HBox spacing="7.0"> | ||
<children> | ||
<Button fx:id="importButton" mnemonicParsing="false" onAction="#onImport" text="Import methods" /> | ||
<Button fx:id="exportButton" mnemonicParsing="false" onAction="#onExport" text="Export selection" /> | ||
<Button fx:id="analysisButton" mnemonicParsing="false" onAction="#onAnalysis" text="Use method for analysis" /> | ||
<Button fx:id="deleteButton" mnemonicParsing="false" onAction="#onDelete" text="Delete selected methods" /> | ||
</children> | ||
<opaqueInsets> | ||
<Insets /> | ||
</opaqueInsets> | ||
<padding> | ||
<Insets bottom="7.0" left="7.0" right="7.0" top="7.0" /> | ||
</padding> | ||
</HBox> | ||
<TableView fx:id="tableView" minWidth="700.0" VBox.vgrow="ALWAYS"> | ||
<columns> | ||
<TableColumn fx:id="kitId" editable="false" prefWidth="178.0" text="Kit ID" /> | ||
<TableColumn fx:id="methodId" editable="false" prefWidth="164.0" text="Method ID" /> | ||
<TableColumn fx:id="revision" editable="false" prefWidth="148.0" text="Revision" /> | ||
</columns> | ||
</TableView> | ||
</children> | ||
</VBox> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to use
Exception
superclass here, i.e. whyRuntime
andIO
only?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point, yes, you are absolutely right. This a leftover from searching what was happening. Catching any kind of exception is a better solution here. The map where exceptions are collected in is already suitable for all types of exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wish to update this, happy to wait. Otherwise, it looks good to go.