--- a/jdk/src/share/classes/com/sun/beans/TypeResolver.java Wed Jan 18 11:27:56 2012 -0800
+++ b/jdk/src/share/classes/com/sun/beans/TypeResolver.java Wed Jan 18 20:23:33 2012 -0800
@@ -154,7 +154,7 @@
* @see #resolve(Type)
*/
public static Type resolve(Type actual, Type formal) {
- return new TypeResolver(actual).resolve(formal);
+ return getTypeResolver(actual).resolve(formal);
}
/**
@@ -169,7 +169,7 @@
* @see #resolve(Type[])
*/
public static Type[] resolve(Type actual, Type[] formals) {
- return new TypeResolver(actual).resolve(formals);
+ return getTypeResolver(actual).resolve(formals);
}
/**
@@ -228,9 +228,20 @@
return classes;
}
+ public static TypeResolver getTypeResolver(Type type) {
+ synchronized (CACHE) {
+ TypeResolver resolver = CACHE.get(type);
+ if (resolver == null) {
+ resolver = new TypeResolver(type);
+ CACHE.put(type, resolver);
+ }
+ return resolver;
+ }
+ }
- private final Map<TypeVariable<?>, Type> map
- = new HashMap<TypeVariable<?>, Type>();
+ private static final WeakCache<Type, TypeResolver> CACHE = new WeakCache<>();
+
+ private final Map<TypeVariable<?>, Type> map = new HashMap<>();
/**
* Constructs the type resolver for the given actual type.
--- a/jdk/src/share/classes/java/awt/AWTKeyStroke.java Wed Jan 18 11:27:56 2012 -0800
+++ b/jdk/src/share/classes/java/awt/AWTKeyStroke.java Wed Jan 18 20:23:33 2012 -0800
@@ -802,8 +802,11 @@
*/
protected Object readResolve() throws java.io.ObjectStreamException {
synchronized (AWTKeyStroke.class) {
- return getCachedStroke(keyChar, keyCode, modifiers, onKeyRelease);
+ if (getClass().equals(getAWTKeyStrokeClass())) {
+ return getCachedStroke(keyChar, keyCode, modifiers, onKeyRelease);
+ }
}
+ return this;
}
private static int mapOldModifiers(int modifiers) {
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java Wed Jan 18 11:27:56 2012 -0800
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java Wed Jan 18 20:23:33 2012 -0800
@@ -1932,20 +1932,22 @@
else {
Rectangle beginRect = getPathBounds(tree, getPathForRow
(tree, beginRow));
- Rectangle visRect = tree.getVisibleRect();
- Rectangle testRect = beginRect;
- int beginY = beginRect.y;
- int maxY = beginY + visRect.height;
-
- for(int counter = beginRow + 1; counter <= endRow; counter++) {
- testRect = getPathBounds(tree,
- getPathForRow(tree, counter));
- if((testRect.y + testRect.height) > maxY)
- counter = endRow;
+ if (beginRect != null) {
+ Rectangle visRect = tree.getVisibleRect();
+ Rectangle testRect = beginRect;
+ int beginY = beginRect.y;
+ int maxY = beginY + visRect.height;
+
+ for(int counter = beginRow + 1; counter <= endRow; counter++) {
+ testRect = getPathBounds(tree,
+ getPathForRow(tree, counter));
+ if((testRect.y + testRect.height) > maxY)
+ counter = endRow;
+ }
+ tree.scrollRectToVisible(new Rectangle(visRect.x, beginY, 1,
+ testRect.y + testRect.height-
+ beginY));
}
- tree.scrollRectToVisible(new Rectangle(visRect.x, beginY, 1,
- testRect.y + testRect.height-
- beginY));
}
}
}
@@ -3485,7 +3487,7 @@
}
Rectangle bounds = getPathBounds(tree, path);
- if (y > (bounds.y + bounds.height)) {
+ if (bounds == null || y > (bounds.y + bounds.height)) {
return false;
}
--- a/jdk/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java Wed Jan 18 11:27:56 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java Wed Jan 18 20:23:33 2012 -0800
@@ -76,9 +76,12 @@
accessor.setFiles(fd, null, null);
} else {
// Fix 6987233: add the trailing slash if it's absent
- accessor.setDirectory(fd, directory +
- (directory.endsWith(File.separator) ?
- "" : File.separator));
+ String with_separator = directory;
+ if (directory != null) {
+ with_separator = directory.endsWith(File.separator) ?
+ directory : (directory + File.separator);
+ }
+ accessor.setDirectory(fd, with_separator);
accessor.setFile(fd, filenames[0]);
accessor.setFiles(fd, directory, filenames);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JSplitPane/4885629/bug4885629.java Wed Jan 18 20:23:33 2012 -0800
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2011, 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 4885629
+ * @summary With JSplitPane in VERTICAL_SPLIT, SplitPaneBorder draws bottom edge of divider
+ * @author Andrey Pikalev
+ */
+
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
+import javax.swing.plaf.basic.BasicBorders;
+import javax.swing.plaf.basic.BasicLookAndFeel;
+import javax.swing.plaf.basic.BasicSplitPaneUI;
+import java.awt.*;
+
+
+public class bug4885629 {
+
+ private static final Color darkShadow = new Color(100,120,200);
+ private static final Color darkHighlight = new Color(200,120,50);
+ private static final Color lightHighlight = darkHighlight.brighter();
+ private static final Color BGCOLOR = Color.blue;
+
+ private static JSplitPane sp;
+
+ public static void main(String[] args) throws Exception {
+ UIManager.setLookAndFeel(new BasicLookAndFeel() {
+ public boolean isSupportedLookAndFeel(){ return true; }
+ public boolean isNativeLookAndFeel(){ return false; }
+ public String getDescription() { return "Foo"; }
+ public String getID() { return "FooID"; }
+ public String getName() { return "FooName"; }
+ });
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ JFrame frame = new JFrame();
+
+ JComponent a = new JPanel();
+ a.setBackground(Color.white);
+ a.setMinimumSize(new Dimension(10, 10));
+
+ JComponent b = new JPanel();
+ b.setBackground(Color.white);
+ b.setMinimumSize(new Dimension(10, 10));
+
+ sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, a, b);
+ sp.setPreferredSize(new Dimension(20, 20));
+ sp.setBackground(BGCOLOR);
+
+ Border bo = new BasicBorders.SplitPaneBorder(lightHighlight,
+ Color.red);
+ Border ibo = new EmptyBorder(0, 0, 0, 0);
+ sp.setBorder(bo);
+ sp.setMinimumSize(new Dimension(200, 200));
+
+ ((BasicSplitPaneUI) sp.getUI()).getDivider().setBorder(ibo);
+
+ frame.getContentPane().setLayout(new FlowLayout());
+ frame.getContentPane().setBackground(darkShadow);
+ frame.getContentPane().add(sp);
+
+ frame.setSize(200, 200);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setVisible(true);
+ }
+ });
+
+ ((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
+
+ final Robot robot = new Robot();
+ robot.delay(1000);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ Rectangle rect = ((BasicSplitPaneUI) sp.getUI()).getDivider().getBounds();
+
+ Point p = rect.getLocation();
+
+ SwingUtilities.convertPointToScreen(p, sp);
+
+ for (int i = 0; i < rect.width; i++) {
+ if (!BGCOLOR.equals(robot.getPixelColor(p.x + i, p.y + rect.height - 1))) {
+ throw new Error("The divider's area has incorrect color.");
+ }
+ }
+ }
+ });
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTextArea/4697612/bug4697612.java Wed Jan 18 20:23:33 2012 -0800
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 4697612 6244705
+ * @author Peter Zhelezniakov
+ * @library ../../regtesthelpers
+ * @build Util
+ * @run main bug4697612
+ */
+import java.io.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+import javax.swing.text.BadLocationException;
+import sun.awt.SunToolkit;
+
+public class bug4697612 {
+
+ static final int FRAME_WIDTH = 300;
+ static final int FRAME_HEIGHT = 300;
+ static final int FONT_HEIGHT = 16;
+ private static volatile int frameHeight;
+ private static volatile int fontHeight;
+ private static JFrame frame;
+ private static JTextArea text;
+ private static JScrollPane scroller;
+
+ public static void main(String[] args) throws Throwable {
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+ Robot robot = new Robot();
+ robot.setAutoDelay(100);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+
+ toolkit.realSync();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ text.requestFocus();
+ }
+ });
+
+ toolkit.realSync();
+
+ // 4697612: pressing PgDn + PgUp should not alter caret position
+ Util.hitKeys(robot, KeyEvent.VK_HOME);
+ Util.hitKeys(robot, KeyEvent.VK_PAGE_DOWN);
+
+
+ int pos0 = getTextCaretPosition();
+ int caretHeight = getTextCaretHeight();
+ fontHeight = FONT_HEIGHT;
+
+ // iterate two times, for different (even and odd) font height
+ for (int i = 0; i < 2; i++) {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ public void run() {
+ text.setFont(text.getFont().deriveFont(fontHeight));
+ }
+ });
+
+ frameHeight = FRAME_HEIGHT;
+
+ for (int j = 0; j < caretHeight; j++) {
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ public void run() {
+ frame.setSize(FRAME_WIDTH, frameHeight);
+ }
+ });
+
+ toolkit.realSync();
+
+ Util.hitKeys(robot, KeyEvent.VK_PAGE_DOWN);
+ Util.hitKeys(robot, KeyEvent.VK_PAGE_UP);
+ toolkit.realSync();
+
+ int pos = getTextCaretPosition();
+ if (pos0 != pos) {
+ throw new RuntimeException("Failed 4697612: PgDn & PgUp keys scroll by different amounts");
+ }
+ frameHeight++;
+ }
+ fontHeight++;
+ }
+
+
+ // 6244705: pressing PgDn at the very bottom should not scroll
+ LookAndFeel laf = UIManager.getLookAndFeel();
+ if (laf.getID().equals("Aqua")) {
+ Util.hitKeys(robot, KeyEvent.VK_END);
+ } else {
+ Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_END);
+ }
+
+ toolkit.realSync();
+
+ pos0 = getScrollerViewPosition();
+ Util.hitKeys(robot, KeyEvent.VK_PAGE_DOWN);
+ toolkit.realSync();
+
+ int pos = getScrollerViewPosition();
+
+ if (pos0 != pos) {
+ throw new RuntimeException("Failed 6244705: PgDn at the bottom causes scrolling");
+ }
+ }
+
+ private static int getTextCaretPosition() throws Exception {
+ final int[] result = new int[1];
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ result[0] = text.getCaretPosition();
+ }
+ });
+
+ return result[0];
+ }
+
+ private static int getTextCaretHeight() throws Exception {
+ final int[] result = new int[1];
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ int pos0 = text.getCaretPosition();
+ Rectangle dotBounds = text.modelToView(pos0);
+ result[0] = dotBounds.height;
+ } catch (BadLocationException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ });
+
+ return result[0];
+ }
+
+ private static int getScrollerViewPosition() throws Exception {
+ final int[] result = new int[1];
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ result[0] = scroller.getViewport().getViewPosition().y;
+ }
+ });
+
+ return result[0];
+ }
+
+ private static void createAndShowGUI() {
+ frame = new JFrame();
+ frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ text = new JTextArea();
+ try {
+ InputStream is =
+ bug4697612.class.getResourceAsStream("bug4697612.txt");
+ text.read(new InputStreamReader(is), null);
+ } catch (IOException e) {
+ throw new Error(e);
+ }
+
+ scroller = new JScrollPane(text);
+
+ frame.getContentPane().add(scroller);
+
+ frame.pack();
+ frame.setVisible(true);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTextArea/4697612/bug4697612.txt Wed Jan 18 20:23:33 2012 -0800
@@ -0,0 +1,223 @@
+ README
+
+ Java(TM) 2 SDK, Standard Edition
+ Version 1.4.2 Beta
+
+ For a more extensive HTML version of this file, see README.html.
+
+Contents
+
+ * Introduction
+ * Release Notes
+ * Bug Reports and Feedback
+ * Java 2 SDK Documentation
+ * Redistribution
+ * Web Pages
+
+
+Introduction
+
+ Thank you for downloading this release of the Java(TM) 2 SDK,
+ Standard Edition. The Java 2 SDK is a development environment for
+ building applications, applets, and components that can be
+ deployed on the Java platform.
+
+ The Java 2 SDK software includes tools useful for developing and
+ testing programs written in the Java programming language and
+ running on the Java platform. These tools are designed to be used
+ from the command line. Except for appletviewer, these tools do not
+ provide a graphical user interface.
+
+
+Release Notes
+
+ See the Release Notes on the Java Software web site for additional
+ information pertaining to this release.
+
+ http://java.sun.com/j2se/1.4.2/relnotes.html
+
+ The on-line release notes will be updated as needed, so you should
+ check it occasionally for the latest information.
+
+
+Bug Reports and Feedback
+
+ The Bug Parade Web Page on the Java Developer Connection(SM) web
+ site lets you search for and examine existing bug reports, submit
+ your own bug reports, and tell us which bug fixes matter most to you.
+
+ http://java.sun.com/jdc/bugParade/
+
+ To directly submit a bug or request a feature, fill out this form:
+
+ http://java.sun.com/cgi-bin/bugreport.cgi
+
+ You can also send comments directly to Java Software engineering
+ team email addresses.
+
+ http://java.sun.com/mail/
+
+
+Java 2 SDK Documentation
+
+ The on-line Java 2 SDK Documentation contains API specifications,
+ feature descriptions, developer guides, tool reference pages, demos,
+ and links to related information. It is located at
+
+ http://java.sun.com/j2se/1.4.2/docs/
+
+ The Java 2 SDK documentation is also available in a download bundle
+ which you can install locally on your machine. See the
+ Java 2 SDK download page:
+
+ http://java.sun.com/j2se/1.4.2/download.html
+
+
+Redistribution
+
+ The term "vendors" used here refers to licensees, developers,
+ and independent software vendors (ISVs) who license and
+ distribute the Java 2 Runtime Environment with their programs.
+ Vendors must follow the terms of the Java 2 SDK, Standard
+ Edition, Binary Code License agreement.
+ Required vs. Optional Files
+
+ The files that make up the Java 2 SDK, Standard Edition, are
+ divided into two categories: required and optional. Optional
+ files may be excluded from redistributions of the Java 2 SDK
+ at the vendor's discretion. The following section contains a
+ list of the files and directories that may optionally be
+ omitted from redistributions of the Java 2 SDK. All files not
+ in these lists of optional files must be included in
+ redistributions of the Java 2 SDK.
+
+ Optional Files and Directories
+
+ The following files may be optionally excluded from
+ redistributions:
+
+ jre/lib/charsets.jar
+ Character conversion classes
+ jre/lib/ext/
+ sunjce_provider.jar - the SunJCE provider for Java
+ Cryptography APIs
+ localedata.jar - contains many of the resources
+ needed for non US English locales
+ ldapsec.jar - contains security features supported
+ by the LDAP service provider
+ dnsns.jar - for the InetAddress wrapper of JNDI DNS
+ provider
+ bin/rmid and jre/bin/rmid
+ Java RMI Activation System Daemon
+ bin/rmiregistry and jre/bin/rmiregistry
+ Java Remote Object Registry
+ bin/tnameserv and jre/bin/tnameserv
+ Java IDL Name Server
+ bin/keytool and jre/bin/keytool
+ Key and Certificate Management Tool
+ bin/kinit and jre/bin/kinit
+ Used to obtain and cache Kerberos ticket-granting tickets
+ bin/klist and jre/bin/klist
+ Kerberos display entries in credentials cache and keytab
+ bin/ktab and jre/bin/ktab
+ Kerberos key table manager
+ bin/policytool and jre/bin/policytool
+ Policy File Creation and Management Tool
+ bin/orbd and jre/bin/orbd
+ Object Request Broker Daemon
+ bin/servertool and jre/bin/servertool
+ Java IDL Server Tool
+ src.zip
+ Archive of source files
+
+ In addition, the Java Web Start product may be excluded from
+ redistributions. The Java Web Start product is contained in a
+ file named javaws-1_2-solaris-sparc-i.zip,
+ javaws-1_2-solaris-i586-i.zip,
+ javaws-1_2-linux-i586-i.zip, or
+ javaws-1_2-windows-i586-i.exe, depending on the platform.
+
+
+ Unlimited Strength Java Cryptography Extension
+
+ Due to import control restrictions for some countries, the
+ Java Cryptography Extension (JCE) policy files shipped with
+ the Java 2 SDK, Standard Edition and the Java 2 Runtime
+ Environment allow strong but limited cryptography to be
+ used. These files are located at
+
+ <java-home>/lib/security/local_policy.jar
+ <java-home>/lib/security/US_export_policy.jar
+
+ where <java-home> is the jre directory of the Java 2
+ SDK or the top-level directory of the Java 2 Runtime
+ Environment.
+
+ An unlimited strength version of these files indicating
+ no restrictions on cryptographic strengths is available
+ on the Java 2 SDK web site for those living in eligible
+ countries. Those living in eligible countries may download
+ the unlimited strength version and replace the strong
+ cryptography jar files with the unlimited strength files.
+
+
+ Endorsed Standards Override Mechanism
+
+ An endorsed standard is a Java API defined through a standards
+ process other than the Java Community Process(SM) (JCP(SM)).
+ Because endorsed standards are defined outside the JCP, it is
+ anticipated that such standards will be revised between
+ releases of the Java 2 Platform. In order to take advantage of
+ new revisions to endorsed standards, developers and software
+ vendors may use the Endorsed Standards Override Mechanism to
+ provide newer versions of an endorsed standard than those
+ included in the Java 2 Platform as released by Sun Microsystems.
+
+ For more information on the Endorsed Standards Override
+ Mechanism, including the list of platform packages that it may
+ be used to override, see
+
+ http://java.sun.com/j2se/1.4.2/docs/guide/standards/
+
+ Classes in the packages listed on that web page may be replaced
+ only by classes implementing a more recent version of the API
+ as defined by the appropriate standards body.
+
+ In addition to the packages listed in the document at the above
+ URL, which are part of the Java 2 Platform, Standard Edition
+ (J2SE(TM)) specification, redistributors of Sun's J2SE
+ Reference Implementation are allowed to override classes whose
+ sole purpose is to implement the functionality provided by
+ public APIs defined in these Endorsed Standards packages.
+ Redistributors may also override classes in the org.w3c.dom.*
+ packages, or other classes whose sole purpose is to implement
+ these APIs.
+
+
+Sun Java Web Pages
+
+ For additional information, refer to these Sun Microsystems pages
+ on the World Wide Web:
+
+ http://java.sun.com/
+ The Java Software web site, with the latest information on
+ Java technology, product information, news, and features.
+ http://java.sun.com/docs
+ Java Platform Documentation provides access to white papers,
+ the Java Tutorial and other documents.
+ http://java.sun.com/jdc
+ The Java Developer Connection(SM) web site. (Free registration
+ required.) Additional technical information, news, and
+ features; user forums; support information, and much more.
+ http://java.sun.com/products/
+ Java Technology Products & API
+
+
+------------------------------------------------------------------------
+The Java 2 SDK, Standard Edition, is a product of Sun Microsystems(TM),
+Inc. This product includes code licensed from RSA Security.
+
+Copyright 2003 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+California 95054, U.S.A. All rights reserved.
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTree/6505523/bug6505523.java Wed Jan 18 20:23:33 2012 -0800
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 6505523
+ * @summary NullPointerException in BasicTreeUI when a node is removed by expansion listener
+ * @author Alexandr Scherbatiy
+ * @run main bug6505523
+ */
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.event.InputEvent;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeExpansionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+import sun.awt.SunToolkit;
+
+public class bug6505523 {
+
+ private static JTree tree;
+
+ public static void main(String[] args) throws Exception {
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+ Robot robot = new Robot();
+ robot.setAutoDelay(50);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+
+ toolkit.realSync();
+
+ Point point = getRowPointToClick(2);
+ robot.mouseMove(point.x, point.y);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ toolkit.realSync();
+
+ }
+
+ private static Point getRowPointToClick(final int row) throws Exception {
+
+ final Point[] result = new Point[1];
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+
+ @Override
+ public void run() {
+ Rectangle rect = tree.getRowBounds(row);
+ Point point = new Point(rect.x - 5, rect.y + rect.height / 2);
+ SwingUtilities.convertPointToScreen(point, tree);
+ result[0] = point;
+ }
+ });
+
+ return result[0];
+ }
+
+ private static void createAndShowGUI() {
+ final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Problem with NPE under JDK 1.6");
+ final DefaultMutableTreeNode problematic = new DefaultMutableTreeNode("Expand me and behold a NPE in stderr");
+ problematic.add(new DefaultMutableTreeNode("some content"));
+ root.add(new DefaultMutableTreeNode("irrelevant..."));
+ root.add(problematic);
+
+ final DefaultTreeModel model = new DefaultTreeModel(root);
+ tree = new JTree(model);
+ tree.setRootVisible(true);
+ tree.setShowsRootHandles(true);
+ tree.expandRow(0);
+ tree.collapseRow(2);
+
+ // this is critical - without dragEnabled everything works
+ tree.setDragEnabled(true);
+
+ tree.addTreeExpansionListener(new TreeExpansionListener() {
+
+ @Override
+ public void treeExpanded(TreeExpansionEvent event) {
+ TreeNode parent = problematic.getParent();
+ if (parent instanceof DefaultMutableTreeNode) {
+ model.removeNodeFromParent(problematic);
+ }
+ }
+
+ @Override
+ public void treeCollapsed(TreeExpansionEvent event) {
+ }
+ });
+
+ JFrame frame = new JFrame("JTree Problem");
+ frame.add(new JScrollPane(tree));
+ frame.setSize(500, 300);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file