Path: blob/master/test/jdk/javax/swing/JEditorPane/8158734/bug8158734.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/* @test24@bug 815873425@summary JEditorPane.createEditorKitForContentType throws NPE after 688255926@author Mikhail Cherkasov27@run main bug815873428*/2930import javax.swing.*;31import javax.swing.text.*;32import java.io.*;33import java.lang.reflect.InvocationTargetException;343536public class bug8158734 {3738public static final String TYPE = "test/test";39public static final String TYPE_2 = "test2/test2";4041static boolean myClassloaderWasUsed = false;4243static class MyEditorKit extends EditorKit {44@Override45public String getContentType() {46return null;47}4849@Override50public ViewFactory getViewFactory() {51return null;52}5354@Override55public Action[] getActions() {56return new Action[0];57}5859@Override60public Caret createCaret() {61return null;62}6364@Override65public Document createDefaultDocument() {66return null;67}6869@Override70public void read(InputStream in, Document doc, int pos) throws IOException, BadLocationException {71}7273@Override74public void write(OutputStream out, Document doc, int pos, int len) throws IOException, BadLocationException {7576}7778@Override79public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {80}8182@Override83public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {84}85}8687static class MyClassloader extends ClassLoader {88@Override89public Class<?> loadClass(String name) throws ClassNotFoundException {90myClassloaderWasUsed = true;91return super.loadClass(name);92}93}9495public static void main(String[] args) throws InvocationTargetException, InterruptedException {96SwingUtilities.invokeAndWait(new Runnable() {97@Override98public void run() {99JEditorPane c = new JEditorPane();100c.setContentType(TYPE);101102final MyClassloader loader = new MyClassloader();103JEditorPane.registerEditorKitForContentType(TYPE_2, MyEditorKit.class.getName(), loader);104JEditorPane.registerEditorKitForContentType(TYPE_2, MyEditorKit.class.getName(), null);105JEditorPane.createEditorKitForContentType(TYPE_2);106107if (myClassloaderWasUsed) {108throw new RuntimeException("Class loader has not been removed for '" + TYPE_2 + "' type");109}110}111});112113}114}115116