|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4178276 |
| 27 | + * @key headful |
| 28 | + * @summary RTFEditorkit.write(...) doesn't throw NPE when used in SecurityManager |
| 29 | + * @run main/othervm/secure=allow bug4178276 |
| 30 | + */ |
| 31 | + |
| 32 | +import java.io.ByteArrayInputStream; |
| 33 | +import java.io.ByteArrayOutputStream; |
| 34 | +import java.nio.charset.StandardCharsets; |
| 35 | +import javax.swing.text.Document; |
| 36 | +import javax.swing.text.rtf.RTFEditorKit; |
| 37 | + |
| 38 | +public class bug4178276 { |
| 39 | + |
| 40 | + public static void main(String[] argv) throws Exception { |
| 41 | + System.setSecurityManager(new SecurityManager()); |
| 42 | + |
| 43 | + String test="{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\f swiss MS Sans Serif;}}{\\colortbl\\red0\\green0\\blue0;}\\qc\\plain\\f0 Test 1 \\par \\ql\\plain\\f0 Test 2 \\par \\qr\\plain\\f0 Test 3 \\par \\qj\\plain\\f0 Test 4}"; |
| 44 | + RTFEditorKit c = new RTFEditorKit(); |
| 45 | + Document doc = c.createDefaultDocument(); |
| 46 | + try { |
| 47 | + c.read(new ByteArrayInputStream(test.getBytes( |
| 48 | + StandardCharsets.ISO_8859_1)), doc, 0); |
| 49 | + ByteArrayOutputStream sw = new ByteArrayOutputStream(); |
| 50 | + c.write(sw, doc, 0, 0); |
| 51 | + } catch (Exception e) { |
| 52 | + throw new RuntimeException("Unexpected NPE exception...", e); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments