diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/src/javafx/fxml/FXMLLoader.java --- a/javafx-fxml/src/javafx/fxml/FXMLLoader.java Thu Nov 29 12:27:40 2012 +0100 +++ b/javafx-fxml/src/javafx/fxml/FXMLLoader.java Thu Nov 29 12:28:39 2012 +0100 @@ -915,6 +915,15 @@ FXMLLoader fxmlLoader = new FXMLLoader(location, resources, builderFactory, controllerFactory, charset, loaders); + fxmlLoader.parentLoader = FXMLLoader.this; + + if (isCyclic(FXMLLoader.this, fxmlLoader)) { + throw new IOException( + String.format( + "Including \"%s\" in \"%s\" created cyclic reference.", + fxmlLoader.location.toExternalForm(), + FXMLLoader.this.location.toExternalForm())); + } fxmlLoader.setClassLoader(classLoader); fxmlLoader.setStaticLoad(staticLoad); @@ -1566,6 +1575,8 @@ private ClassLoader classLoader = defaultClassLoader; private boolean staticLoad = false; private LoadListener loadListener = null; + + private FXMLLoader parentLoader; private XMLStreamReader xmlStreamReader = null; private Element current = null; @@ -1809,6 +1820,28 @@ this.root = root; } + @Override + public boolean equals(Object obj) { + if (obj instanceof FXMLLoader) { + FXMLLoader loader = (FXMLLoader)obj; + return loader.location.toExternalForm().equals( + location.toExternalForm()); + } + return false; + } + + private boolean isCyclic( + FXMLLoader currentLoader, + FXMLLoader node) { + if (currentLoader == null) { + return false; + } + if (currentLoader.equals(node)) { + return true; + } + return isCyclic(currentLoader.parentLoader, node); + } + /** * Returns the controller associated with the root object. */ diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/RT_25494_Cycle_DetectionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/RT_25494_Cycle_DetectionTest.java Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,47 @@ +/* + * 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_25494_Cycle_DetectionTest { + + @Test(expected=IOException.class) + public void test_dummy_cycle() throws Exception { + FXMLLoader.load(RT_25494_Cycle_DetectionTest.class.getResource("dummy-cycle.fxml")); + } + + @Test(expected=IOException.class) + public void test_one_2_one_cycle() throws Exception { + FXMLLoader.load(RT_25494_Cycle_DetectionTest.class.getResource("one-2-one-cycle.fxml")); + } + + @Test(expected=IOException.class) + public void test_cycle() throws Exception { + FXMLLoader.load(RT_25494_Cycle_DetectionTest.class.getResource("cycle.fxml")); + } +} diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/cycle.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/cycle.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/dummy-cycle.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/dummy-cycle.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/leaf1.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/leaf1.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/leaf2.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/leaf2.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/leaf3.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/leaf3.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,35 @@ + + + + + + + + + + + + diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/leaf4.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/leaf4.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,34 @@ + + + + + + + + + + + diff -r 99e8153aadac -r 3bc0d0e01ed0 javafx-fxml/test/javafx/fxml/one-2-one-cycle.fxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javafx-fxml/test/javafx/fxml/one-2-one-cycle.fxml Thu Nov 29 12:28:39 2012 +0100 @@ -0,0 +1,37 @@ + + + + + + + + + + + + + +