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 8048887 27 @summary Tests SortingFTP for an exception caused by the tim-sort algo. 28 @author anton.tarasov: area=awt.focus 29 @run main JDK8040632 30 */ 31 32 import javax.swing.JFrame; 33 import javax.swing.JPanel; 34 import javax.swing.SwingUtilities; 35 import java.awt.Dimension; 36 import java.awt.Color; 37 import java.awt.GridBagLayout; 38 import java.awt.GridBagConstraints; 39 import java.awt.event.WindowAdapter; 40 import java.awt.event.WindowEvent; 41 import java.util.concurrent.CountDownLatch; 42 import java.util.concurrent.TimeUnit; 43 44 public class JDK8048887 { 45 46 static volatile boolean passed = true; 47 48 public static void main(String[] args) { 49 JDK8048887 app = new JDK8048887(); 50 app.start(); 51 } 52 53 public void start() { 54 final CountDownLatch latch = new CountDownLatch(1); 55 56 SwingUtilities.invokeLater(() -> { 57 // Catch the original exception which sounds like: 58 // java.lang.IllegalArgumentException: Comparison method violates its general contract! 59 Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { 60 public void uncaughtException(Thread t, Throwable e) { 61 e.printStackTrace(); 62 if (e instanceof IllegalArgumentException) { 63 passed = false; 64 latch.countDown(); 65 } 66 } 67 }); 68 69 TestDialog d = new TestDialog(); 70 // It's expected that the dialog is focused on start. 71 // The listener is called after the FTP completes processing and the bug is reproduced or not. 72 d.addWindowFocusListener(new WindowAdapter() { 73 public void windowGainedFocus(WindowEvent e) { 74 latch.countDown(); 75 } 76 }); 77 d.setVisible(true); 78 }); 79 80 try { 81 latch.await(5, TimeUnit.SECONDS); 82 } catch (InterruptedException e) { 83 e.printStackTrace(); 84 } 85 86 if (passed) 87 System.out.println("Test passed."); 88 else 89 throw new RuntimeException("Test failed!"); 90 } 91 } 92 93 class TestDialog extends JFrame { 94 95 // The layout of the components reproduces the transitivity issue 96 // with SortingFocusTraversalPolicy relying on the tim-sort algo. 97 | 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 8048887 27 @summary Tests SortingFTP for an exception caused by the tim-sort algo. 28 @author anton.tarasov: area=awt.focus 29 @run main JDK8048887 30 */ 31 32 import javax.swing.JFrame; 33 import javax.swing.JPanel; 34 import javax.swing.SwingUtilities; 35 import java.awt.Dimension; 36 import java.awt.Color; 37 import java.awt.GridBagLayout; 38 import java.awt.GridBagConstraints; 39 import java.awt.event.WindowAdapter; 40 import java.awt.event.WindowEvent; 41 import java.util.concurrent.CountDownLatch; 42 import java.util.concurrent.TimeUnit; 43 44 public class JDK8048887 { 45 46 static volatile boolean passed = true; 47 48 public static void main(String[] args) { 49 JDK8048887 app = new JDK8048887(); 50 app.start(); 51 } 52 53 public void start() { 54 final CountDownLatch latch = new CountDownLatch(1); 55 56 SwingUtilities.invokeLater(new Runnable(){ 57 @Override 58 public void run(){ 59 // Catch the original exception which sounds like: 60 // java.lang.IllegalArgumentException: Comparison method violates its general contract! 61 62 Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { 63 public void uncaughtException(Thread t, Throwable e) { 64 e.printStackTrace(); 65 if (e instanceof IllegalArgumentException) { 66 passed = false; 67 latch.countDown(); 68 } 69 } 70 }); 71 72 TestDialog d = new TestDialog(); 73 // It's expected that the dialog is focused on start. 74 // The listener is called after the FTP completes processing and the bug is reproduced or not. 75 d.addWindowFocusListener(new WindowAdapter() { 76 public void windowGainedFocus(WindowEvent e) { 77 latch.countDown(); 78 } 79 }); 80 d.setVisible(true); 81 82 83 } 84 }); 85 86 try { 87 latch.await(5, TimeUnit.SECONDS); 88 } catch (InterruptedException e) { 89 e.printStackTrace(); 90 } 91 92 if (passed) 93 System.out.println("Test passed."); 94 else 95 throw new RuntimeException("Test failed!"); 96 } 97 } 98 99 class TestDialog extends JFrame { 100 101 // The layout of the components reproduces the transitivity issue 102 // with SortingFocusTraversalPolicy relying on the tim-sort algo. 103 |