1 /* 2 * Copyright (c) 2011, 2019, 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 import java.awt.Color; 25 import java.awt.SystemColor; 26 27 /** 28 * @test 29 * @bug 4559156 30 * @summary java.awt.Color.equals() does not work when comparing to 31 * java.awt.SystemColor 32 */ 33 public final class EqualityTest { 34 35 private final static SystemColor [] colorArray = { 36 SystemColor.desktop, 37 SystemColor.activeCaption, 38 SystemColor.activeCaptionText, 39 SystemColor.activeCaptionBorder, 40 SystemColor.inactiveCaption, 41 SystemColor.inactiveCaptionText, 42 SystemColor.inactiveCaptionBorder, 43 SystemColor.window, 44 SystemColor.windowBorder, 45 SystemColor.windowText, 46 SystemColor.menu, 47 SystemColor.menuText, 48 SystemColor.text, 49 SystemColor.textText, 50 SystemColor.textHighlight, 51 SystemColor.textHighlightText, 52 SystemColor.textInactiveText, 53 SystemColor.control, 54 SystemColor.controlText, 55 SystemColor.controlHighlight, 56 SystemColor.controlLtHighlight, 57 SystemColor.controlShadow, 58 SystemColor.controlDkShadow, 59 SystemColor.scrollbar, 60 SystemColor.info, 61 SystemColor.infoText 62 }; 63 main(final String[] str)64 public static void main(final String[] str) { 65 for (final SystemColor system : colorArray) { 66 Color color = new Color(system.getRGB(), system.getAlpha() < 255); 67 System.out.printf("System color = %s = [%d]: color = %s [%d]%n", 68 system, system.getRGB(), color, color.getRGB()); 69 boolean equalityStatement1 = color.equals(system); 70 boolean equalityStatement2 = system.equals(color); 71 if (!equalityStatement1 || !equalityStatement2) { 72 System.out.println("COLOR.equals(SC) = " + equalityStatement1); 73 System.out.println("SC.equals(COLOR) = " + equalityStatement2); 74 throw new RuntimeException("The equals() method doesn't work correctly"); 75 } 76 } 77 } 78 } 79