changeset 2188:7a8bd0b6f190

RT-26449 Throws RuntimeException when root was set prior loading fxml file.
author tb115823 <Tomas.Brandalik@oracle.com>
date Wed, 09 Jan 2013 14:51:52 +0100
parents 38fdf8162e78
children 9b32f08b395a
files javafx-fxml/src/javafx/fxml/FXMLLoader.java javafx-fxml/test/javafx/fxml/RT_26449Test.java javafx-fxml/test/javafx/fxml/rt_26449.fxml
diffstat 3 files changed, 71 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-fxml/src/javafx/fxml/FXMLLoader.java	Tue Jan 08 13:51:57 2013 -0800
+++ b/javafx-fxml/src/javafx/fxml/FXMLLoader.java	Wed Jan 09 14:51:52 2013 +0100
@@ -1087,20 +1087,10 @@
             if (type == null) {
                 throw new LoadException(this.type + " is not a valid type.");
             }
-
+            
             Object value;
             if (root == null) {
-                value = (builderFactory == null) ? null : builderFactory.getBuilder(type);
-
-                if (value == null) {
-                    try {
-                        value = type.newInstance();
-                    } catch (InstantiationException exception) {
-                        throw new LoadException(exception);
-                    } catch (IllegalAccessException exception) {
-                        throw new LoadException(exception);
-                    }
-                }
+                throw new LoadException("Root hasn't been set. Use method setRoot() before load.");                        
             } else {
                 if (!type.isAssignableFrom(root.getClass())) {
                     throw new LoadException("Root is not an instance of "
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-fxml/test/javafx/fxml/RT_26449Test.java	Wed Jan 09 14:51:52 2013 +0100
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javafx.fxml;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class RT_26449Test {
+    @Test(expected=LoadException.class)
+    public void testRootNotSet() throws IOException {
+        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("rt_26449.fxml"));
+        fxmlLoader.load();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-fxml/test/javafx/fxml/rt_26449.fxml	Wed Jan 09 14:51:52 2013 +0100
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+This code is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.  Oracle designates this
+particular file as subject to the "Classpath" exception as provided
+by Oracle in the LICENSE file that accompanied this code.
+
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+-->
+
+<?import javafx.scene.control.*?>
+
+<fx:root type="javafx.scene.layout.VBox" fx:id="default_root" xmlns:fx="http://javafx.com/fxml">
+    <Label text="Label in VBox"/>
+</fx:root>