diff --git a/make/src/classes/build/tools/generatecurrencydata/GenerateCurrencyData.java b/make/src/classes/build/tools/generatecurrencydata/GenerateCurrencyData.java index ca1271e68515fb9df6cba945f777298bbf8a641d..d424bc1494b108514e8235ce6b8ad329e4884d1d 100644 --- a/make/src/classes/build/tools/generatecurrencydata/GenerateCurrencyData.java +++ b/make/src/classes/build/tools/generatecurrencydata/GenerateCurrencyData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2015, 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 @@ -72,10 +72,6 @@ public class GenerateCurrencyData { private static String formatVersion; private static String dataVersion; private static String validCurrencyCodes; - private static String currenciesWith0MinorUnitDecimals; - private static String currenciesWith1MinorUnitDecimal; - private static String currenciesWith3MinorUnitDecimal; - private static String currenciesWithMinorUnitsUndefined; // handy constants - must match definitions in java.util.Currency // magic number @@ -83,29 +79,31 @@ public class GenerateCurrencyData { // number of characters from A to Z private static final int A_TO_Z = ('Z' - 'A') + 1; // entry for invalid country codes - private static final int INVALID_COUNTRY_ENTRY = 0x007F; + private static final int INVALID_COUNTRY_ENTRY = 0x0000007F; // entry for countries without currency - private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x0080; + private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x00000200; // mask for simple case country entries - private static final int SIMPLE_CASE_COUNTRY_MASK = 0x0000; + private static final int SIMPLE_CASE_COUNTRY_MASK = 0x00000000; // mask for simple case country entry final character - private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x001F; + private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x0000001F; // mask for simple case country entry default currency digits - private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x0060; + private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x000001E0; // shift count for simple case country entry default currency digits private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT = 5; + // maximum number for simple case country entry default currency digits + private static final int SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS = 9; // mask for special case country entries - private static final int SPECIAL_CASE_COUNTRY_MASK = 0x0080; + private static final int SPECIAL_CASE_COUNTRY_MASK = 0x00000200; // mask for special case country index - private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x001F; + private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x0000001F; // delta from entry index component in main table to index into special case tables private static final int SPECIAL_CASE_COUNTRY_INDEX_DELTA = 1; // mask for distinguishing simple and special case countries private static final int COUNTRY_TYPE_MASK = SIMPLE_CASE_COUNTRY_MASK | SPECIAL_CASE_COUNTRY_MASK; // mask for the numeric code of the currency - private static final int NUMERIC_CODE_MASK = 0x0003FF00; + private static final int NUMERIC_CODE_MASK = 0x000FFC00; // shift count for the numeric code of the currency - private static final int NUMERIC_CODE_SHIFT = 8; + private static final int NUMERIC_CODE_SHIFT = 10; // generated data private static int[] mainTable = new int[A_TO_Z * A_TO_Z]; @@ -120,7 +118,7 @@ public class GenerateCurrencyData { private static int[] specialCaseOldCurrenciesNumericCode = new int[maxSpecialCases]; private static int[] specialCaseNewCurrenciesNumericCode = new int[maxSpecialCases]; - private static final int maxOtherCurrencies = 70; + private static final int maxOtherCurrencies = 128; private static int otherCurrenciesCount = 0; private static StringBuffer otherCurrencies = new StringBuffer(); private static int[] otherCurrenciesDefaultFractionDigits = new int[maxOtherCurrencies]; @@ -129,6 +127,11 @@ public class GenerateCurrencyData { // date format for parsing cut-over times private static SimpleDateFormat format; + // Minor Units + private static String[] currenciesWithDefinedMinorUnitDecimals = + new String[SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS + 1]; + private static String currenciesWithMinorUnitsUndefined; + public static void main(String[] args) { // Look for "-o outputfilename" option @@ -171,16 +174,14 @@ public class GenerateCurrencyData { formatVersion = (String) currencyData.get("formatVersion"); dataVersion = (String) currencyData.get("dataVersion"); validCurrencyCodes = (String) currencyData.get("all"); - currenciesWith0MinorUnitDecimals = (String) currencyData.get("minor0"); - currenciesWith1MinorUnitDecimal = (String) currencyData.get("minor1"); - currenciesWith3MinorUnitDecimal = (String) currencyData.get("minor3"); + for (int i = 0; i <= SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS; i++) { + currenciesWithDefinedMinorUnitDecimals[i] + = (String) currencyData.get("minor"+i); + } currenciesWithMinorUnitsUndefined = (String) currencyData.get("minorUndefined"); if (formatVersion == null || dataVersion == null || validCurrencyCodes == null || - currenciesWith0MinorUnitDecimals == null || - currenciesWith1MinorUnitDecimal == null || - currenciesWith3MinorUnitDecimal == null || currenciesWithMinorUnitsUndefined == null) { throw new NullPointerException("not all required data is defined in input"); } @@ -207,7 +208,7 @@ public class GenerateCurrencyData { if (currencyInfo.charAt(0) == firstChar && currencyInfo.charAt(1) == secondChar) { checkCurrencyCode(currencyInfo); int digits = getDefaultFractionDigits(currencyInfo); - if (digits < 0 || digits > 3) { + if (digits < 0 || digits > SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS) { throw new RuntimeException("fraction digits out of range for " + currencyInfo); } int numericCode= getNumericCode(currencyInfo); @@ -231,13 +232,14 @@ public class GenerateCurrencyData { } private static int getDefaultFractionDigits(String currencyCode) { - if (currenciesWith0MinorUnitDecimals.indexOf(currencyCode) != -1) { - return 0; - } else if (currenciesWith1MinorUnitDecimal.indexOf(currencyCode) != -1) { - return 1; - } else if (currenciesWith3MinorUnitDecimal.indexOf(currencyCode) != -1) { - return 3; - } else if (currenciesWithMinorUnitsUndefined.indexOf(currencyCode) != -1) { + for (int i = 0; i <= SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS; i++) { + if (currenciesWithDefinedMinorUnitDecimals[i] != null && + currenciesWithDefinedMinorUnitDecimals[i].indexOf(currencyCode) != -1) { + return i; + } + } + + if (currenciesWithMinorUnitsUndefined.indexOf(currencyCode) != -1) { return -1; } else { return 2; diff --git a/src/macosx/classes/com/apple/laf/AquaBorder.java b/src/macosx/classes/com/apple/laf/AquaBorder.java index dfb6fddd5ce30b397b11d9467810a752134a8336..dcc645f8a690ff5d92a91dd40d4992dbc7b2a4e4 100644 --- a/src/macosx/classes/com/apple/laf/AquaBorder.java +++ b/src/macosx/classes/com/apple/laf/AquaBorder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -68,8 +68,9 @@ public abstract class AquaBorder implements Border, UIResource { painter.state.set(size); } + @Override public Insets getBorderInsets(final Component c) { - return sizeVariant.margins; + return (Insets) sizeVariant.margins.clone(); } protected AquaBorder deriveBorderForSize(final Size size) { @@ -130,8 +131,10 @@ public abstract class AquaBorder implements Border, UIResource { return (focusable != null && focusable instanceof JComponent && ((JComponent)focusable).hasFocus()); } + @Override public boolean isBorderOpaque() { return false; } + @Override public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) { painter.paint(g, c, x, y, w, h); } diff --git a/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java b/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java index d847bd7ca95e9412de171ffaf808396f00ac08a0..6c4ee805ee0098534af9264bad8d79e10b02e2f6 100644 --- a/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java +++ b/src/macosx/classes/com/apple/laf/AquaFileChooserUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -1089,8 +1089,15 @@ public class AquaFileChooserUI extends FileChooserUI { super(f); } - public Component getTableCellRendererComponent(final JTable list, final Object value, final boolean isSelected, final boolean cellHasFocus, final int index, final int col) { - super.getTableCellRendererComponent(list, value, isSelected, false, index, col); // No focus border, thanks + public Component getTableCellRendererComponent(final JTable list, + final Object value, + final boolean isSelected, + final boolean cellHasFocus, + final int index, + final int col) { + super.getTableCellRendererComponent(list, value, isSelected, false, + index, + col); // No focus border, thanks final File file = (File)value; final JFileChooser fc = getFileChooser(); setText(fc.getName(file)); @@ -1105,8 +1112,14 @@ public class AquaFileChooserUI extends FileChooserUI { super(f); } - public Component getTableCellRendererComponent(final JTable list, final Object value, final boolean isSelected, final boolean cellHasFocus, final int index, final int col) { - super.getTableCellRendererComponent(list, value, isSelected, false, index, col); + public Component getTableCellRendererComponent(final JTable list, + final Object value, + final boolean isSelected, + final boolean cellHasFocus, + final int index, + final int col) { + super.getTableCellRendererComponent(list, value, isSelected, false, + index, col); final File file = (File)fFileList.getValueAt(index, 0); setEnabled(isSelectableInList(file)); final DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT); @@ -1122,14 +1135,17 @@ public class AquaFileChooserUI extends FileChooserUI { } } + @Override public Dimension getPreferredSize(final JComponent c) { - return PREF_SIZE; + return new Dimension(PREF_WIDTH, PREF_HEIGHT); } + @Override public Dimension getMinimumSize(final JComponent c) { - return MIN_SIZE; + return new Dimension(MIN_WIDTH, MIN_HEIGHT); } + @Override public Dimension getMaximumSize(final JComponent c) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } @@ -1793,12 +1809,8 @@ public class AquaFileChooserUI extends FileChooserUI { private static final int PREF_WIDTH = 550; private static final int PREF_HEIGHT = 400; - private static final Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT); - private static final int MIN_WIDTH = 400; private static final int MIN_HEIGHT = 250; - private static final Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT); - private static final int LIST_MIN_WIDTH = 400; private static final int LIST_MIN_HEIGHT = 100; private static final Dimension LIST_MIN_SIZE = new Dimension(LIST_MIN_WIDTH, LIST_MIN_HEIGHT); diff --git a/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java b/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java index 389eb4cfeec746e7fd307b412cdd2c848fc0b1ea..bd5ab2b6a8a5e24547aedf55fff6ad0cf76f9969 100644 --- a/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java +++ b/src/macosx/classes/com/apple/laf/AquaMenuBarBorder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -25,46 +25,33 @@ package com.apple.laf; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; import javax.swing.border.Border; +import sun.swing.SwingUtilities2; + +/** + * The class represents the border of a {@code JMenuBar}. + */ public class AquaMenuBarBorder implements Border { - public AquaMenuBarBorder() { - super(); - } - /** - * Paints the border for the specified component with the specified - * position and size. - * @param c the component for which this border is being painted - * @param g the paint graphics - * @param x the x position of the painted border - * @param y the y position of the painted border - * @param width the width of the painted border - * @param height the height of the painted border - */ - public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { - // for now we don't paint a border. We let the button paint it since there - // needs to be a strict ordering for aqua components. - //paintButton(c, g, x, y, width, height); + @Override + public void paintBorder(final Component c, final Graphics g, final int x, + final int y, final int width, final int height) { g.setColor(Color.gray); - g.drawLine(x, y + height - 1, x + width, y + height - 1); + SwingUtilities2.drawHLine(g, x, x + width - 1, y + height - 1); } - /** - * Returns the insets of the border. - * @param c the component for which this border insets value applies - */ + @Override public Insets getBorderInsets(final Component c) { return new Insets(0, 0, 1, 0); } - /** - * Returns whether or not the border is opaque. If the border - * is opaque, it is responsible for filling in it's own - * background when painting. - */ + @Override public boolean isBorderOpaque() { return false; } diff --git a/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java b/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java index c3b91a2fa86274756c61dccbf4bb946dce355c2a..fe85cce80810d8674a07c8e1c1b3a5f94c40b157 100644 --- a/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java +++ b/src/macosx/classes/sun/lwawt/LWCheckboxPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -132,7 +132,9 @@ final class LWCheckboxPeer @Override public void setState(final boolean state) { synchronized (getDelegateLock()) { + getDelegate().getCurrentButton().removeItemListener(this); getDelegate().setSelected(state); + getDelegate().getCurrentButton().addItemListener(this); } repaintPeer(); } diff --git a/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp b/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp index 7b95a70dff8897e40cc99ab2c928fe1214caf939..40cddfcf53d52aef9fe86c24fd4f889988972d2a 100644 --- a/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp +++ b/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -28,7 +28,6 @@ //#define USE_VERBOSE_TRACE #include -#include #include #include #include @@ -617,7 +616,7 @@ struct OSX_DirectAudioDevice { ~OSX_DirectAudioDevice() { if (audioUnit) { - CloseComponent(audioUnit); + AudioComponentInstanceDispose(audioUnit); } if (resampler) { delete resampler; @@ -629,17 +628,16 @@ static AudioUnit CreateOutputUnit(AudioDeviceID deviceID, int isSource) { OSStatus err; AudioUnit unit; - UInt32 size; - ComponentDescription desc; + AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = (deviceID == 0 && isSource) ? kAudioUnitSubType_DefaultOutput : kAudioUnitSubType_HALOutput; desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentFlags = 0; desc.componentFlagsMask = 0; - Component comp = FindNextComponent(NULL, &desc); - err = OpenAComponent(comp, &unit); + AudioComponent comp = AudioComponentFindNext(NULL, &desc); + err = AudioComponentInstanceNew(comp, &unit); if (err) { OS_ERROR0(err, "CreateOutputUnit:OpenAComponent"); @@ -664,7 +662,7 @@ static AudioUnit CreateOutputUnit(AudioDeviceID deviceID, int isSource) // get real AudioDeviceID for default input device (macosx current input device) deviceID = GetDefaultDevice(isSource); if (!deviceID) { - CloseComponent(unit); + AudioComponentInstanceDispose(unit); return NULL; } } @@ -675,7 +673,7 @@ static AudioUnit CreateOutputUnit(AudioDeviceID deviceID, int isSource) 0, &deviceID, sizeof(deviceID)); if (err) { OS_ERROR0(err, "SetProperty (CurrentDevice)"); - CloseComponent(unit); + AudioComponentInstanceDispose(unit); return NULL; } } diff --git a/src/macosx/native/sun/awt/LWCToolkit.h b/src/macosx/native/sun/awt/LWCToolkit.h index 9df44bea3b79d84f3a379d58172b1a17e7e19e68..c3e1b538ac995de5fc619893388fbc26d1e98148 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.h +++ b/src/macosx/native/sun/awt/LWCToolkit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -28,8 +28,6 @@ #import #import -#import -#import #define DEBUG 1 diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java index fc5607696dccc75d45d2f53f82fae21abc2df47d..6a33bd5a15b045f741899c30b8738f0330c75274 100644 --- a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +++ b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -43,8 +43,6 @@ import org.w3c.dom.Node; import java.awt.image.Raster; import java.awt.image.WritableRaster; -import java.awt.image.SampleModel; -import java.awt.image.DataBuffer; import java.awt.image.DataBufferByte; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; @@ -1048,7 +1046,13 @@ public class JPEGImageWriter extends ImageWriter { // Call the writer, who will call back for every scanline - processImageStarted(currentImage); + clearAbortRequest(); + cbLock.lock(); + try { + processImageStarted(currentImage); + } finally { + cbLock.unlock(); + } boolean aborted = false; @@ -1100,6 +1104,11 @@ public class JPEGImageWriter extends ImageWriter { currentImage++; // After a successful write } + @Override + public boolean canWriteSequence() { + return true; + } + public void prepareWriteSequence(IIOMetadata streamMetadata) throws IOException { setThreadLock(); @@ -1225,6 +1234,23 @@ public class JPEGImageWriter extends ImageWriter { } } + @Override + protected synchronized void clearAbortRequest() { + setThreadLock(); + try { + cbLock.check(); + if (abortRequested()) { + super.clearAbortRequest(); + // reset C structures + resetWriter(structPointer); + // reset the native destination + setDest(structPointer); + } + } finally { + clearThreadLock(); + } + } + private void resetInternalState() { // reset C structures resetWriter(structPointer); diff --git a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java index 530cecea29f699af62a943973a69dcc55199881b..258e3e3c7d577e7af200728ae489e5229aa4159f 100644 --- a/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java @@ -100,7 +100,8 @@ class GTKFileChooserUI extends SynthFileChooserUI { private static Dimension prefListSize = new Dimension(75, 150); private static Dimension PREF_SIZE = new Dimension(435, 360); - private static Dimension MIN_SIZE = new Dimension(200, 300); + private static final int MIN_WIDTH = 200; + private static final int MIN_HEIGHT = 300; private static Dimension ZERO_ACC_SIZE = new Dimension(1, 1); @@ -1038,6 +1039,7 @@ class GTKFileChooserUI extends SynthFileChooserUI { } } + @Override public Dimension getPreferredSize(JComponent c) { Dimension prefSize = new Dimension(PREF_SIZE); JComponent accessory = getFileChooser().getAccessory(); @@ -1053,10 +1055,12 @@ class GTKFileChooserUI extends SynthFileChooserUI { } } - public Dimension getMinimumSize(JComponent x) { - return new Dimension(MIN_SIZE); + @Override + public Dimension getMinimumSize(JComponent x) { + return new Dimension(MIN_WIDTH, MIN_HEIGHT); } + @Override public Dimension getMaximumSize(JComponent x) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } diff --git a/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java b/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java index ae7baa53bc292aa459d68139912bb0004813b3de..e6b33bc3f1a94b28e3b0ef9b5c7df8c6398d5531 100644 --- a/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -65,8 +65,8 @@ public class MotifFileChooserUI extends BasicFileChooserUI { private static Dimension WITH_ACCELERATOR_PREF_SIZE = new Dimension(650, 450); private static Dimension PREF_SIZE = new Dimension(350, 450); - private static Dimension MIN_SIZE = new Dimension(200, 300); - + private static final int MIN_WIDTH = 200; + private static final int MIN_HEIGHT = 300; private static Dimension PREF_ACC_SIZE = new Dimension(10, 10); private static Dimension ZERO_ACC_SIZE = new Dimension(1, 1); @@ -615,6 +615,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { return scrollpane; } + @Override public Dimension getPreferredSize(JComponent c) { Dimension prefSize = (getFileChooser().getAccessory() != null) ? WITH_ACCELERATOR_PREF_SIZE : PREF_SIZE; @@ -627,10 +628,12 @@ public class MotifFileChooserUI extends BasicFileChooserUI { } } - public Dimension getMinimumSize(JComponent x) { - return MIN_SIZE; + @Override + public Dimension getMinimumSize(JComponent x) { + return new Dimension(MIN_WIDTH, MIN_HEIGHT); } + @Override public Dimension getMaximumSize(JComponent x) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index b22ebf958ba68a0148eb49ffb19f9dfd6a548a32..b9b9b91e0fcddc828bc5fcc0cc335607690a00ec 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -93,7 +93,6 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { private static int MIN_WIDTH = 425; private static int MIN_HEIGHT = 245; - private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT); private static int LIST_PREF_WIDTH = 444; private static int LIST_PREF_HEIGHT = 138; @@ -631,6 +630,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { * @return a Dimension specifying the preferred * width and height of the file chooser */ + @Override public Dimension getPreferredSize(JComponent c) { int prefWidth = PREF_SIZE.width; Dimension d = c.getLayout().preferredLayoutSize(c); @@ -649,8 +649,9 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { * @return a Dimension specifying the minimum * width and height of the file chooser */ + @Override public Dimension getMinimumSize(JComponent c) { - return MIN_SIZE; + return new Dimension(MIN_WIDTH, MIN_HEIGHT); } /** @@ -660,6 +661,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { * @return a Dimension specifying the maximum * width and height of the file chooser */ + @Override public Dimension getMaximumSize(JComponent c) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } diff --git a/src/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.java b/src/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.java index da7e55a2d9fa796257d3b58e0a3b43a8a6d8adc7..0f263ad3537553ca178c68690743560e08a6b8cb 100644 --- a/src/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.java +++ b/src/share/classes/com/sun/tools/jdi/InterfaceTypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -130,6 +130,15 @@ final public class InterfaceTypeImpl extends InvokableTypeImpl return null; } + @Override + boolean isAssignableTo(ReferenceType type) { + if (type.name().equals("java.lang.Object")) { + // interfaces are always assignable to j.l.Object + return true; + } + return super.isAssignableTo(type); + } + @Override List interfaces() { return superinterfaces(); @@ -140,4 +149,4 @@ final public class InterfaceTypeImpl extends InvokableTypeImpl // method must be directly in this interface return this.equals(method.declaringType()); } -} \ No newline at end of file +} diff --git a/src/share/classes/java/awt/GraphicsEnvironment.java b/src/share/classes/java/awt/GraphicsEnvironment.java index 0f7ad266fbef898548d7c92a50341cff6fb6b085..b3c6b1184ea25ab86532bc27056fd862ed2ca1f3 100644 --- a/src/share/classes/java/awt/GraphicsEnvironment.java +++ b/src/share/classes/java/awt/GraphicsEnvironment.java @@ -28,6 +28,7 @@ package java.awt; import java.awt.image.BufferedImage; import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Locale; import sun.font.FontManager; @@ -160,43 +161,38 @@ public abstract class GraphicsEnvironment { */ private static boolean getHeadlessProperty() { if (headless == null) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - String nm = System.getProperty("java.awt.headless"); + AccessController.doPrivileged((PrivilegedAction) () -> { + String nm = System.getProperty("java.awt.headless"); - if (nm == null) { - /* No need to ask for DISPLAY when run in a browser */ - if (System.getProperty("javaplugin.version") != null) { - headless = defaultHeadless = Boolean.FALSE; + if (nm == null) { + /* No need to ask for DISPLAY when run in a browser */ + if (System.getProperty("javaplugin.version") != null) { + headless = defaultHeadless = Boolean.FALSE; + } else { + String osName = System.getProperty("os.name"); + if (osName.contains("OS X") && "sun.awt.HToolkit".equals( + System.getProperty("awt.toolkit"))) + { + headless = defaultHeadless = Boolean.TRUE; } else { - String osName = System.getProperty("os.name"); - if (osName.contains("OS X") && "sun.awt.HToolkit".equals( - System.getProperty("awt.toolkit"))) - { - headless = defaultHeadless = Boolean.TRUE; - } else { - headless = defaultHeadless = - Boolean.valueOf(("Linux".equals(osName) || - "SunOS".equals(osName) || - "FreeBSD".equals(osName) || - "NetBSD".equals(osName) || - "OpenBSD".equals(osName) || - "AIX".equals(osName)) && - (System.getenv("DISPLAY") == null)); - } + final String display = System.getenv("DISPLAY"); + headless = defaultHeadless = + ("Linux".equals(osName) || + "SunOS".equals(osName) || + "FreeBSD".equals(osName) || + "NetBSD".equals(osName) || + "OpenBSD".equals(osName) || + "AIX".equals(osName)) && + (display == null || display.trim().isEmpty()); } - } else if (nm.equals("true")) { - headless = Boolean.TRUE; - } else { - headless = Boolean.FALSE; } - return null; - } + } else { + headless = Boolean.valueOf(nm); } - ); + return null; + }); } - return headless.booleanValue(); + return headless; } /** diff --git a/src/share/classes/java/awt/MenuBar.java b/src/share/classes/java/awt/MenuBar.java index a31745a3a60d4a1a488798a4f6a45ff19e7501c3..afaa35d687dc7582c026a7798fd7383f4147efa6 100644 --- a/src/share/classes/java/awt/MenuBar.java +++ b/src/share/classes/java/awt/MenuBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2015, 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 @@ -181,7 +181,7 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible * removed from the menu bar, and replaced with the specified menu. * @param m the menu to be set as the help menu */ - public void setHelpMenu(Menu m) { + public void setHelpMenu(final Menu m) { synchronized (getTreeLock()) { if (helpMenu == m) { return; @@ -189,11 +189,11 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible if (helpMenu != null) { remove(helpMenu); } - if (m.parent != this) { - add(m); - } helpMenu = m; if (m != null) { + if (m.parent != this) { + add(m); + } m.isHelpMenu = true; m.parent = this; MenuBarPeer peer = (MenuBarPeer)this.peer; @@ -242,7 +242,7 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible * @param index the position of the menu to be removed. * @see java.awt.MenuBar#add(java.awt.Menu) */ - public void remove(int index) { + public void remove(final int index) { synchronized (getTreeLock()) { Menu m = getMenu(index); menus.removeElementAt(index); @@ -252,6 +252,10 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible m.parent = null; peer.delMenu(index); } + if (helpMenu == m) { + helpMenu = null; + m.isHelpMenu = false; + } } } diff --git a/src/share/classes/java/awt/image/BufferedImage.java b/src/share/classes/java/awt/image/BufferedImage.java index bb272aacf69fa7a20cea8b2999335ed6056e9948..5ad5bd50d16e7fc4599fe212673baa767b24841d 100644 --- a/src/share/classes/java/awt/image/BufferedImage.java +++ b/src/share/classes/java/awt/image/BufferedImage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,26 +25,23 @@ package java.awt.image; -import java.awt.Transparency; -import java.awt.color.ColorSpace; import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; -import java.awt.ImageCapabilities; -import java.awt.geom.Rectangle2D; -import java.awt.geom.Point2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.Transparency; +import java.awt.color.ColorSpace; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Hashtable; +import java.util.Set; import java.util.Vector; -import sun.awt.image.BytePackedRaster; -import sun.awt.image.ShortComponentRaster; import sun.awt.image.ByteComponentRaster; +import sun.awt.image.BytePackedRaster; import sun.awt.image.IntegerComponentRaster; import sun.awt.image.OffScreenImageSource; +import sun.awt.image.ShortComponentRaster; /** * @@ -68,18 +65,14 @@ import sun.awt.image.OffScreenImageSource; * @see Raster * @see WritableRaster */ - public class BufferedImage extends java.awt.Image implements WritableRenderedImage, Transparency { - int imageType = TYPE_CUSTOM; - ColorModel colorModel; - WritableRaster raster; - OffScreenImageSource osis; - Hashtable properties; - - boolean isAlphaPremultiplied;// If true, alpha has been premultiplied in - // color channels + private int imageType = TYPE_CUSTOM; + private ColorModel colorModel; + private final WritableRaster raster; + private OffScreenImageSource osis; + private Hashtable properties; /** * Image Type Constants @@ -328,8 +321,8 @@ public class BufferedImage extends java.awt.Image 0x000000ff, // Blue 0x0 // Alpha ); - raster = colorModel.createCompatibleWritableRaster(width, - height); + raster = colorModel.createCompatibleWritableRaster(width, + height); } break; @@ -355,9 +348,8 @@ public class BufferedImage extends java.awt.Image true, // Alpha Premultiplied DataBuffer.TYPE_INT ); - - raster = colorModel.createCompatibleWritableRaster(width, - height); + raster = colorModel.createCompatibleWritableRaster(width, + height); } break; @@ -368,8 +360,8 @@ public class BufferedImage extends java.awt.Image 0x0000ff00, // Green 0x00ff0000 // Blue ); - raster = colorModel.createCompatibleWritableRaster(width, - height); + raster = colorModel.createCompatibleWritableRaster(width, + height); } break; @@ -642,7 +634,14 @@ public class BufferedImage extends java.awt.Image colorModel = cm; this.raster = raster; - this.properties = properties; + if (properties != null && !properties.isEmpty()) { + this.properties = new Hashtable<>(); + for (final Object key : properties.keySet()) { + if (key instanceof String) { + this.properties.put((String) key, properties.get(key)); + } + } + } int numBands = raster.getNumBands(); boolean isAlphaPre = cm.isAlphaPremultiplied(); final boolean isStandard = isStandard(cm, raster); @@ -1272,7 +1271,11 @@ public class BufferedImage extends java.awt.Image * or null if no property names are recognized. */ public String[] getPropertyNames() { - return null; + if (properties == null || properties.isEmpty()) { + return null; + } + final Set keys = properties.keySet(); + return keys.toArray(new String[keys.size()]); } /** diff --git a/src/share/classes/java/beans/package.html b/src/share/classes/java/beans/package.html index 9f8234673e70343ba80a1fa7bd220d319f5f36b6..a1e7498735dad4c06a9ec14a9e65ccc48dedc8a3 100644 --- a/src/share/classes/java/beans/package.html +++ b/src/share/classes/java/beans/package.html @@ -1,5 +1,5 @@ don't test defines max and min in + // terms of preferred + runTest(new JScrollPane()); + runTest(new JViewport()); + runTest(new JSplitPane()); + runTest(new JTabbedPane()); + runTest(new JToolBar()); + runTest(new JSeparator()); + runTest(new JProgressBar()); + if (!failures.isEmpty()) { + System.out.println("These classes failed"); + for (final Component failure : failures) { + System.out.println(failure.getClass()); + } + throw new RuntimeException("Test failed"); + } + } + + public void runTest(final Component c) { + try { + test(c); + c.setMinimumSize(new Dimension(100, 10)); + c.setMaximumSize(new Dimension(200, 20)); + c.setPreferredSize(new Dimension(300, 30)); + test(c); + } catch (final Throwable ignored) { + failures.add(c); + } + } + + public void test(final Component component) { + final Dimension psize = component.getPreferredSize(); + psize.width += 200; + if (Objects.equals(psize, component.getPreferredSize())) { + throw new RuntimeException("PreferredSize is wrong"); + } + final Dimension msize = component.getMaximumSize(); + msize.width += 200; + if (Objects.equals(msize, component.getMaximumSize())) { + throw new RuntimeException("MaximumSize is wrong"); + } + final Dimension misize = component.getMinimumSize(); + misize.width += 200; + if (Objects.equals(misize, component.getMinimumSize())) { + throw new RuntimeException("MinimumSize is wrong"); + } + } + + private static void setLookAndFeel(final LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + UnsupportedLookAndFeelException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/test/java/awt/Component/InsetsEncapsulation/InsetsEncapsulation.java b/test/java/awt/Component/InsetsEncapsulation/InsetsEncapsulation.java new file mode 100644 index 0000000000000000000000000000000000000000..9a14a665ee6e7db602ec869f06043823724c3d48 --- /dev/null +++ b/test/java/awt/Component/InsetsEncapsulation/InsetsEncapsulation.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Component; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.Collection; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JColorChooser; +import javax.swing.JComponent; +import javax.swing.JDesktopPane; +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JFormattedTextField; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JLayeredPane; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPasswordField; +import javax.swing.JPopupMenu; +import javax.swing.JProgressBar; +import javax.swing.JRadioButton; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JRootPane; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; +import javax.swing.JSeparator; +import javax.swing.JSlider; +import javax.swing.JSpinner; +import javax.swing.JSplitPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.JTextPane; +import javax.swing.JToggleButton; +import javax.swing.JToolBar; +import javax.swing.JTree; +import javax.swing.JViewport; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.table.JTableHeader; + +import static javax.swing.UIManager.LookAndFeelInfo; +import static javax.swing.UIManager.getInstalledLookAndFeels; + +/** + * @test + * @bug 6459800 + * @author Sergey Bylokhov + */ +public final class InsetsEncapsulation implements Runnable { + + private final Collection failures = new ArrayList<>(); + + public static void main(final String[] args) throws Exception { + for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) { + SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); + SwingUtilities.invokeAndWait(new InsetsEncapsulation()); + } + } + + @Override + public void run() { + runTest(new JLabel("hi")); + runTest(new JMenu()); + runTest(new JTree()); + runTest(new JTable()); + runTest(new JMenuItem()); + runTest(new JCheckBoxMenuItem()); + runTest(new JToggleButton()); + runTest(new JSpinner()); + runTest(new JSlider()); + runTest(Box.createVerticalBox()); + runTest(Box.createHorizontalBox()); + runTest(new JTextField()); + runTest(new JTextArea()); + runTest(new JTextPane()); + runTest(new JPasswordField()); + runTest(new JFormattedTextField()); + runTest(new JEditorPane()); + runTest(new JButton()); + runTest(new JColorChooser()); + runTest(new JFileChooser()); + runTest(new JCheckBox()); + runTest(new JInternalFrame()); + runTest(new JDesktopPane()); + runTest(new JTableHeader()); + runTest(new JLayeredPane()); + runTest(new JRootPane()); + runTest(new JMenuBar()); + runTest(new JOptionPane()); + runTest(new JRadioButton()); + runTest(new JRadioButtonMenuItem()); + runTest(new JPopupMenu()); + runTest(new JScrollBar()); + runTest(new JScrollPane()); + runTest(new JViewport()); + runTest(new JSplitPane()); + runTest(new JTabbedPane()); + runTest(new JToolBar()); + runTest(new JSeparator()); + runTest(new JProgressBar()); + if (!failures.isEmpty()) { + System.out.println("These classes failed"); + for (final Component failure : failures) { + System.out.println(failure.getClass()); + } + throw new RuntimeException("Test failed"); + } + } + + void runTest(final JComponent component) { + try { + test(component); + } catch (final Throwable ignored) { + failures.add(component); + } + } + + void test(final JComponent component) { + final Insets p = component.getInsets(); + p.top += 3; + if (p.equals(component.getInsets())) { + throw new RuntimeException("Insets altered by altering Insets!"); + } + } + + private static void setLookAndFeel(final LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + UnsupportedLookAndFeelException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh b/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh index 6642efa5bd2492ce0ce080641e9e2aeef0d0bf14..2e1fd42c588d185d9a7ae937e8e278d511a88a9f 100644 --- a/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh +++ b/test/java/awt/GraphicsEnvironment/TestDetectHeadless/TestDetectHeadless.sh @@ -28,7 +28,7 @@ # # @test -# @bug 8058930 +# @bug 8058930 7077826 # @summary java.awt.GraphicsEnvironment.getHeadlessProperty() does not work for AIX # # @build TestDetectHeadless @@ -36,11 +36,21 @@ OS=`uname -s` case "$OS" in - Windows* | CYGWIN* ) + Windows* | CYGWIN* | Darwin) echo "Passed"; exit 0 ;; * ) unset DISPLAY ;; esac +${TESTJAVA}/bin/java ${TESTVMOPTS} \ + -cp ${TESTCLASSES} TestDetectHeadless + +if [ $? -ne 0 ]; then + exit 1; +fi + +DISPLAY= +export DISPLAY + ${TESTJAVA}/bin/java ${TESTVMOPTS} \ -cp ${TESTCLASSES} TestDetectHeadless diff --git a/test/java/awt/MenuBar/RemoveHelpMenu/RemoveHelpMenu.java b/test/java/awt/MenuBar/RemoveHelpMenu/RemoveHelpMenu.java new file mode 100644 index 0000000000000000000000000000000000000000..5d87f8edc775c437c59d149ad500cc64ce48130f --- /dev/null +++ b/test/java/awt/MenuBar/RemoveHelpMenu/RemoveHelpMenu.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; + +/** + * @test + * @bug 6475361 + * @author Sergey Bylokhov + */ +public final class RemoveHelpMenu { + + public static void main(final String[] args) { + final Frame frame = new Frame("RemoveHelpMenu Test"); + try { + frame.pack(); + // peer exists + test1(getMenuBar(frame)); + test2(getMenuBar(frame)); + test3(getMenuBar(frame)); + test4(getMenuBar(frame)); + } finally { + frame.dispose(); + } + // peer is null + test1(getMenuBar(frame)); + test2(getMenuBar(frame)); + test3(getMenuBar(frame)); + test4(getMenuBar(frame)); + } + + private static MenuBar getMenuBar(final Frame frame) { + final MenuBar menuBar = new MenuBar(); + frame.setMenuBar(menuBar); + return menuBar; + } + + private static void checkHelpMenu(final Menu menu, final boolean expected) { + final boolean actual = menu.toString().contains("isHelpMenu=true"); + if (actual != expected) { + throw new RuntimeException("Incorrect menu type"); + } + } + + private static void checkMenuCount(final MenuBar bar, final int expected) { + final int actual = bar.getMenuCount(); + if (actual != expected) { + throw new RuntimeException("Incorrect menus count"); + } + } + + private static void checkCurrentMenu(final MenuBar bar, final Menu menu) { + if (bar.getHelpMenu() != menu) { + throw new RuntimeException("Wrong HelpMenu"); + } + } + + private static void test1(final MenuBar menuBar) { + checkCurrentMenu(menuBar, null); + checkMenuCount(menuBar, 0); + } + + private static void test2(final MenuBar menuBar) { + final Menu helpMenu = new Menu("Help Menu"); + menuBar.setHelpMenu(helpMenu); + checkCurrentMenu(menuBar, helpMenu); + checkMenuCount(menuBar, 1); + checkHelpMenu(helpMenu, true); + + menuBar.remove(helpMenu); + checkCurrentMenu(menuBar, null); + checkMenuCount(menuBar, 0); + checkHelpMenu(helpMenu, false); + } + + private static void test3(final MenuBar menuBar) { + final Menu helpMenu1 = new Menu("Help Menu1"); + final Menu helpMenu2 = new Menu("Help Menu2"); + menuBar.setHelpMenu(helpMenu1); + checkCurrentMenu(menuBar, helpMenu1); + checkMenuCount(menuBar, 1); + checkHelpMenu(helpMenu1, true); + checkHelpMenu(helpMenu2, false); + + menuBar.setHelpMenu(helpMenu2); + checkCurrentMenu(menuBar, helpMenu2); + checkMenuCount(menuBar, 1); + checkHelpMenu(helpMenu1, false); + checkHelpMenu(helpMenu2, true); + + menuBar.remove(helpMenu2); + checkCurrentMenu(menuBar, null); + checkMenuCount(menuBar, 0); + checkHelpMenu(helpMenu1, false); + checkHelpMenu(helpMenu2, false); + } + + private static void test4(final MenuBar menuBar) { + final Menu helpMenu = new Menu("Help Menu"); + menuBar.setHelpMenu(helpMenu); + checkCurrentMenu(menuBar, helpMenu); + checkMenuCount(menuBar, 1); + checkHelpMenu(helpMenu, true); + + menuBar.setHelpMenu(null); + checkCurrentMenu(menuBar, null); + checkMenuCount(menuBar, 0); + checkHelpMenu(helpMenu, false); + } +} \ No newline at end of file diff --git a/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh b/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh index e58072890c13afacd2f3f25e703d46f1bd8724a4..acd31541dc857b34e11be25b942c062def619965 100644 --- a/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh +++ b/test/java/awt/Toolkit/BadDisplayTest/BadDisplayTest.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2014, 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 @@ -21,23 +21,15 @@ ${TESTJAVA}/bin/javac -cp ${TESTSRC} -d . ${TESTSRC}/BadDisplayTest.java - -DISPLAY= -export DISPLAY - OS=`uname -s` case "$OS" in - SunOS ) - ${TESTJAVA}/bin/java BadDisplayTest - ;; - Linux ) - ${TESTJAVA}/bin/java BadDisplayTest - ;; - * ) - echo "Unsupported System: ${OS}" - exit 0; - ;; + Windows* | CYGWIN* | Darwin) + echo "Passed"; exit 0 ;; esac -exit $? +DISPLAY=SomeBadDisplay +export DISPLAY + +${TESTJAVA}/bin/java ${TESTVMOPTS} BadDisplayTest +exit $? diff --git a/test/java/awt/Toolkit/GetImage/bug8078165.java b/test/java/awt/Toolkit/GetImage/bug8078165.java new file mode 100644 index 0000000000000000000000000000000000000000..81ebc8a8618c17080a80d7ee993358a991834ea0 --- /dev/null +++ b/test/java/awt/Toolkit/GetImage/bug8078165.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, 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. + */ + + +import java.awt.*; +import java.net.URL; +import java.security.Permission; + + +/** + * @test + * @bug 8078165 + * @summary NPE when attempting to get image from toolkit + * @author Anton Nashatyrev + */ +public final class bug8078165 { + + public static void main(final String[] args) throws Exception { + // Mac only + System.setSecurityManager(new SecurityManager() { + @Override + public void checkPermission(Permission permission) { + // Just allows everything + } + }); + // The method shouldn't throw NPE + Toolkit.getDefaultToolkit().getImage(new URL("file://./dummyImage@2x.png")); + Toolkit.getDefaultToolkit().getImage("./dummyImage@2x.png"); + } +} diff --git a/test/java/awt/image/BufferedImage/GetPropertyNames.java b/test/java/awt/image/BufferedImage/GetPropertyNames.java new file mode 100644 index 0000000000000000000000000000000000000000..244da3af94cb2496f5b1cbf95da8061c28689f10 --- /dev/null +++ b/test/java/awt/image/BufferedImage/GetPropertyNames.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.util.Properties; + +import static java.awt.image.BufferedImage.TYPE_INT_ARGB; + +/** + * @test + * @bug 8066132 + * @author Sergey Bylokhov + */ +public final class GetPropertyNames { + + static BufferedImage defaultProps = new BufferedImage(1, 1, TYPE_INT_ARGB); + + public static void main(final String[] args) { + // default result is null + if (defaultProps.getPropertyNames() != null) { + throw new RuntimeException("PropertyNames should be null"); + } + // for null properties result is null + final BufferedImage emptyProps = getBufferedImage(null); + if (emptyProps.getPropertyNames() != null) { + throw new RuntimeException("PropertyNames should be null"); + } + // for empty properties result is null + final BufferedImage nullProps = getBufferedImage(new Properties()); + if (nullProps.getPropertyNames() != null) { + throw new RuntimeException("PropertyNames should be null"); + } + // for non-string keys result is null + final Properties properties = new Properties(); + properties.put(1, 1); + properties.put(2, 2); + properties.put(3, 3); + final BufferedImage nonStringProps = getBufferedImage(properties); + if (nonStringProps.getPropertyNames() != null) { + throw new RuntimeException("PropertyNames should be null"); + } + // for string keys result is not null + properties.clear(); + properties.setProperty("1", "1"); + properties.setProperty("2", "2"); + validate(getBufferedImage(properties), 2); + // for the mix of strings and objects result is not null + properties.clear(); + properties.put(1, 1); + properties.put(2, 2); + properties.put(3, 3); + properties.setProperty("key1", "value1"); + properties.setProperty("key2", "value2"); + final BufferedImage mixProps = getBufferedImage(properties); + validate(mixProps, 2); + if (!"value1".equals(mixProps.getProperty("key1")) + || !"value2".equals(mixProps.getProperty("key2"))) { + throw new RuntimeException("Wrong key-value pair"); + } + } + + + private static BufferedImage getBufferedImage(final Properties properties) { + return new BufferedImage(defaultProps.getColorModel(), + defaultProps.getRaster(), + defaultProps.isAlphaPremultiplied(), + properties); + } + + private static void validate(final BufferedImage bi, final int expected) { + final String[] names = bi.getPropertyNames(); + if (names.length != expected) { + throw new RuntimeException("Wrong number of names"); + } + for (final String name : names) { + final Object property = bi.getProperty(name); + if (property == Image.UndefinedProperty || property == null) { + throw new RuntimeException("Unexpected property"); + } + } + } +} diff --git a/test/java/util/Currency/CurrencyTest.java b/test/java/util/Currency/CurrencyTest.java index 6971442bfb0a90f55ab80e8049346e114cbcea25..cb6d35a2a9f7131ff3d70271ac1894167c7a039b 100644 --- a/test/java/util/Currency/CurrencyTest.java +++ b/test/java/util/Currency/CurrencyTest.java @@ -23,7 +23,7 @@ /* * @test * @bug 4290801 4692419 4693631 5101540 5104960 6296410 6336600 6371531 - * 6488442 7036905 + * 6488442 7036905 8074350 8074351 * @summary Basic tests for Currency class. */ @@ -49,6 +49,7 @@ public class CurrencyTest { testFractionDigits(); testSerialization(); testDisplayNames(); + testFundsCodes(); } static void testCurrencyCodeValidation() { @@ -265,4 +266,41 @@ public class CurrencyTest { } } + static void testFundsCodes() { + testValidCurrency("BOV"); + testValidCurrency("CHE"); + testValidCurrency("CHW"); + testValidCurrency("CLF"); + testValidCurrency("COU"); + testValidCurrency("MXV"); + testValidCurrency("USN"); + testValidCurrency("UYI"); + + testFractionDigits("BOV", 2); + testFractionDigits("CHE", 2); + testFractionDigits("CHW", 2); + testFractionDigits("CLF", 4); + testFractionDigits("COU", 2); + testFractionDigits("MXV", 2); + testFractionDigits("USN", 2); + testFractionDigits("UYI", 0); + + testNumericCode("BOV", 984); + testNumericCode("CHE", 947); + testNumericCode("CHW", 948); + testNumericCode("CLF", 990); + testNumericCode("COU", 970); + testNumericCode("MXV", 979); + testNumericCode("USN", 997); + testNumericCode("UYI", 940); + } + + static void testNumericCode(String currencyCode, int expectedNumeric) { + int numeric = Currency.getInstance(currencyCode).getNumericCode(); + if (numeric != expectedNumeric) { + throw new RuntimeException("Wrong numeric code for currency " + + currencyCode +": expected " + expectedNumeric + + ", got " + numeric); + } + } } diff --git a/test/java/util/Currency/PropertiesTest.java b/test/java/util/Currency/PropertiesTest.java index 4b84e06584e8eb1a88c9d2f0b7ec6077493cbe1d..96127bf19fea5f1ae4c682d7cf2f937d19ece1b0 100644 --- a/test/java/util/Currency/PropertiesTest.java +++ b/test/java/util/Currency/PropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, 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 @@ -107,7 +107,7 @@ public class PropertiesTest { keys = p.stringPropertyNames(); Pattern propertiesPattern = Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + - "([0-3])\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + + "(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + "\\d{2}:\\d{2})?"); for (String key: keys) { String val = p.getProperty(key); @@ -135,14 +135,20 @@ public class PropertiesTest { // ignore this continue; } + + String code = m.group(1); + int numeric = Integer.parseInt(m.group(2)); + int fraction = Integer.parseInt(m.group(3)); + if (fraction > 9) { + System.out.println("Skipping since the fraction is greater than 9"); + continue; + } + Matcher mAfter = propertiesPattern.matcher(afterVal); mAfter.find(); - String code = m.group(1); String codeAfter = mAfter.group(1); - int numeric = Integer.parseInt(m.group(2)); int numericAfter = Integer.parseInt(mAfter.group(2)); - int fraction = Integer.parseInt(m.group(3)); int fractionAfter = Integer.parseInt(mAfter.group(3)); if (code.equals(codeAfter) && (numeric == numericAfter)&& diff --git a/test/java/util/Currency/PropertiesTest.sh b/test/java/util/Currency/PropertiesTest.sh index 01f1326cd2d474ab0a6ebc9c095865b684aab28b..aa4f8d15b6e59b36f8acf7b65f84e299f2d639bc 100644 --- a/test/java/util/Currency/PropertiesTest.sh +++ b/test/java/util/Currency/PropertiesTest.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2015, 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 @@ -23,7 +23,7 @@ # # @test -# @bug 6332666 6863624 7180362 8003846 +# @bug 6332666 6863624 7180362 8003846 8074350 8074351 # @summary tests the capability of replacing the currency data with user # specified currency properties file # @build PropertiesTest diff --git a/test/java/util/Currency/ValidateISO4217.java b/test/java/util/Currency/ValidateISO4217.java index bf433a1c8ede97d8bc1ebfb9248070cfac660837..c65c9802fb452e20c6f6ad89e84160aee983ece8 100644 --- a/test/java/util/Currency/ValidateISO4217.java +++ b/test/java/util/Currency/ValidateISO4217.java @@ -23,6 +23,7 @@ /* * @test * @bug 4691089 4819436 4942982 5104960 6544471 6627549 7066203 7195759 + * 8074350 8074351 * @summary Validate ISO 4217 data for Currency class. */ @@ -92,7 +93,7 @@ public class ValidateISO4217 { /* Codes that are obsolete, do not have related country */ static final String otherCodes = - "ADP-AFA-ATS-AYM-AZM-BEF-BGL-BOV-BYB-CLF-CUC-CYP-DEM-EEK-ESP-FIM-FRF-GHC-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-MZM-NLG-PTE-ROL-RUR-SDD-SIT-SKK-SRG-TMM-TPE-TRL-VEF-USN-USS-VEB-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XSU-XTS-XUA-XXX-YUM-ZMK-ZWD-ZWN-ZWR"; + "ADP-AFA-ATS-AYM-AZM-BEF-BGL-BOV-BYB-CHE-CHW-CLF-COU-CUC-CYP-DEM-EEK-ESP-FIM-FRF-GHC-GRD-GWP-IEP-ITL-LUF-MGF-MTL-MXV-MZM-NLG-PTE-ROL-RUR-SDD-SIT-SKK-SRG-TMM-TPE-TRL-VEF-UYI-USN-USS-VEB-XAG-XAU-XBA-XBB-XBC-XBD-XDR-XFO-XFU-XPD-XPT-XSU-XTS-XUA-XXX-YUM-ZMK-ZWD-ZWN-ZWR"; static boolean err = false; diff --git a/test/java/util/Currency/currency.properties b/test/java/util/Currency/currency.properties index ce3c7bba79b3f25ec928f7c9d9533e63b1828b92..d8e874d819a63a07374582288fee2482d487c74e 100644 --- a/test/java/util/Currency/currency.properties +++ b/test/java/util/Currency/currency.properties @@ -1,20 +1,30 @@ # # Test data for replacing the currency data # -JP=JPZ,123,2 -ES=ESD,877,2 -US=euR,978,2,2001-01-01T00:00:00 + +# valid entries +CL=CLF,990,4 CM=IED,111,2, 2004-01-01T00:70:00 +ES=ESD,877,2 +JP=JPZ,123,2 +MA=MAA,555,5 +MC=MCC,555,6 +MD=MDD,555,7 +ME=MEE,555,8 +MF=MFF,555,9 +NO=EUR ,978 ,2, 2099-01-01T00:00:00 SB=EUR,111,2, 2099-01-01T00:00:00 +US=euR,978,2,2001-01-01T00:00:00 ZZ = ZZZ , 999 , 3 -NO=EUR ,978 ,2, 2099-01-01T00:00:00 # invalid entries -GB=123 -FR=zzzzz.123 DE=2009-01-01T00:00:00,EUR,111,2 -IE=euR,111,2,#testcomment -=euR,111,2, 2099-01-01-00-00-00 FM=DED,194,2,eeee-01-01T00:00:00 -PE=EUR ,978 ,2, 20399-01-01T00:00:00 +FR=zzzzz.123 +GB=123 +IE=euR,111,2,#testcomment +MG=MGG,990,10 MX=SSS,493,2,2001-01-01-00-00-00 +PE=EUR ,978 ,2, 20399-01-01T00:00:00 +MG=MGG,990,10 +=euR,111,2, 2099-01-01-00-00-00 diff --git a/test/java/util/Currency/tablea1.txt b/test/java/util/Currency/tablea1.txt index 298856753b5842c98f42e3b93fcaa1d0d02682b2..12c9f7e2024bf4eb2c7aeb96320aef9f2ae883ca 100644 --- a/test/java/util/Currency/tablea1.txt +++ b/test/java/util/Currency/tablea1.txt @@ -5,7 +5,7 @@ # # Version -FILEVERSION=1 +FILEVERSION=2 DATAVERSION=159 # ISO 4217 currency data @@ -55,7 +55,7 @@ KY KYD 136 2 CF XAF 950 0 TD XAF 950 0 CL CLP 152 0 -#CL CLF 990 0 +#CL CLF 990 4 CN CNY 156 2 CX AUD 36 2 CC AUD 36 2 @@ -265,6 +265,7 @@ US USD 840 2 #US USN 997 2 UM USD 840 2 UY UYU 858 2 +#UY UYI 940 0 UZ UZS 860 2 VU VUV 548 0 VE VEF 937 2 diff --git a/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java b/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java index edd991b4cd185e2e8d12b236e28b71384ba98006..8eab9947dd7fac1cd0137c42be162f3a40411014 100644 --- a/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java +++ b/test/java/util/PluggableLocale/TimeZoneNameProviderTest.java @@ -25,6 +25,7 @@ */ import java.text.*; +import java.time.format.TextStyle; import java.util.*; import sun.util.locale.provider.*; import sun.util.resources.*; @@ -42,6 +43,7 @@ public class TimeZoneNameProviderTest extends ProviderTest { test2(); test3(); aliasTest(); + genericFallbackTest(); } void test1() { @@ -169,9 +171,9 @@ public class TimeZoneNameProviderTest extends ProviderTest { for (int style : new int[] { TimeZone.LONG, TimeZone.SHORT }) { String osakaStd = tz.getDisplayName(false, style, OSAKA); if (osakaStd != null) { - // No API for getting generic time zone names - String generic = TimeZoneNameUtility.retrieveGenericDisplayName(tzname, - style, GENERIC); + String generic = tz.toZoneId().getDisplayName( + style == TimeZone.LONG ? TextStyle.FULL : TextStyle.SHORT, + GENERIC); String expected = "Generic " + osakaStd; if (!expected.equals(generic)) { throw new RuntimeException("Wrong generic name: got=\"" + generic @@ -230,4 +232,20 @@ public class TimeZoneNameProviderTest extends ProviderTest { throw new RuntimeException("Provider's localized name is not available for an alias ID: "+JAPAN+". result: "+japan+" expected: "+JST_IN_OSAKA); } } + + /* + * Tests whether generic names can be retrieved through fallback. + * The test assumes the provider impl for OSAKA locale does NOT + * provide generic names. + */ + final String PT = "PT"; // SHORT generic name for "America/Los_Angeles" + void genericFallbackTest() { + String generic = + TimeZone.getTimeZone(LATIME) + .toZoneId() + .getDisplayName(TextStyle.SHORT, OSAKA); + if (!PT.equals(generic)) { + throw new RuntimeException("Generic name fallback failed. got: "+generic); + } + } } diff --git a/test/javax/crypto/Cipher/CipherInputStreamExceptions.java b/test/javax/crypto/Cipher/CipherInputStreamExceptions.java new file mode 100644 index 0000000000000000000000000000000000000000..783967a9eacc24cd5f46684c0e7355ac807e6fd5 --- /dev/null +++ b/test/javax/crypto/Cipher/CipherInputStreamExceptions.java @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2015, 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 8064546 + * @summary Throw exceptions during reading but not closing of a + * CipherInputStream: + * - Make sure authenticated algorithms continue to throwing exceptions + * when the authentication tag fails verification. + * - Make sure other algorithms do not throw exceptions when the stream + * calls close() and only throw when read() errors. + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.Exception; +import java.lang.RuntimeException; +import java.lang.Throwable; +import java.security.AlgorithmParameters; +import javax.crypto.AEADBadTagException; +import javax.crypto.Cipher; +import javax.crypto.CipherInputStream; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import javax.crypto.spec.GCMParameterSpec; + +public class CipherInputStreamExceptions { + + static SecretKeySpec key = new SecretKeySpec(new byte[16], "AES"); + static GCMParameterSpec gcmspec = new GCMParameterSpec(128, new byte[16]); + static IvParameterSpec iv = new IvParameterSpec(new byte[16]); + static boolean failure = false; + + /* Full read stream, check that getMoreData() is throwing an exception + * This test + * 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding + * 2) Changes the last byte to invalidate the authetication tag. + * 3) Fully reads CipherInputStream to decrypt the message and closes + */ + + static void gcm_AEADBadTag() throws Exception { + Cipher c; + byte[] read = new byte[200]; + + System.out.println("Running gcm_AEADBadTag"); + + // Encrypt 100 bytes with AES/GCM/PKCS5Padding + byte[] ct = encryptedText("GCM", 100); + // Corrupt the encrypted message + ct = corruptGCM(ct); + // Create stream for decryption + CipherInputStream in = getStream("GCM", ct); + + try { + int size = in.read(read); + throw new RuntimeException("Fail: CipherInputStream.read() " + + "returned " + size + " and didn't throw an exception."); + } catch (IOException e) { + Throwable ec = e.getCause(); + if (ec instanceof AEADBadTagException) { + System.out.println(" Pass."); + } else { + System.out.println(" Fail: " + ec.getMessage()); + throw new RuntimeException(ec); + } + } finally { + in.close(); + } + } + + /* Short read stream, + * This test + * 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding + * 2) Reads 100 bytes from stream to decrypt the message and closes + * 3) Make sure no value is returned by read() + * 4) Make sure no exception is thrown + */ + + static void gcm_shortReadAEAD() throws Exception { + Cipher c; + byte[] read = new byte[100]; + + System.out.println("Running gcm_shortReadAEAD"); + + byte[] pt = new byte[600]; + pt[0] = 1; + // Encrypt provided 600 bytes with AES/GCM/PKCS5Padding + byte[] ct = encryptedText("GCM", pt); + // Create stream for decryption + CipherInputStream in = getStream("GCM", ct); + + int size = 0; + try { + size = in.read(read); + in.close(); + if (read.length != 100) { + throw new RuntimeException("Fail: read size = " + read.length + + "should be 100."); + } + if (read[0] != 1) { + throw new RuntimeException("Fail: The decrypted text does " + + "not match the plaintext: '" + read[0] +"'"); + } + } catch (IOException e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + System.out.println(" Pass."); + } + + /* + * Verify doFinal() exception is suppressed when input stream is not + * read before it is closed. + * This test: + * 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding + * 2) Changes the last byte to invalidate the authetication tag. + * 3) Opens a CipherInputStream and the closes it. Never reads from it. + * + * There should be no exception thrown. + */ + static void gcm_suppressUnreadCorrupt() throws Exception { + Cipher c; + byte[] read = new byte[200]; + + System.out.println("Running supressUnreadCorrupt test"); + + // Encrypt 100 bytes with AES/GCM/PKCS5Padding + byte[] ct = encryptedText("GCM", 100); + // Corrupt the encrypted message + ct = corruptGCM(ct); + // Create stream for decryption + CipherInputStream in = getStream("GCM", ct); + + try { + in.close(); + System.out.println(" Pass."); + } catch (IOException e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + } + + /* + * Verify noexception thrown when 1 byte is read from a GCM stream + * and then closed + * This test: + * 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding + * 2) Read one byte from the stream, expect no exception thrown. + * 4) Close stream,expect no exception thrown. + */ + static void gcm_oneReadByte() throws Exception { + + System.out.println("Running gcm_oneReadByte test"); + + // Encrypt 100 bytes with AES/GCM/PKCS5Padding + byte[] ct = encryptedText("GCM", 100); + // Create stream for decryption + CipherInputStream in = getStream("GCM", ct); + + try { + in.read(); + System.out.println(" Pass."); + } catch (Exception e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + } + + /* + * Verify exception thrown when 1 byte is read from a corrupted GCM stream + * and then closed + * This test: + * 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding + * 2) Changes the last byte to invalidate the authetication tag. + * 3) Read one byte from the stream, expect exception thrown. + * 4) Close stream,expect no exception thrown. + */ + static void gcm_oneReadByteCorrupt() throws Exception { + + System.out.println("Running gcm_oneReadByteCorrupt test"); + + // Encrypt 100 bytes with AES/GCM/PKCS5Padding + byte[] ct = encryptedText("GCM", 100); + // Corrupt the encrypted message + ct = corruptGCM(ct); + // Create stream for decryption + CipherInputStream in = getStream("GCM", ct); + + try { + in.read(); + System.out.println(" Fail. No exception thrown."); + } catch (IOException e) { + Throwable ec = e.getCause(); + if (ec instanceof AEADBadTagException) { + System.out.println(" Pass."); + } else { + System.out.println(" Fail: " + ec.getMessage()); + throw new RuntimeException(ec); + } + } + } + + /* Check that close() does not throw an exception with full message in + * CipherInputStream's ibuffer. + * This test: + * 1) Encrypts a 97 byte message with AES/CBC/PKCS5Padding + * 2) Create a stream that sends 96 bytes. + * 3) Read stream once, + * 4) Close and expect no exception + */ + + static void cbc_shortStream() throws Exception { + Cipher c; + AlgorithmParameters params; + byte[] read = new byte[200]; + + System.out.println("Running cbc_shortStream"); + + // Encrypt 97 byte with AES/CBC/PKCS5Padding + byte[] ct = encryptedText("CBC", 97); + // Create stream with only 96 bytes of encrypted data + CipherInputStream in = getStream("CBC", ct, 96); + + try { + int size = in.read(read); + in.close(); + if (size != 80) { + throw new RuntimeException("Fail: CipherInputStream.read() " + + "returned " + size + ". Should have been 80"); + } + System.out.println(" Pass."); + } catch (IOException e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + } + + /* Check that close() does not throw an exception when the whole message is + * inside the internal buffer (ibuffer) in CipherInputStream and we read + * one byte and close the stream. + * This test: + * 1) Encrypts a 400 byte message with AES/CBC/PKCS5Padding + * 2) Read one byte from the stream + * 3) Close and expect no exception + */ + + static void cbc_shortRead400() throws Exception { + System.out.println("Running cbc_shortRead400"); + + // Encrypt 400 byte with AES/CBC/PKCS5Padding + byte[] ct = encryptedText("CBC", 400); + // Create stream with encrypted data + CipherInputStream in = getStream("CBC", ct); + + try { + in.read(); + in.close(); + System.out.println(" Pass."); + } catch (IOException e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + } + + /* Check that close() does not throw an exception when the inside the + * internal buffer (ibuffer) in CipherInputStream does not contain the + * whole message. + * This test: + * 1) Encrypts a 600 byte message with AES/CBC/PKCS5Padding + * 2) Read one byte from the stream + * 3) Close and expect no exception + */ + + static void cbc_shortRead600() throws Exception { + System.out.println("Running cbc_shortRead600"); + + // Encrypt 600 byte with AES/CBC/PKCS5Padding + byte[] ct = encryptedText("CBC", 600); + // Create stream with encrypted data + CipherInputStream in = getStream("CBC", ct); + + try { + in.read(); + in.close(); + System.out.println(" Pass."); + } catch (IOException e) { + System.out.println(" Fail: " + e.getMessage()); + throw new RuntimeException(e.getCause()); + } + } + + /* Check that exception is thrown when message is fully read + * This test: + * 1) Encrypts a 96 byte message with AES/CBC/PKCS5Padding + * 2) Create a stream that sends 95 bytes. + * 3) Read stream to the end + * 4) Expect IllegalBlockSizeException thrown + */ + + static void cbc_readAllIllegalBlockSize() throws Exception { + byte[] read = new byte[200]; + + System.out.println("Running cbc_readAllIllegalBlockSize test"); + + // Encrypt 96 byte with AES/CBC/PKCS5Padding + byte[] ct = encryptedText("CBC", 96); + // Create a stream with only 95 bytes of encrypted data + CipherInputStream in = getStream("CBC", ct, 95); + + try { + int s, size = 0; + while ((s = in.read(read)) != -1) { + size += s; + } + throw new RuntimeException("Fail: No IllegalBlockSizeException. " + + "CipherInputStream.read() returned " + size); + + } catch (IOException e) { + Throwable ec = e.getCause(); + if (ec instanceof IllegalBlockSizeException) { + System.out.println(" Pass."); + } else { + System.out.println(" Fail: " + ec.getMessage()); + throw new RuntimeException(ec); + } + } + } + + /* Generic method to create encrypted text */ + static byte[] encryptedText(String mode, int length) throws Exception{ + return encryptedText(mode, new byte[length]); + } + + /* Generic method to create encrypted text */ + static byte[] encryptedText(String mode, byte[] pt) throws Exception{ + Cipher c; + if (mode.compareTo("GCM") == 0) { + c = Cipher.getInstance("AES/GCM/PKCS5Padding", "SunJCE"); + c.init(Cipher.ENCRYPT_MODE, key, gcmspec); + } else if (mode.compareTo("CBC") == 0) { + c = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE"); + c.init(Cipher.ENCRYPT_MODE, key, iv); + } else { + return null; + } + + return c.doFinal(pt); + } + + /* Generic method to get a properly setup CipherInputStream */ + static CipherInputStream getStream(String mode, byte[] ct) throws Exception { + return getStream(mode, ct, ct.length); + } + + /* Generic method to get a properly setup CipherInputStream */ + static CipherInputStream getStream(String mode, byte[] ct, int length) + throws Exception { + Cipher c; + + if (mode.compareTo("GCM") == 0) { + c = Cipher.getInstance("AES/GCM/PKCS5Padding", "SunJCE"); + c.init(Cipher.DECRYPT_MODE, key, gcmspec); + } else if (mode.compareTo("CBC") == 0) { + c = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE"); + c.init(Cipher.DECRYPT_MODE, key, iv); + } else { + return null; + } + + return new CipherInputStream(new ByteArrayInputStream(ct, 0, length), c); + + } + + /* Generic method for corrupting a GCM message. Change the last + * byte on of the authentication tag + */ + static byte[] corruptGCM(byte[] ct) { + ct[ct.length - 1] = (byte) (ct[ct.length - 1] + 1); + return ct; + } + + public static void main(String[] args) throws Exception { + gcm_AEADBadTag(); + gcm_shortReadAEAD(); + gcm_suppressUnreadCorrupt(); + gcm_oneReadByte(); + gcm_oneReadByteCorrupt(); + cbc_shortStream(); + cbc_shortRead400(); + cbc_shortRead600(); + cbc_readAllIllegalBlockSize(); + } +} diff --git a/test/javax/imageio/plugins/shared/CanWriteSequence.java b/test/javax/imageio/plugins/shared/CanWriteSequence.java new file mode 100644 index 0000000000000000000000000000000000000000..54da1b77cb7da64dddeee968b865fc94cc5b1207 --- /dev/null +++ b/test/javax/imageio/plugins/shared/CanWriteSequence.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.io.File; +import java.io.FileOutputStream; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.spi.IIORegistry; +import javax.imageio.spi.ImageWriterSpi; +import javax.imageio.stream.ImageOutputStream; + +/** + * @test + * @bug 4958064 + * @author Sergey Bylokhov + */ +public final class CanWriteSequence { + + public static void main(final String[] args) throws Exception { + final IIORegistry registry = IIORegistry.getDefaultInstance(); + final Iterator iter = + registry.getServiceProviders(ImageWriterSpi.class, + provider -> true, true); + // Validates all supported ImageWriters + while (iter.hasNext()) { + final ImageWriter writer = iter.next().createWriterInstance(); + System.out.println("ImageWriter = " + writer); + test(writer); + } + System.out.println("Test passed"); + } + + private static void test(final ImageWriter writer) throws Exception { + final File file = File.createTempFile("temp", ".img"); + file.deleteOnExit(); + final FileOutputStream fos = new FileOutputStream(file); + final ImageOutputStream ios = ImageIO.createImageOutputStream(fos); + writer.setOutput(ios); + final IIOMetadata data = writer.getDefaultStreamMetadata(null); + + if (writer.canWriteSequence()) { + writer.prepareWriteSequence(data); + } else { + try { + writer.prepareWriteSequence(data); + throw new RuntimeException( + "UnsupportedOperationException was not thrown"); + } catch (final UnsupportedOperationException ignored) { + // expected + } + } + writer.dispose(); + ios.close(); + } +} \ No newline at end of file diff --git a/test/javax/imageio/plugins/shared/WriteAfterAbort.java b/test/javax/imageio/plugins/shared/WriteAfterAbort.java new file mode 100644 index 0000000000000000000000000000000000000000..4b503d2fe6f893cc97b208f5fc6c45903bc9f878 --- /dev/null +++ b/test/javax/imageio/plugins/shared/WriteAfterAbort.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageWriter; +import javax.imageio.event.IIOWriteProgressListener; +import javax.imageio.spi.IIORegistry; +import javax.imageio.spi.ImageWriterSpi; +import javax.imageio.stream.ImageOutputStream; + +import static java.awt.image.BufferedImage.TYPE_BYTE_BINARY; + +/** + * @test + * @bug 4952954 + * @summary abortFlag must be cleared for every ImageWriter.write operation + * @author Sergey Bylokhov + */ +public final class WriteAfterAbort implements IIOWriteProgressListener { + + private volatile boolean abortFlag = true; + private volatile boolean isAbortCalled; + private volatile boolean isCompleteCalled; + private volatile boolean isProgressCalled; + private volatile boolean isStartedCalled; + private static final int WIDTH = 100; + private static final int HEIGHT = 100; + + private void test(final ImageWriter writer) throws IOException { + // Image initialization + final BufferedImage imageWrite = new BufferedImage(WIDTH, HEIGHT, + TYPE_BYTE_BINARY); + final Graphics2D g = imageWrite.createGraphics(); + g.setColor(Color.WHITE); + g.fillRect(0, 0, WIDTH, HEIGHT); + g.dispose(); + + // File initialization + final File file = File.createTempFile("temp", ".img"); + file.deleteOnExit(); + final FileOutputStream fos = new SkipWriteOnAbortOutputStream(file); + final ImageOutputStream ios = ImageIO.createImageOutputStream(fos); + writer.setOutput(ios); + writer.addIIOWriteProgressListener(this); + + // This write will be aborted, and file will not be touched + writer.write(imageWrite); + if (!isStartedCalled) { + throw new RuntimeException("Started should be called"); + } + if (!isProgressCalled) { + throw new RuntimeException("Progress should be called"); + } + if (!isAbortCalled) { + throw new RuntimeException("Abort should be called"); + } + if (isCompleteCalled) { + throw new RuntimeException("Complete should not be called"); + } + // Flush aborted data + ios.flush(); + + // This write should be completed successfully and the file should + // contain correct image data. + abortFlag = false; + isAbortCalled = false; + isCompleteCalled = false; + isProgressCalled = false; + isStartedCalled = false; + writer.write(imageWrite); + + if (!isStartedCalled) { + throw new RuntimeException("Started should be called"); + } + if (!isProgressCalled) { + throw new RuntimeException("Progress should be called"); + } + if (isAbortCalled) { + throw new RuntimeException("Abort should not be called"); + } + if (!isCompleteCalled) { + throw new RuntimeException("Complete should be called"); + } + writer.dispose(); + ios.close(); + + // Validates content of the file. + final BufferedImage imageRead = ImageIO.read(file); + for (int x = 0; x < WIDTH; ++x) { + for (int y = 0; y < HEIGHT; ++y) { + if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) { + throw new RuntimeException("Test failed."); + } + } + } + } + + public static void main(final String[] args) throws IOException { + final IIORegistry registry = IIORegistry.getDefaultInstance(); + final Iterator iter = registry.getServiceProviders( + ImageWriterSpi.class, provider -> true, true); + + // Validates all supported ImageWriters + while (iter.hasNext()) { + final WriteAfterAbort writeAfterAbort = new WriteAfterAbort(); + final ImageWriter writer = iter.next().createWriterInstance(); + System.out.println("ImageWriter = " + writer); + writeAfterAbort.test(writer); + } + System.out.println("Test passed"); + } + + // Callbacks + + @Override + public void imageComplete(ImageWriter source) { + isCompleteCalled = true; + } + + @Override + public void imageProgress(ImageWriter source, float percentageDone) { + isProgressCalled = true; + if (percentageDone > 50 && abortFlag) { + source.abort(); + } + } + + @Override + public void imageStarted(ImageWriter source, int imageIndex) { + isStartedCalled = true; + } + + @Override + public void writeAborted(final ImageWriter source) { + isAbortCalled = true; + } + + @Override + public void thumbnailComplete(ImageWriter source) { + } + + @Override + public void thumbnailProgress(ImageWriter source, float percentageDone) { + } + + @Override + public void thumbnailStarted(ImageWriter source, int imageIndex, + int thumbnailIndex) { + } + + /** + * We need to skip writes on abort, because content of the file after abort + * is undefined. + */ + private class SkipWriteOnAbortOutputStream extends FileOutputStream { + + SkipWriteOnAbortOutputStream(File file) throws FileNotFoundException { + super(file); + } + + @Override + public void write(int b) throws IOException { + if (!abortFlag) { + super.write(b); + } + } + + @Override + public void write(byte[] b) throws IOException { + if (!abortFlag) { + super.write(b); + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (!abortFlag) { + super.write(b, off, len); + } + } + } +} + diff --git a/test/javax/sound/midi/Devices/InitializationHang.java b/test/javax/sound/midi/Devices/InitializationHang.java new file mode 100644 index 0000000000000000000000000000000000000000..c8e38d2d81fe34e7526fb1b71b2e5926400b0d5d --- /dev/null +++ b/test/javax/sound/midi/Devices/InitializationHang.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Toolkit; + +import javax.sound.midi.MidiSystem; + +/** + * @test + * @bug 8068412 + * @author Sergey Bylokhov + */ +public final class InitializationHang { + + public static void main(final String[] argv) throws Exception { + MidiSystem.getReceiver(); + Toolkit.getDefaultToolkit(); + } +} + diff --git a/test/javax/swing/AbstractButton/AnimatedIcon/AnimatedIcon.java b/test/javax/swing/AbstractButton/AnimatedIcon/AnimatedIcon.java new file mode 100644 index 0000000000000000000000000000000000000000..d8843ab5d640759b819a4bf9d5a4d5f9d9c268dd --- /dev/null +++ b/test/javax/swing/AbstractButton/AnimatedIcon/AnimatedIcon.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.SwingUtilities; + +import static java.awt.image.BufferedImage.TYPE_INT_RGB; + +/** + * @test + * @bug 6573305 + * @summary Animated icon should animate when the JButton is pressed. + * @author Sergey Bylokhov + */ +public final class AnimatedIcon { + + public static void main(final String[] args) throws Exception { + SwingUtilities.invokeAndWait(() -> { + final BufferedImage bi = new BufferedImage(1, 1, TYPE_INT_RGB); + final ImageIcon icon = new ImageIcon(bi); + final JButton button = new JButton(icon); + // Default icon is set => imageUpdate should return true for it + isAnimated(bi, button); + button.getModel().setPressed(true); + button.getModel().setArmed(true); + isAnimated(bi, button); + button.getModel().setPressed(false); + button.getModel().setArmed(false); + button.getModel().setSelected(true); + isAnimated(bi, button); + button.getModel().setSelected(false); + button.getModel().setRollover(true); + button.setRolloverEnabled(true); + isAnimated(bi, button); + button.getModel().setSelected(true); + isAnimated(bi, button); + // Default icon is not set => imageUpdate should return true for + // other icons if any + button.setIcon(null); + button.setPressedIcon(icon); + button.getModel().setPressed(true); + button.getModel().setArmed(true); + isAnimated(bi, button); + }); + } + + private static void isAnimated(BufferedImage bi, JButton button) { + if (!button.imageUpdate(bi, ImageObserver.SOMEBITS, 0, 0, 1, 1)) { + throw new RuntimeException(); + } + } +} diff --git a/test/javax/swing/JMenuBar/MisplacedBorder/MisplacedBorder.java b/test/javax/swing/JMenuBar/MisplacedBorder/MisplacedBorder.java new file mode 100644 index 0000000000000000000000000000000000000000..43a7dc31533b857ed3edc3664ef273137ddce991 --- /dev/null +++ b/test/javax/swing/JMenuBar/MisplacedBorder/MisplacedBorder.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE; +import static javax.swing.UIManager.getInstalledLookAndFeels; + +/** + * @test + * @bug 8073795 + * @summary JMenuBar has incorrect border when the window is on retina display. + * @author Sergey Bylokhov + * @run main/othervm MisplacedBorder + * @run main/othervm -Dswing.metalTheme=steel MisplacedBorder + */ +public final class MisplacedBorder implements Runnable { + + public static final int W = 400; + public static final int H = 400; + + public static void main(final String[] args) throws Exception { + for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) { + SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); + SwingUtilities.invokeAndWait(new MisplacedBorder()); + } + System.out.println("Test passed"); + } + + @Override + public void run() { + final JMenuBar menubar = new JMenuBar(); + menubar.add(new JMenu("")); + menubar.add(new JMenu("")); + final JFrame frame = new JFrame(); + frame.setUndecorated(true); + frame.setJMenuBar(menubar); + frame.setSize(W / 3, H / 3); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + + // draw menu bar using standard order. + final BufferedImage bi1 = step1(menubar); + + // draw menu border on top of the menu bar, nothing should be changed. + final BufferedImage bi2 = step2(menubar); + frame.dispose(); + + for (int x = 0; x < W; ++x) { + for (int y = 0; y < H; ++y) { + if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { + try { + ImageIO.write(bi1, "png", new File("image1.png")); + ImageIO.write(bi2, "png", new File("image2.png")); + } catch (IOException e) { + e.printStackTrace(); + } + throw new RuntimeException("Failed: wrong color"); + } + } + } + } + + /** + * Draws standard JMenuBar. + */ + private BufferedImage step1(final JMenuBar menubar) { + final BufferedImage bi1 = new BufferedImage(W, H, TYPE_INT_ARGB_PRE); + final Graphics2D g2d = bi1.createGraphics(); + g2d.scale(2, 2); + g2d.setColor(Color.RED); + g2d.fillRect(0, 0, W, H); + menubar.paintAll(g2d); + g2d.dispose(); + return bi1; + } + + /** + * Draws standard JMenuBar and border on top of it. + */ + private BufferedImage step2(final JMenuBar menubar) { + final BufferedImage bi2 = new BufferedImage(W, H, TYPE_INT_ARGB_PRE); + final Graphics2D g2d2 = bi2.createGraphics(); + g2d2.scale(2, 2); + g2d2.setColor(Color.RED); + g2d2.fillRect(0, 0, W, H); + menubar.paintAll(g2d2); + menubar.getBorder().paintBorder(menubar, g2d2, menubar.getX(), menubar + .getX(), menubar.getWidth(), menubar.getHeight()); + g2d2.dispose(); + return bi2; + } + + private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + UnsupportedLookAndFeelException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java b/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java new file mode 100644 index 0000000000000000000000000000000000000000..59806a33a0af831077329ff7befa889ec6444f13 --- /dev/null +++ b/test/javax/swing/SwingUtilities/TestBadBreak/TestBadBreak.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; + +import static java.awt.image.BufferedImage.TYPE_INT_ARGB; + +/** + * @test + * @bug 8015085 + * @summary Shortening via " ... " is broken for Strings containing a combining + * diaeresis. + * @author Sergey Bylokhov + */ +public class TestBadBreak { + + static JFrame frame; + static Robot robot; + static final String withCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/a\u0308" ; + static final String withoutCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/\u00E4" ; + + public static void main(final String[] args) throws Exception { + robot = new Robot(); + final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB); + final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB); + test(withCombiningDiaeresis, bi1); + test(withoutCombiningDiaeresis, bi2); + for (int x = 0; x < bi1.getWidth(); ++x) { + for (int y = 0; y < bi1.getHeight(); ++y) { + if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { + ImageIO.write(bi1, "png", new File("image1.png")); + ImageIO.write(bi2, "png", new File("image2.png")); + throw new RuntimeException("Wrong color"); + } + } + } + } + + private static void test(final String text, final BufferedImage i1) + throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame(); + final JLabel label = new JLabel(text) { + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2d = i1.createGraphics(); + super.paintComponent(g2d); + g2d.dispose(); + } + }; + frame.getContentPane().add(label); + frame.setBounds(200, 200, 200, 90); + } + }); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(() -> frame.setVisible(true)); + robot.waitForIdle(); + SwingUtilities.invokeAndWait(frame::dispose); + robot.waitForIdle(); + } +} diff --git a/test/javax/swing/UIDefaults/7180976/Pending.java b/test/javax/swing/UIDefaults/7180976/Pending.java new file mode 100644 index 0000000000000000000000000000000000000000..23ece57ebb0637915aac4bf0d5ab0358d7f182a2 --- /dev/null +++ b/test/javax/swing/UIDefaults/7180976/Pending.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, 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. + */ + +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +/** + * @test + * @bug 7180976 + * @author Sergey Bylokhov + */ +public final class Pending implements Runnable { + + private static volatile boolean passed; + + public static void main(final String[] args) throws Exception { + SwingUtilities.invokeLater(new Pending()); + Thread.sleep(10000); + if (!passed) { + throw new RuntimeException("Test failed"); + } + } + + @Override + public void run() { + UIManager.put("foobar", "Pending"); + UIManager.get("foobar"); + passed = true; + } +} \ No newline at end of file diff --git a/test/javax/swing/text/html/parser/8074956/bug8074956.java b/test/javax/swing/text/html/parser/8074956/bug8074956.java new file mode 100644 index 0000000000000000000000000000000000000000..160e6dc1345abc9b682fc3e024bce220a3613730 --- /dev/null +++ b/test/javax/swing/text/html/parser/8074956/bug8074956.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, 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. + */ + +import javax.swing.text.html.parser.ContentModel; +import javax.swing.text.html.parser.DTD; +import javax.swing.text.html.parser.Element; + +/* + * @test + * @bug 8074956 + * @author Alexey Ivanov + * @summary Tests correct handling of additional HTML elements in ContentModel + * @run main bug8074956 + */ +public class bug8074956 { + public static void main(String[] args) throws Exception { + final DTD html32 = DTD.getDTD("html32"); + ContentModel contentModel = new ContentModel('&', new ContentModel()); + + Element elem1 = html32.getElement("html-element"); + contentModel.first(elem1); + + Element elem2 = html32.getElement("test-element"); + // Shouldn't throw ArrayIndexOutOfBoundsException + contentModel.first(elem2); + } +} diff --git a/test/javax/xml/ws/8046817/GenerateEnumSchema.java b/test/javax/xml/ws/8046817/GenerateEnumSchema.java index cb70d2247aeb8d4f537afc2a89c0b9db56f5a973..4ef1f055d53fd2e998d87d017f3b70ecf3685ecc 100644 --- a/test/javax/xml/ws/8046817/GenerateEnumSchema.java +++ b/test/javax/xml/ws/8046817/GenerateEnumSchema.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -23,57 +23,83 @@ /* * @test - * @bug 8046817 - * @summary schemagen fails to generate xsd for enum types + * @bug 8046817 8073357 + * @summary schemagen fails to generate xsd for enum types. + * Check that order of Enum values is preserved. * @run main/othervm GenerateEnumSchema */ import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Scanner; +import java.util.stream.Collectors; public class GenerateEnumSchema { private static final String SCHEMA_OUTPUT_FILENAME = "schema1.xsd"; private static final File schemaOutputFile = new File(SCHEMA_OUTPUT_FILENAME); + private static final String[] expectedEnums = { + "\"FIRST\"", "\"ONE\"", "\"TWO\"", "\"THREE\"", + "\"FOUR\"", "\"FIVE\"", "\"SIX\"", "\"LAST\""}; + private static String schemaContent = ""; + + public static void main(String[] args) throws Exception { - public static void main(String[] args) throws Exception, IOException { //Check schema generation for class type runSchemaGen("TestClassType.java"); checkIfSchemaGenerated(); + readSchemaContent(); checkSchemaContent(""); checkSchemaContent(""); - schemaOutputFile.delete(); + //Check schema generation for enum type runSchemaGen("TestEnumType.java"); checkIfSchemaGenerated(); + readSchemaContent(); + //Check if Enum type schema is generated checkSchemaContent(""); - checkSchemaContent(""); - checkSchemaContent(""); - checkSchemaContent(""); + //Check the sequence of enum values order + checkEnumOrder(); schemaOutputFile.delete(); } + // Check if schema file successfully generated by schemagen private static void checkIfSchemaGenerated() { if (!schemaOutputFile.exists()) { throw new RuntimeException("FAIL:" + SCHEMA_OUTPUT_FILENAME + " was not generated by schemagen tool"); } } - private static void checkSchemaContent(String exp_token) throws FileNotFoundException { - System.out.print("Check if generated schema contains '" + exp_token + "' string: "); - try (Scanner scanner = new Scanner(schemaOutputFile)) { - if (scanner.findWithinHorizon(exp_token, 0) != null) { - System.out.println("OK"); - return; - } + //Read schema content from file + private static void readSchemaContent() throws Exception { + schemaContent = Files.lines(schemaOutputFile.toPath()).collect(Collectors.joining("")); + } + + // Check if schema file contains specific string + private static void checkSchemaContent(String expContent) { + System.out.print("Check if generated schema contains '" + expContent + "' string: "); + if (schemaContent.contains(expContent)) { + System.out.println("OK"); + return; } System.out.println("FAIL"); - throw new RuntimeException("The '" + exp_token + "' is not found in generated schema"); + throw new RuntimeException("The '" + expContent + "' is not found in generated schema"); + } + // Check if the generated schema contains all enum constants + // and their order is preserved + private static void checkEnumOrder() throws Exception { + int prevElem = -1; + for (String elem : expectedEnums) { + int curElem = schemaContent.indexOf(elem); + System.out.println(elem + " position = " + curElem); + if (curElem < prevElem) { + throw new RuntimeException("FAIL: Enum values order is incorrect or " + elem + " element is not found"); + } + prevElem = curElem; + } } private static String getClassFilePath(String filename) { diff --git a/test/javax/xml/ws/8046817/TestEnumType.java b/test/javax/xml/ws/8046817/TestEnumType.java index 785fb191c02ec84a57f8ed30cea1dd770441b801..728e1b7187ffbae9c48ed7f6f21305402b82e1ab 100644 --- a/test/javax/xml/ws/8046817/TestEnumType.java +++ b/test/javax/xml/ws/8046817/TestEnumType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, 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 @@ -25,5 +25,5 @@ import javax.xml.bind.annotation.XmlEnum; @XmlEnum(String.class) public enum TestEnumType { - ONE, TWO, THREE + FIRST, ONE, TWO, THREE, FOUR, FIVE, SIX, LAST } diff --git a/test/lib/testlibrary/jdk/testlibrary/OSInfo.java b/test/lib/testlibrary/jdk/testlibrary/OSInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..c32df1b6ccceb308c948c1016a44bfa62b09dfb0 --- /dev/null +++ b/test/lib/testlibrary/jdk/testlibrary/OSInfo.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) 1997, 2015, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package jdk.testlibrary; + +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; + +import static jdk.testlibrary.OSInfo.OSType.*; + +/** + * @author Pavel Porvatov + * copied to testlibrary by yan + */ +public class OSInfo { + public static enum OSType { + WINDOWS, + LINUX, + SOLARIS, + MACOSX, + UNKNOWN + } + + /* + The map windowsVersionMap must contain all windows version constants except WINDOWS_UNKNOWN, + and so the method getWindowsVersion() will return the constant for known OS. + It allows compare objects by "==" instead of "equals". + */ + public static final WindowsVersion WINDOWS_UNKNOWN = new WindowsVersion(-1, -1); + public static final WindowsVersion WINDOWS_95 = new WindowsVersion(4, 0); + public static final WindowsVersion WINDOWS_98 = new WindowsVersion(4, 10); + public static final WindowsVersion WINDOWS_ME = new WindowsVersion(4, 90); + public static final WindowsVersion WINDOWS_2000 = new WindowsVersion(5, 0); + public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1); + public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2); + public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0); + + private static final String OS_NAME = "os.name"; + private static final String OS_VERSION = "os.version"; + + private final static Map windowsVersionMap = new HashMap(); + + static { + windowsVersionMap.put(WINDOWS_95.toString(), WINDOWS_95); + windowsVersionMap.put(WINDOWS_98.toString(), WINDOWS_98); + windowsVersionMap.put(WINDOWS_ME.toString(), WINDOWS_ME); + windowsVersionMap.put(WINDOWS_2000.toString(), WINDOWS_2000); + windowsVersionMap.put(WINDOWS_XP.toString(), WINDOWS_XP); + windowsVersionMap.put(WINDOWS_2003.toString(), WINDOWS_2003); + windowsVersionMap.put(WINDOWS_VISTA.toString(), WINDOWS_VISTA); + } + + private static final PrivilegedAction osTypeAction = new PrivilegedAction() { + public OSType run() { + return getOSType(); + } + }; + + private OSInfo() { + // Don't allow to create instances + } + + /** + * Returns type of operating system. + */ + public static OSType getOSType() throws SecurityException { + String osName = System.getProperty(OS_NAME); + + if (osName != null) { + if (osName.contains("Windows")) { + return WINDOWS; + } + + if (osName.contains("Linux")) { + return LINUX; + } + + if (osName.contains("Solaris") || osName.contains("SunOS")) { + return SOLARIS; + } + + if (osName.contains("OS X")) { + return MACOSX; + } + + // determine another OS here + } + + return UNKNOWN; + } + + public static PrivilegedAction getOSTypeAction() { + return osTypeAction; + } + + public static WindowsVersion getWindowsVersion() throws SecurityException { + String osVersion = System.getProperty(OS_VERSION); + + if (osVersion == null) { + return WINDOWS_UNKNOWN; + } + + synchronized (windowsVersionMap) { + WindowsVersion result = windowsVersionMap.get(osVersion); + + if (result == null) { + // Try parse version and put object into windowsVersionMap + String[] arr = osVersion.split("\\."); + + if (arr.length == 2) { + try { + result = new WindowsVersion(Integer.parseInt(arr[0]), Integer.parseInt(arr[1])); + } catch (NumberFormatException e) { + return WINDOWS_UNKNOWN; + } + } else { + return WINDOWS_UNKNOWN; + } + + windowsVersionMap.put(osVersion, result); + } + + return result; + } + } + + public static class WindowsVersion implements Comparable { + private final int major; + + private final int minor; + + private WindowsVersion(int major, int minor) { + this.major = major; + this.minor = minor; + } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } + + public int compareTo(WindowsVersion o) { + int result = major - o.getMajor(); + + if (result == 0) { + result = minor - o.getMinor(); + } + + return result; + } + + public boolean equals(Object obj) { + return obj instanceof WindowsVersion && compareTo((WindowsVersion) obj) == 0; + } + + public int hashCode() { + return 31 * major + minor; + } + + public String toString() { + return major + "." + minor; + } + } +} + diff --git a/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java b/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java index d4cbd27fa9b93639cd135459b56620b5a4ef1145..d39c0ab2ce2102a64e6cf35a935ba7aea00b5862 100644 --- a/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java +++ b/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015 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 @@ -24,6 +24,8 @@ package jdk.testlibrary; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -394,4 +396,23 @@ public final class OutputAnalyzer { public int getExitValue() { return exitValue; } + + /** + * Get the contents of the output buffer (stdout and stderr) as list of strings. + * Output will be split by system property 'line.separator'. + * + * @return Contents of the output buffer as list of strings + */ + public List asLines() { + return asLines(getOutput()); + } + + private List asLines(String buffer) { + List l = new ArrayList<>(); + String[] a = buffer.split(Utils.NEW_LINE); + for (String string : a) { + l.add(string); + } + return l; + } } diff --git a/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java b/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java index c949e0f6c112929428e254910962b720398dd504..a5b956fea2bc5e7f3dab0cf65476eb691426d5f5 100644 --- a/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java +++ b/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -31,6 +31,7 @@ import java.lang.management.RuntimeMXBean; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.Map; @@ -41,6 +42,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Predicate; import java.util.function.Consumer; +import java.util.stream.Collectors; import sun.management.VMManagement; @@ -374,4 +376,40 @@ public final class ProcessTools { } return cmd.toString().trim(); } + + /** + * Executes a process, waits for it to finish, prints the process output + * to stdout, and returns the process output. + * + * The process will have exited before this method returns. + * + * @param cmds The command line to execute. + * @return The {@linkplain OutputAnalyzer} instance wrapping the process. + */ + public static OutputAnalyzer executeCommand(String... cmds) + throws Throwable { + String cmdLine = Arrays.stream(cmds).collect(Collectors.joining(" ")); + System.out.println("Command line: [" + cmdLine + "]"); + OutputAnalyzer analyzer = ProcessTools.executeProcess(cmds); + System.out.println(analyzer.getOutput()); + return analyzer; + } + + /** + * Executes a process, waits for it to finish, prints the process output + * to stdout and returns the process output. + * + * The process will have exited before this method returns. + * + * @param pb The ProcessBuilder to execute. + * @return The {@linkplain OutputAnalyzer} instance wrapping the process. + */ + public static OutputAnalyzer executeCommand(ProcessBuilder pb) + throws Throwable { + String cmdLine = pb.command().stream().collect(Collectors.joining(" ")); + System.out.println("Command line: [" + cmdLine + "]"); + OutputAnalyzer analyzer = ProcessTools.executeProcess(pb); + System.out.println(analyzer.getOutput()); + return analyzer; + } } diff --git a/test/sun/security/pkcs11/sslecc/CipherTest.java b/test/sun/security/pkcs11/sslecc/CipherTest.java index ae5091e0b09c5aadb31c3d4f6a3b0c93c50da2db..4ec23743b2a9f6f6bdea033d9fbebe23ea4e97e7 100644 --- a/test/sun/security/pkcs11/sslecc/CipherTest.java +++ b/test/sun/security/pkcs11/sslecc/CipherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -45,7 +45,7 @@ import javax.net.ssl.*; public class CipherTest { // use any available port for the server socket - static int serverPort = 0; + static volatile int serverPort = 0; final int THREADS; diff --git a/test/sun/security/pkcs11/sslecc/JSSEServer.java b/test/sun/security/pkcs11/sslecc/JSSEServer.java index 0d1002b5834128518e3f57c7a717e27bc0514140..af8d4b5a0884022b977e1a676b60cb3669c02c06 100644 --- a/test/sun/security/pkcs11/sslecc/JSSEServer.java +++ b/test/sun/security/pkcs11/sslecc/JSSEServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2015, 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 @@ -42,7 +42,7 @@ class JSSEServer extends CipherTest.Server { serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom); SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory(); - serverSocket = (SSLServerSocket)factory.createServerSocket(cipherTest.serverPort); + serverSocket = (SSLServerSocket)factory.createServerSocket(0); cipherTest.serverPort = serverSocket.getLocalPort(); serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites()); serverSocket.setWantClientAuth(true);