Path: blob/master/test/jdk/javax/swing/JEditorPane/8146319/JEditorPaneTest.java
58462 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 814631927* @summary JEditorPane function setPage leaves a file lock28* @run main JEditorPaneTest29*/30import java.awt.Robot;31import java.io.BufferedWriter;32import java.io.File;33import java.io.FileWriter;34import java.io.IOException;35import javax.swing.JEditorPane;36import javax.swing.SwingUtilities;3738public class JEditorPaneTest {3940public static void main(String[] args) throws Exception {41Robot robot = new Robot();42try {43File file = File.createTempFile("Temp_", ".txt");44file.deleteOnExit();45writeFile(file);46SwingUtilities.invokeAndWait(new Runnable() {47@Override48public void run() {49JEditorPane editorPane = new JEditorPane();50try {51editorPane.setPage(file.toURI().toURL());52} catch (IOException ex) {53file.delete();54throw new RuntimeException("Test Failed" + ex);55}56}57});58robot.waitForIdle();59if (!file.renameTo(file)) {60file.delete();61throw new RuntimeException("Test Failed");62}63} catch (IOException ex) {64throw new RuntimeException("Failed to create File" + ex);65}66}6768private static void writeFile(File file) {69FileWriter fw = null;70try {71fw = new FileWriter(file.getAbsoluteFile());72BufferedWriter bw = new BufferedWriter(fw);73bw.write("Test Text");74bw.close();75} catch (IOException ex) {76throw new RuntimeException("Failed to write File" + ex);77}7879}80}818283