From a12feb33eb99ba1f83c11814c5c6fa4af02feb57 Mon Sep 17 00:00:00 2001 From: Rocky Sloan Date: Tue, 24 Jun 2014 10:47:30 +0400 Subject: [PATCH 01/30] 8044256: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.nimbus Reviewed-by: alexsch --- .../javax/swing/plaf/nimbus/AbstractRegionPainter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java b/jdk/src/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java index 15a10fbf5f9..c41d9247138 100644 --- a/jdk/src/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java +++ b/jdk/src/share/classes/javax/swing/plaf/nimbus/AbstractRegionPainter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -421,6 +421,13 @@ public abstract class AbstractRegionPainter implements Painter { * @param property The name of a bean style property or client property * @param defaultColor The color to return if no color was obtained from * the component. + * @param saturationOffset additively modifies the HSB saturation component + * of the color returned (ignored if default color is returned). + * @param brightnessOffset additively modifies the HSB brightness component + * of the color returned (ignored if default color is returned). + * @param alphaOffset additively modifies the ARGB alpha component of the + * color returned (ignored if default color is returned). + * * @return The color that was obtained from the component or defaultColor */ protected final Color getComponentColor(JComponent c, String property, From 0a5b921c130faff305b9bd1674a82b797f91ed79 Mon Sep 17 00:00:00 2001 From: Shanliang Jiang Date: Tue, 24 Jun 2014 11:09:57 +0200 Subject: [PATCH 02/30] 8038321: RMIConnector_NPETest.java can't start rmid if running on fastdebug or Solaris-sparc Reviewed-by: sla, jbachorik --- .../remote/mandatory/connection/RMIConnector_NPETest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java b/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java index ae94557e44d..1e246514dcd 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/RMIConnector_NPETest.java @@ -38,7 +38,7 @@ import javax.management.remote.rmi.*; public class RMIConnector_NPETest { public static void main(String argv[]) throws Exception { RMID rmid = RMID.createRMID(); - rmid.start(); + rmid.start(Long.MAX_VALUE); int rmidPort = rmid.getPort(); Exception failureCause = null; RMIConnector agent = null; From 18728f8cb91a212a357f60df5512baa1887d7d8a Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Tue, 24 Jun 2014 10:25:56 +0100 Subject: [PATCH 03/30] 8047674: java/net/URLPermission/nstest/lookup.sh NoClassDefFoundError when run in concurrent mode Reviewed-by: alanb --- jdk/test/java/net/URLPermission/nstest/lookup.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jdk/test/java/net/URLPermission/nstest/lookup.sh b/jdk/test/java/net/URLPermission/nstest/lookup.sh index 33afed78ba6..eefd73cae12 100644 --- a/jdk/test/java/net/URLPermission/nstest/lookup.sh +++ b/jdk/test/java/net/URLPermission/nstest/lookup.sh @@ -24,9 +24,9 @@ # @test # @library /lib/testlibrary +# @build jdk.testlibrary.* # @compile -XDignore.symbol.file=true SimpleNameService.java # LookupTest.java SimpleNameServiceDescriptor.java -# @build jdk.testlibrary.* # @run shell/timeout=50 lookup.sh # @@ -42,8 +42,7 @@ Windows_* | CYGWIN*) ;; esac - -port=`${TESTJAVA}/bin/java -cp ${TESTCLASSES} LookupTest -getport` +port=`${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} LookupTest -getport` cat << POLICY > policy grant { @@ -60,4 +59,4 @@ POLICY ${TESTJAVA}/bin/java ${TESTVMOPTS} \ -Djava.security.policy=file:./policy \ -Dsun.net.spi.nameservice.provider.1=simple,sun \ - -cp ${TESTCLASSES}${PS}${TESTSRC} LookupTest -runtest ${port} + -cp ${TESTCLASSPATH}${PS}${TESTSRC} LookupTest -runtest ${port} From 825d9ee98530a01cee857ce965a8109ee9acefe6 Mon Sep 17 00:00:00 2001 From: Alexander Stepanov Date: Tue, 24 Jun 2014 16:57:02 +0400 Subject: [PATCH 04/30] 8043967: Fix doclint warnings for java.awt Reviewed-by: pchelko --- jdk/src/share/classes/java/awt/AWTEvent.java | 7 +- .../classes/java/awt/AWTEventMulticaster.java | 81 ++++++++- .../share/classes/java/awt/AWTKeyStroke.java | 1 + .../classes/java/awt/AlphaComposite.java | 6 +- .../share/classes/java/awt/BorderLayout.java | 8 +- jdk/src/share/classes/java/awt/Button.java | 4 +- jdk/src/share/classes/java/awt/Checkbox.java | 5 +- .../share/classes/java/awt/CheckboxGroup.java | 11 +- jdk/src/share/classes/java/awt/Choice.java | 15 +- jdk/src/share/classes/java/awt/Component.java | 157 +++++++++++++++++- .../java/awt/ComponentOrientation.java | 10 +- jdk/src/share/classes/java/awt/Container.java | 17 +- jdk/src/share/classes/java/awt/Cursor.java | 7 +- .../share/classes/java/awt/DisplayMode.java | 4 +- .../share/classes/java/awt/EventQueue.java | 3 + jdk/src/share/classes/java/awt/Frame.java | 8 +- .../classes/java/awt/GraphicsEnvironment.java | 2 + .../share/classes/java/awt/GridBagLayout.java | 39 +++-- .../classes/java/awt/HeadlessException.java | 16 +- .../classes/java/awt/ItemSelectable.java | 4 +- .../java/awt/KeyboardFocusManager.java | 2 + jdk/src/share/classes/java/awt/Label.java | 6 +- .../share/classes/java/awt/LayoutManager.java | 11 +- .../classes/java/awt/LayoutManager2.java | 12 +- jdk/src/share/classes/java/awt/List.java | 60 ++++++- .../share/classes/java/awt/MediaTracker.java | 10 +- jdk/src/share/classes/java/awt/Menu.java | 7 +- jdk/src/share/classes/java/awt/MenuBar.java | 14 +- .../share/classes/java/awt/MenuComponent.java | 3 +- .../share/classes/java/awt/MenuContainer.java | 17 +- jdk/src/share/classes/java/awt/MenuItem.java | 15 +- .../share/classes/java/awt/PrintGraphics.java | 4 +- jdk/src/share/classes/java/awt/PrintJob.java | 10 +- jdk/src/share/classes/java/awt/Robot.java | 15 +- .../share/classes/java/awt/ScrollPane.java | 9 +- jdk/src/share/classes/java/awt/Scrollbar.java | 19 ++- jdk/src/share/classes/java/awt/TextArea.java | 31 +++- .../share/classes/java/awt/TextComponent.java | 5 +- jdk/src/share/classes/java/awt/TextField.java | 22 ++- jdk/src/share/classes/java/awt/Toolkit.java | 26 ++- jdk/src/share/classes/java/awt/Window.java | 11 +- 41 files changed, 634 insertions(+), 80 deletions(-) diff --git a/jdk/src/share/classes/java/awt/AWTEvent.java b/jdk/src/share/classes/java/awt/AWTEvent.java index db51f2c1088..4a935f39848 100644 --- a/jdk/src/share/classes/java/awt/AWTEvent.java +++ b/jdk/src/share/classes/java/awt/AWTEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -388,6 +388,8 @@ public abstract class AWTEvent extends EventObject { /** * Returns the event type. + * + * @return the event's type id */ public int getID() { return id; @@ -446,6 +448,9 @@ public abstract class AWTEvent extends EventObject { /** * Returns whether this event has been consumed. + * + * @return {@code true} if this event has been consumed; + * otherwise {@code false} */ protected boolean isConsumed() { return consumed; diff --git a/jdk/src/share/classes/java/awt/AWTEventMulticaster.java b/jdk/src/share/classes/java/awt/AWTEventMulticaster.java index de51ab1c0b4..112dbb62ace 100644 --- a/jdk/src/share/classes/java/awt/AWTEventMulticaster.java +++ b/jdk/src/share/classes/java/awt/AWTEventMulticaster.java @@ -110,7 +110,15 @@ public class AWTEventMulticaster implements TextListener, InputMethodListener, HierarchyListener, HierarchyBoundsListener, MouseWheelListener { - protected final EventListener a, b; + /** + * A variable in the event chain (listener-a) + */ + protected final EventListener a; + + /** + * A variable in the event chain (listener-b) + */ + protected final EventListener b; /** * Creates an event multicaster instance which chains listener-a @@ -537,6 +545,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a component-listener-a * @param b component-listener-b + * @return the resulting listener */ public static ComponentListener add(ComponentListener a, ComponentListener b) { return (ComponentListener)addInternal(a, b); @@ -547,6 +556,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a container-listener-a * @param b container-listener-b + * @return the resulting listener */ public static ContainerListener add(ContainerListener a, ContainerListener b) { return (ContainerListener)addInternal(a, b); @@ -557,6 +567,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a focus-listener-a * @param b focus-listener-b + * @return the resulting listener */ public static FocusListener add(FocusListener a, FocusListener b) { return (FocusListener)addInternal(a, b); @@ -567,6 +578,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a key-listener-a * @param b key-listener-b + * @return the resulting listener */ public static KeyListener add(KeyListener a, KeyListener b) { return (KeyListener)addInternal(a, b); @@ -577,6 +589,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a mouse-listener-a * @param b mouse-listener-b + * @return the resulting listener */ public static MouseListener add(MouseListener a, MouseListener b) { return (MouseListener)addInternal(a, b); @@ -587,6 +600,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a mouse-motion-listener-a * @param b mouse-motion-listener-b + * @return the resulting listener */ public static MouseMotionListener add(MouseMotionListener a, MouseMotionListener b) { return (MouseMotionListener)addInternal(a, b); @@ -597,6 +611,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a window-listener-a * @param b window-listener-b + * @return the resulting listener */ public static WindowListener add(WindowListener a, WindowListener b) { return (WindowListener)addInternal(a, b); @@ -607,6 +622,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param a window-state-listener-a * @param b window-state-listener-b + * @return the resulting listener * @since 1.4 */ @SuppressWarnings("overloads") @@ -620,6 +636,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param a window-focus-listener-a * @param b window-focus-listener-b + * @return the resulting listener * @since 1.4 */ public static WindowFocusListener add(WindowFocusListener a, @@ -632,6 +649,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a action-listener-a * @param b action-listener-b + * @return the resulting listener */ @SuppressWarnings("overloads") public static ActionListener add(ActionListener a, ActionListener b) { @@ -643,6 +661,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a item-listener-a * @param b item-listener-b + * @return the resulting listener */ @SuppressWarnings("overloads") public static ItemListener add(ItemListener a, ItemListener b) { @@ -654,11 +673,21 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a adjustment-listener-a * @param b adjustment-listener-b + * @return the resulting listener */ @SuppressWarnings("overloads") public static AdjustmentListener add(AdjustmentListener a, AdjustmentListener b) { return (AdjustmentListener)addInternal(a, b); } + + /** + * Adds text-listener-a with text-listener-b and + * returns the resulting multicast listener. + * + * @param a text-listener-a + * @param b text-listener-b + * @return the resulting listener + */ @SuppressWarnings("overloads") public static TextListener add(TextListener a, TextListener b) { return (TextListener)addInternal(a, b); @@ -669,6 +698,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a input-method-listener-a * @param b input-method-listener-b + * @return the resulting listener */ public static InputMethodListener add(InputMethodListener a, InputMethodListener b) { return (InputMethodListener)addInternal(a, b); @@ -679,6 +709,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a hierarchy-listener-a * @param b hierarchy-listener-b + * @return the resulting listener * @since 1.3 */ @SuppressWarnings("overloads") @@ -691,6 +722,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a hierarchy-bounds-listener-a * @param b hierarchy-bounds-listener-b + * @return the resulting listener * @since 1.3 */ public static HierarchyBoundsListener add(HierarchyBoundsListener a, HierarchyBoundsListener b) { @@ -702,6 +734,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param a mouse-wheel-listener-a * @param b mouse-wheel-listener-b + * @return the resulting listener * @since 1.4 */ @SuppressWarnings("overloads") @@ -715,6 +748,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l component-listener-l * @param oldl the component-listener being removed + * @return the resulting listener */ public static ComponentListener remove(ComponentListener l, ComponentListener oldl) { return (ComponentListener) removeInternal(l, oldl); @@ -725,6 +759,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l container-listener-l * @param oldl the container-listener being removed + * @return the resulting listener */ public static ContainerListener remove(ContainerListener l, ContainerListener oldl) { return (ContainerListener) removeInternal(l, oldl); @@ -735,6 +770,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l focus-listener-l * @param oldl the focus-listener being removed + * @return the resulting listener */ public static FocusListener remove(FocusListener l, FocusListener oldl) { return (FocusListener) removeInternal(l, oldl); @@ -745,6 +781,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l key-listener-l * @param oldl the key-listener being removed + * @return the resulting listener */ public static KeyListener remove(KeyListener l, KeyListener oldl) { return (KeyListener) removeInternal(l, oldl); @@ -755,6 +792,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l mouse-listener-l * @param oldl the mouse-listener being removed + * @return the resulting listener */ public static MouseListener remove(MouseListener l, MouseListener oldl) { return (MouseListener) removeInternal(l, oldl); @@ -765,6 +803,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param l mouse-motion-listener-l * @param oldl the mouse-motion-listener being removed + * @return the resulting listener */ public static MouseMotionListener remove(MouseMotionListener l, MouseMotionListener oldl) { return (MouseMotionListener) removeInternal(l, oldl); @@ -775,6 +814,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l window-listener-l * @param oldl the window-listener being removed + * @return the resulting listener */ public static WindowListener remove(WindowListener l, WindowListener oldl) { return (WindowListener) removeInternal(l, oldl); @@ -785,6 +825,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param l window-state-listener-l * @param oldl the window-state-listener being removed + * @return the resulting listener * @since 1.4 */ @SuppressWarnings("overloads") @@ -798,6 +839,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param l window-focus-listener-l * @param oldl the window-focus-listener being removed + * @return the resulting listener * @since 1.4 */ public static WindowFocusListener remove(WindowFocusListener l, @@ -810,6 +852,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l action-listener-l * @param oldl the action-listener being removed + * @return the resulting listener */ @SuppressWarnings("overloads") public static ActionListener remove(ActionListener l, ActionListener oldl) { @@ -821,6 +864,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l item-listener-l * @param oldl the item-listener being removed + * @return the resulting listener */ @SuppressWarnings("overloads") public static ItemListener remove(ItemListener l, ItemListener oldl) { @@ -832,11 +876,21 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l adjustment-listener-l * @param oldl the adjustment-listener being removed + * @return the resulting listener */ @SuppressWarnings("overloads") public static AdjustmentListener remove(AdjustmentListener l, AdjustmentListener oldl) { return (AdjustmentListener) removeInternal(l, oldl); } + + /** + * Removes the old text-listener from text-listener-l and + * returns the resulting multicast listener. + * + * @param l text-listener-l + * @param oldl the text-listener being removed + * @return the resulting listener + */ @SuppressWarnings("overloads") public static TextListener remove(TextListener l, TextListener oldl) { return (TextListener) removeInternal(l, oldl); @@ -847,6 +901,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l input-method-listener-l * @param oldl the input-method-listener being removed + * @return the resulting listener */ public static InputMethodListener remove(InputMethodListener l, InputMethodListener oldl) { return (InputMethodListener) removeInternal(l, oldl); @@ -857,6 +912,7 @@ public class AWTEventMulticaster implements * returns the resulting multicast listener. * @param l hierarchy-listener-l * @param oldl the hierarchy-listener being removed + * @return the resulting listener * @since 1.3 */ @SuppressWarnings("overloads") @@ -870,6 +926,7 @@ public class AWTEventMulticaster implements * listener. * @param l hierarchy-bounds-listener-l * @param oldl the hierarchy-bounds-listener being removed + * @return the resulting listener * @since 1.3 */ public static HierarchyBoundsListener remove(HierarchyBoundsListener l, HierarchyBoundsListener oldl) { @@ -881,6 +938,7 @@ public class AWTEventMulticaster implements * and returns the resulting multicast listener. * @param l mouse-wheel-listener-l * @param oldl the mouse-wheel-listener being removed + * @return the resulting listener * @since 1.4 */ @SuppressWarnings("overloads") @@ -898,6 +956,7 @@ public class AWTEventMulticaster implements * a new AWTEventMulticaster instance which chains a with b. * @param a event listener-a * @param b event listener-b + * @return the resulting listener */ protected static EventListener addInternal(EventListener a, EventListener b) { if (a == null) return b; @@ -915,6 +974,7 @@ public class AWTEventMulticaster implements * Else, returns listener l. * @param l the listener being removed from * @param oldl the listener being removed + * @return the resulting listener */ protected static EventListener removeInternal(EventListener l, EventListener oldl) { if (l == oldl || l == null) { @@ -927,9 +987,14 @@ public class AWTEventMulticaster implements } - /* Serialization support. - */ - + /** + * Serialization support. Saves all Serializable listeners + * to a serialization stream. + * + * @param s the stream to save to + * @param k a prefix stream to put before each serializable listener + * @throws IOException if serialization fails + */ protected void saveInternal(ObjectOutputStream s, String k) throws IOException { if (a instanceof AWTEventMulticaster) { ((AWTEventMulticaster)a).saveInternal(s, k); @@ -948,6 +1013,14 @@ public class AWTEventMulticaster implements } } + /** + * Saves a Serializable listener chain to a serialization stream. + * + * @param s the stream to save to + * @param k a prefix stream to put before each serializable listener + * @param l the listener chain to save + * @throws IOException if serialization fails + */ protected static void save(ObjectOutputStream s, String k, EventListener l) throws IOException { if (l == null) { return; diff --git a/jdk/src/share/classes/java/awt/AWTKeyStroke.java b/jdk/src/share/classes/java/awt/AWTKeyStroke.java index 4be729b8c89..681113a07db 100644 --- a/jdk/src/share/classes/java/awt/AWTKeyStroke.java +++ b/jdk/src/share/classes/java/awt/AWTKeyStroke.java @@ -802,6 +802,7 @@ public class AWTKeyStroke implements Serializable { * AWTKeyStroke) which is equal to this instance. * * @return a cached instance which is equal to this instance + * @throws java.io.ObjectStreamException if a serialization problem occurs */ protected Object readResolve() throws java.io.ObjectStreamException { synchronized (AWTKeyStroke.class) { diff --git a/jdk/src/share/classes/java/awt/AlphaComposite.java b/jdk/src/share/classes/java/awt/AlphaComposite.java index f08ea2b47bf..542d2884a01 100644 --- a/jdk/src/share/classes/java/awt/AlphaComposite.java +++ b/jdk/src/share/classes/java/awt/AlphaComposite.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -621,7 +621,9 @@ public final class AlphaComposite implements Composite { /** * Creates an AlphaComposite object with the specified rule. + * * @param rule the compositing rule + * @return the {@code AlphaComposite} object created * @throws IllegalArgumentException if rule is not one of * the following: {@link #CLEAR}, {@link #SRC}, {@link #DST}, * {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN}, @@ -664,10 +666,12 @@ public final class AlphaComposite implements Composite { * the constant alpha to multiply with the alpha of the source. * The source is multiplied with the specified alpha before being composited * with the destination. + * * @param rule the compositing rule * @param alpha the constant alpha to be multiplied with the alpha of * the source. alpha must be a floating point number in the * inclusive range [0.0, 1.0]. + * @return the {@code AlphaComposite} object created * @throws IllegalArgumentException if * alpha is less than 0.0 or greater than 1.0, or if * rule is not one of diff --git a/jdk/src/share/classes/java/awt/BorderLayout.java b/jdk/src/share/classes/java/awt/BorderLayout.java index b2f7e25fe19..fd891bc371b 100644 --- a/jdk/src/share/classes/java/awt/BorderLayout.java +++ b/jdk/src/share/classes/java/awt/BorderLayout.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -367,6 +367,8 @@ public class BorderLayout implements LayoutManager2, /** * Returns the horizontal gap between components. + * + * @return the horizontal gap between components * @since 1.1 */ public int getHgap() { @@ -375,6 +377,7 @@ public class BorderLayout implements LayoutManager2, /** * Sets the horizontal gap between components. + * * @param hgap the horizontal gap between components * @since 1.1 */ @@ -384,6 +387,8 @@ public class BorderLayout implements LayoutManager2, /** * Returns the vertical gap between components. + * + * @return the vertical gap between components * @since 1.1 */ public int getVgap() { @@ -392,6 +397,7 @@ public class BorderLayout implements LayoutManager2, /** * Sets the vertical gap between components. + * * @param vgap the vertical gap between components * @since 1.1 */ diff --git a/jdk/src/share/classes/java/awt/Button.java b/jdk/src/share/classes/java/awt/Button.java index 08e569d446a..cc01947a9f1 100644 --- a/jdk/src/share/classes/java/awt/Button.java +++ b/jdk/src/share/classes/java/awt/Button.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -238,6 +238,8 @@ public class Button extends Component implements Accessible { * Returns the command name of the action event fired by this button. * If the command name is null (default) then this method * returns the label of the button. + * + * @return the action command name (or label) for this button */ public String getActionCommand() { return (actionCommand == null? label : actionCommand); diff --git a/jdk/src/share/classes/java/awt/Checkbox.java b/jdk/src/share/classes/java/awt/Checkbox.java index 8e8b5dd226a..021b2fcebaa 100644 --- a/jdk/src/share/classes/java/awt/Checkbox.java +++ b/jdk/src/share/classes/java/awt/Checkbox.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -713,6 +713,9 @@ public class Checkbox extends Component implements ItemSelectable, Accessible { */ private static final long serialVersionUID = 7881579233144754107L; + /** + * Constructor for {@code AccessibleAWTCheckbox} + */ public AccessibleAWTCheckbox() { super(); Checkbox.this.addItemListener(this); diff --git a/jdk/src/share/classes/java/awt/CheckboxGroup.java b/jdk/src/share/classes/java/awt/CheckboxGroup.java index a34c337b712..15e91c4d2a0 100644 --- a/jdk/src/share/classes/java/awt/CheckboxGroup.java +++ b/jdk/src/share/classes/java/awt/CheckboxGroup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -91,6 +91,10 @@ public class CheckboxGroup implements java.io.Serializable { } /** + * Returns the current choice from this check box group + * or {@code null} if none of checkboxes are selected. + * + * @return the selected checkbox * @deprecated As of JDK version 1.1, * replaced by getSelectedCheckbox(). */ @@ -120,6 +124,11 @@ public class CheckboxGroup implements java.io.Serializable { } /** + * Sets the currently selected check box in this group + * to be the specified check box and unsets all others. + * + * @param box the {@code Checkbox} to set as the + * current selection. * @deprecated As of JDK version 1.1, * replaced by setSelectedCheckbox(Checkbox). */ diff --git a/jdk/src/share/classes/java/awt/Choice.java b/jdk/src/share/classes/java/awt/Choice.java index 1d79dc71831..a6f20718321 100644 --- a/jdk/src/share/classes/java/awt/Choice.java +++ b/jdk/src/share/classes/java/awt/Choice.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -156,6 +156,7 @@ public class Choice extends Component implements ItemSelectable, Accessible { /** * Returns the number of items in this Choice menu. + * * @return the number of items in this Choice menu * @see #getItem * @since 1.1 @@ -165,6 +166,9 @@ public class Choice extends Component implements ItemSelectable, Accessible { } /** + * Returns the number of items in this {@code Choice} menu. + * + * @return the number of items in this {@code Choice} menu * @deprecated As of JDK version 1.1, * replaced by getItemCount(). */ @@ -176,8 +180,10 @@ public class Choice extends Component implements ItemSelectable, Accessible { /** * Gets the string at the specified index in this * Choice menu. - * @param index the index at which to begin - * @see #getItemCount + * + * @param index the index at which to begin + * @return the item at the specified index + * @see #getItemCount */ public String getItem(int index) { return getItemImpl(index); @@ -759,6 +765,9 @@ public class Choice extends Component implements ItemSelectable, Accessible { */ private static final long serialVersionUID = 7175603582428509322L; + /** + * Constructor for {@code AccessibleAWTChoice} + */ public AccessibleAWTChoice() { super(); } diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index 8e328a5e586..b062cc718b7 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -1075,6 +1075,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @deprecated As of JDK version 1.1, * programs should not directly manipulate peers; * replaced by boolean isDisplayable(). + * @return the peer for this component */ @Deprecated public ComponentPeer getPeer() { @@ -1132,6 +1133,8 @@ public abstract class Component implements ImageObserver, MenuContainer, /** * Gets the DropTarget associated with this * Component. + * + * @return the drop target */ public synchronized DropTarget getDropTarget() { return dropTarget; } @@ -1498,6 +1501,11 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Enables or disables this component. + * + * @param b {@code true} to enable this component; + * otherwise {@code false} + * * @deprecated As of JDK version 1.1, * replaced by setEnabled(boolean). */ @@ -1656,6 +1664,11 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Makes this component visible or invisible. + * + * @param b {@code true} to make this component visible; + * otherwise {@code false} + * * @deprecated As of JDK version 1.1, * replaced by setVisible(boolean). */ @@ -2068,6 +2081,9 @@ public abstract class Component implements ImageObserver, MenuContainer, /** + * Returns the location of this component's top left corner. + * + * @return the location of this component's top left corner * @deprecated As of JDK version 1.1, * replaced by getLocation(). */ @@ -2102,6 +2118,13 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Moves this component to a new location. + * + * @param x the x-coordinate of the new location's + * top-left corner in the parent's coordinate space + * @param y the y-coordinate of the new location's + * top-left corner in the parent's coordinate space + * * @deprecated As of JDK version 1.1, * replaced by setLocation(int, int). */ @@ -2150,6 +2173,11 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Returns the size of this component in the form of a + * {@code Dimension} object. + * + * @return the {@code Dimension} object that indicates the + * size of this component * @deprecated As of JDK version 1.1, * replaced by getSize(). */ @@ -2177,6 +2205,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Resizes this component. + * + * @param width the new width of the component + * @param height the new height of the component * @deprecated As of JDK version 1.1, * replaced by setSize(int, int). */ @@ -2208,6 +2240,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Resizes this component so that it has width {@code d.width} + * and height {@code d.height}. + * + * @param d the new size of this component * @deprecated As of JDK version 1.1, * replaced by setSize(Dimension). */ @@ -2231,6 +2267,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Returns the bounding rectangle of this component. + * + * @return the bounding rectangle for this component * @deprecated As of JDK version 1.1, * replaced by getBounds(). */ @@ -2265,6 +2304,13 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Reshapes the bounding rectangle for this component. + * + * @param x the x coordinate of the upper left corner of the rectangle + * @param y the y coordinate of the upper left corner of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * * @deprecated As of JDK version 1.1, * replaced by setBounds(int, int, int, int). */ @@ -2631,6 +2677,9 @@ public abstract class Component implements ImageObserver, MenuContainer, /** + * Returns the component's preferred size. + * + * @return the component's preferred size * @deprecated As of JDK version 1.1, * replaced by getPreferredSize(). */ @@ -2701,6 +2750,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Returns the minimum size of this component. + * + * @return the minimum size of this component * @deprecated As of JDK version 1.1, * replaced by getMinimumSize(). */ @@ -2781,6 +2833,8 @@ public abstract class Component implements ImageObserver, MenuContainer, * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. + * + * @return the horizontal alignment of this component */ public float getAlignmentX() { return CENTER_ALIGNMENT; @@ -2792,6 +2846,8 @@ public abstract class Component implements ImageObserver, MenuContainer, * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. + * + * @return the vertical alignment of this component */ public float getAlignmentY() { return CENTER_ALIGNMENT; @@ -3157,8 +3213,10 @@ public abstract class Component implements ImageObserver, MenuContainer, * not have a cursor set, the cursor of its parent is returned. * If no cursor is set in the entire hierarchy, * Cursor.DEFAULT_CURSOR is returned. + * + * @return the cursor for this component * @see #setCursor - * @since 1.1 + * @since 1.1 */ public Cursor getCursor() { return getCursor_NoClientCode(); @@ -3942,6 +4000,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * a lost state. */ protected boolean validatedContents; // = false + /** * Size of the back buffers. (Note: these fields were added in 6.0 * but kept package-private to avoid exposing them in the spec. @@ -3949,7 +4008,15 @@ public abstract class Component implements ImageObserver, MenuContainer, * protected when they were introduced in 1.4, but now we just have * to live with that decision.) */ + + /** + * The width of the back buffers + */ int width; + + /** + * The height of the back buffers + */ int height; /** @@ -4304,6 +4371,8 @@ public abstract class Component implements ImageObserver, MenuContainer, /** * Creates the back buffers + * + * @param numBuffers the number of buffers to create */ protected void createBackBuffers(int numBuffers) { if (numBuffers == 0) { @@ -4593,6 +4662,9 @@ public abstract class Component implements ImageObserver, MenuContainer, * better performance is desired, or if page-flipping is used as the * buffer strategy. * + * @param ignoreRepaint {@code true} if the paint messages from the OS + * should be ignored; otherwise {@code false} + * * @since 1.4 * @see #getIgnoreRepaint * @see Canvas#createBufferStrategy @@ -4619,8 +4691,11 @@ public abstract class Component implements ImageObserver, MenuContainer, * Checks whether this component "contains" the specified point, * where x and y are defined to be * relative to the coordinate system of this component. + * * @param x the x coordinate of the point * @param y the y coordinate of the point + * @return {@code true} if the point is within the component; + * otherwise {@code false} * @see #getComponentAt(int, int) * @since 1.1 */ @@ -4629,6 +4704,12 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Checks whether the point is inside of this component. + * + * @param x the x coordinate of the point + * @param y the y coordinate of the point + * @return {@code true} if the point is within the component; + * otherwise {@code false} * @deprecated As of JDK version 1.1, * replaced by contains(int, int). */ @@ -4641,7 +4722,10 @@ public abstract class Component implements ImageObserver, MenuContainer, * Checks whether this component "contains" the specified point, * where the point's x and y coordinates are defined * to be relative to the coordinate system of this component. + * * @param p the point + * @return {@code true} if the point is within the component; + * otherwise {@code false} * @throws NullPointerException if {@code p} is {@code null} * @see #getComponentAt(Point) * @since 1.1 @@ -4676,6 +4760,13 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * Returns the component occupying the position specified (this component, + * or immediate child component, or null if neither + * of the first two occupies the location). + * + * @param x the x coordinate to search for components at + * @param y the y coordinate to search for components at + * @return the component at the specified location or {@code null} * @deprecated As of JDK version 1.1, * replaced by getComponentAt(int, int). */ @@ -4687,15 +4778,17 @@ public abstract class Component implements ImageObserver, MenuContainer, /** * Returns the component or subcomponent that contains the * specified point. - * @param p the point - * @see java.awt.Component#contains - * @since 1.1 + * @param p the point + * @return the component at the specified location or {@code null} + * @see java.awt.Component#contains + * @since 1.1 */ public Component getComponentAt(Point p) { return getComponentAt(p.x, p.y); } /** + * @param e the event to deliver * @deprecated As of JDK version 1.1, * replaced by dispatchEvent(AWTEvent e). */ @@ -6746,6 +6839,8 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @return {@code true} if the event was handled, {@code false} otherwise * @deprecated As of JDK version 1.1 * replaced by processEvent(AWTEvent). */ @@ -6789,6 +6884,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseEvent(MouseEvent). */ @@ -6798,6 +6897,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseMotionEvent(MouseEvent). */ @@ -6807,6 +6910,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseEvent(MouseEvent). */ @@ -6816,6 +6923,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseMotionEvent(MouseEvent). */ @@ -6825,6 +6936,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseEvent(MouseEvent). */ @@ -6834,6 +6949,10 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param x the x coordinate + * @param y the y coordinate + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processMouseEvent(MouseEvent). */ @@ -6843,6 +6962,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param key the key pressed + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processKeyEvent(KeyEvent). */ @@ -6852,6 +6974,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param key the key pressed + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processKeyEvent(KeyEvent). */ @@ -6861,6 +6986,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param what the object acted on + * @return {@code false} * @deprecated As of JDK version 1.1, * should register this component as ActionListener on component * which fires action events. @@ -7070,6 +7198,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param what the object focused + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processFocusEvent(FocusEvent). */ @@ -7079,6 +7210,9 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** + * @param evt the event to handle + * @param what the object focused + * @return {@code false} * @deprecated As of JDK version 1.1, * replaced by processFocusEvent(FocusEvent). */ @@ -8390,6 +8524,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * Returns an array of all the listeners which have been associated * with the named property. * + * @param propertyName the property name * @return all of the PropertyChangeListeners associated with * the named property; if no such listeners have been added or * if propertyName is null, an empty @@ -8400,8 +8535,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #getPropertyChangeListeners * @since 1.4 */ - public PropertyChangeListener[] getPropertyChangeListeners( - String propertyName) { + public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { synchronized (getObjectLock()) { if (changeSupport == null) { return new PropertyChangeListener[0]; @@ -8879,6 +9013,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * This method changes layout-related information, and therefore, * invalidates the component hierarchy. * + * @param o the orientation to be set * * @see ComponentOrientation * @see #invalidate @@ -8906,6 +9041,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * subclasses that wish to respect orientation should call this method to * get the component's orientation before performing layout or drawing. * + * @return the orientation to order the elements or text * @see ComponentOrientation * * @author Laura Werner, IBM @@ -9063,7 +9199,16 @@ public abstract class Component implements ImageObserver, MenuContainer, */ private volatile transient int propertyListenersCount = 0; + /** + * A component listener to track show/hide/resize events + * and convert them to PropertyChange events. + */ protected ComponentListener accessibleAWTComponentHandler = null; + + /** + * A listener to track focus events + * and convert them to PropertyChange events. + */ protected FocusListener accessibleAWTFocusHandler = null; /** diff --git a/jdk/src/share/classes/java/awt/ComponentOrientation.java b/jdk/src/share/classes/java/awt/ComponentOrientation.java index 8655aafa322..226b004a273 100644 --- a/jdk/src/share/classes/java/awt/ComponentOrientation.java +++ b/jdk/src/share/classes/java/awt/ComponentOrientation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -126,6 +126,8 @@ public final class ComponentOrientation implements java.io.Serializable * Are lines horizontal? * This will return true for horizontal, left-to-right writing * systems such as Roman. + * + * @return {@code true} if this orientation has horizontal lines */ public boolean isHorizontal() { return (orientation & HORIZ_BIT) != 0; @@ -136,6 +138,8 @@ public final class ComponentOrientation implements java.io.Serializable * Vertical Lines: Do lines run left-to-right?
* This will return true for horizontal, left-to-right writing * systems such as Roman. + * + * @return {@code true} if this orientation is left-to-right */ public boolean isLeftToRight() { return (orientation & LTR_BIT) != 0; @@ -143,7 +147,9 @@ public final class ComponentOrientation implements java.io.Serializable /** * Returns the orientation that is appropriate for the given locale. + * * @param locale the specified locale + * @return the orientation for the locale */ public static ComponentOrientation getOrientation(Locale locale) { // A more flexible implementation would consult a ResourceBundle @@ -171,6 +177,8 @@ public final class ComponentOrientation implements java.io.Serializable *
  • Return the default locale's orientation. * * + * @param bdl the bundle to use + * @return the orientation * @deprecated As of J2SE 1.4, use {@link #getOrientation(java.util.Locale)}. */ @Deprecated diff --git a/jdk/src/share/classes/java/awt/Container.java b/jdk/src/share/classes/java/awt/Container.java index a352bab43ef..95997f4f900 100644 --- a/jdk/src/share/classes/java/awt/Container.java +++ b/jdk/src/share/classes/java/awt/Container.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -310,6 +310,9 @@ public class Container extends Component { } /** + * Returns the number of components in this container. + * + * @return the number of components in this container * @deprecated As of JDK version 1.1, * replaced by getComponentCount(). */ @@ -391,8 +394,11 @@ public class Container extends Component { } /** + * Returns the insets for this container. + * * @deprecated As of JDK version 1.1, * replaced by getInsets(). + * @return the insets for this container */ @Deprecated public Insets insets() { @@ -438,6 +444,9 @@ public class Container extends Component { * displayed, the hierarchy must be validated thereafter in order to * display the added component. * + * @param name the name of the component to be added + * @param comp the component to be added + * @return the component added * @exception NullPointerException if {@code comp} is {@code null} * @see #add(Component, Object) * @see #invalidate @@ -1471,8 +1480,10 @@ public class Container extends Component { /** * Gets the layout manager for this container. + * * @see #doLayout * @see #setLayout + * @return the current layout manager for this container */ public LayoutManager getLayout() { return layoutMgr; @@ -3854,6 +3865,10 @@ public class Container extends Component { */ private volatile transient int propertyListenersCount = 0; + /** + * The handler to fire {@code PropertyChange} + * when children are added or removed + */ protected ContainerListener accessibleContainerHandler = null; /** diff --git a/jdk/src/share/classes/java/awt/Cursor.java b/jdk/src/share/classes/java/awt/Cursor.java index 794c7c9b242..1468e162134 100644 --- a/jdk/src/share/classes/java/awt/Cursor.java +++ b/jdk/src/share/classes/java/awt/Cursor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -294,6 +294,7 @@ public class Cursor implements java.io.Serializable { * @return the system specific custom cursor named * @exception HeadlessException if * GraphicsEnvironment.isHeadless returns true + * @exception AWTException in case of erroneous retrieving of the cursor */ static public Cursor getSystemCustomCursor(final String name) throws AWTException, HeadlessException { @@ -378,6 +379,8 @@ public class Cursor implements java.io.Serializable { /** * Return the system default cursor. + * + * @return the default cursor */ static public Cursor getDefaultCursor() { return getPredefinedCursor(Cursor.DEFAULT_CURSOR); @@ -416,6 +419,8 @@ public class Cursor implements java.io.Serializable { /** * Returns the type for this cursor. + * + * @return the cursor type */ public int getType() { return type; diff --git a/jdk/src/share/classes/java/awt/DisplayMode.java b/jdk/src/share/classes/java/awt/DisplayMode.java index 71a5d7e8122..41564300615 100644 --- a/jdk/src/share/classes/java/awt/DisplayMode.java +++ b/jdk/src/share/classes/java/awt/DisplayMode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -125,6 +125,8 @@ public final class DisplayMode { /** * Returns whether the two display modes are equal. + * + * @param dm the display mode to compare to * @return whether the two display modes are equal */ public boolean equals(DisplayMode dm) { diff --git a/jdk/src/share/classes/java/awt/EventQueue.java b/jdk/src/share/classes/java/awt/EventQueue.java index 87bbace3ac8..a89311352ab 100644 --- a/jdk/src/share/classes/java/awt/EventQueue.java +++ b/jdk/src/share/classes/java/awt/EventQueue.java @@ -222,6 +222,9 @@ public class EventQueue { }); } + /** + * Initializes a new instance of {@code EventQueue}. + */ public EventQueue() { for (int i = 0; i < NUM_PRIORITIES; i++) { queues[i] = new Queue(); diff --git a/jdk/src/share/classes/java/awt/Frame.java b/jdk/src/share/classes/java/awt/Frame.java index df3fcda4773..c6ce4814078 100644 --- a/jdk/src/share/classes/java/awt/Frame.java +++ b/jdk/src/share/classes/java/awt/Frame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -1089,6 +1089,9 @@ public class Frame extends Window implements MenuContainer { } /** + * Sets the cursor for this frame to the specified type. + * + * @param cursorType the cursor type * @deprecated As of JDK version 1.1, * replaced by Component.setCursor(Cursor). */ @@ -1103,6 +1106,7 @@ public class Frame extends Window implements MenuContainer { /** * @deprecated As of JDK version 1.1, * replaced by Component.getCursor(). + * @return the cursor type for this frame */ @Deprecated public int getCursorType() { @@ -1124,6 +1128,8 @@ public class Frame extends Window implements MenuContainer { * ownerless {@code Dialog}s (introduced in release 1.6), use {@link * Window#getOwnerlessWindows Window.getOwnerlessWindows}. * + * @return the array of all {@code Frame}s created by this application + * * @see Window#getWindows() * @see Window#getOwnerlessWindows * diff --git a/jdk/src/share/classes/java/awt/GraphicsEnvironment.java b/jdk/src/share/classes/java/awt/GraphicsEnvironment.java index e9e9080dba6..2d6436cc00d 100644 --- a/jdk/src/share/classes/java/awt/GraphicsEnvironment.java +++ b/jdk/src/share/classes/java/awt/GraphicsEnvironment.java @@ -357,6 +357,8 @@ public abstract class GraphicsEnvironment { *

    Notice that an application can supersede the registration * of an earlier created font with a new one. * + * + * @param font the font to be registered * @return true if the font is successfully * registered in this GraphicsEnvironment. * @throws NullPointerException if font is null diff --git a/jdk/src/share/classes/java/awt/GridBagLayout.java b/jdk/src/share/classes/java/awt/GridBagLayout.java index 0b2c32ba2b5..981c993751a 100644 --- a/jdk/src/share/classes/java/awt/GridBagLayout.java +++ b/jdk/src/share/classes/java/awt/GridBagLayout.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -981,9 +981,15 @@ java.io.Serializable { * This method is obsolete and supplied for backwards * compatibility only; new code should call {@link * #getLayoutInfo(java.awt.Container, int) getLayoutInfo} instead. - * This method is the same as getLayoutInfo; - * refer to getLayoutInfo for details on parameters - * and return value. + * + * Fills in an instance of {@code GridBagLayoutInfo} for the + * current set of managed children. This method is the same + * as {@code getLayoutInfo}; refer to {@code getLayoutInfo} + * description for details. + * + * @param parent the layout container + * @param sizeflag either {@code PREFERREDSIZE} or {@code MINSIZE} + * @return the {@code GridBagLayoutInfo} for the set of children */ protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) { synchronized (parent.getTreeLock()) { @@ -1611,13 +1617,17 @@ java.io.Serializable { } /** + * Adjusts the x, y, width, and height fields to the correct + * values depending on the constraint geometry and pads. + *

    * This method is obsolete and supplied for backwards * compatibility only; new code should call {@link * #adjustForGravity(java.awt.GridBagConstraints, java.awt.Rectangle) * adjustForGravity} instead. - * This method is the same as adjustForGravity; - * refer to adjustForGravity for details - * on parameters. + * This method is the same as adjustForGravity + * + * @param constraints the constraints to be applied + * @param r the {@code Rectangle} to be adjusted */ protected void AdjustForGravity(GridBagConstraints constraints, Rectangle r) { @@ -1995,9 +2005,12 @@ java.io.Serializable { * This method is obsolete and supplied for backwards * compatibility only; new code should call {@link * #getMinSize(java.awt.Container, GridBagLayoutInfo) getMinSize} instead. - * This method is the same as getMinSize; - * refer to getMinSize for details on parameters - * and return value. + * This method is the same as getMinSize + * + * @param parent the layout container + * @param info the layout info for this parent + * @return a Dimension object containing the + * minimum size */ protected Dimension GetMinSize(Container parent, GridBagLayoutInfo info) { Dimension d = new Dimension(); @@ -2035,9 +2048,9 @@ java.io.Serializable { * This method is obsolete and supplied for backwards * compatibility only; new code should call {@link * #arrangeGrid(Container) arrangeGrid} instead. - * This method is the same as arrangeGrid; - * refer to arrangeGrid for details on the - * parameter. + * This method is the same as arrangeGrid + * + * @param parent the layout container */ protected void ArrangeGrid(Container parent) { Component comp; diff --git a/jdk/src/share/classes/java/awt/HeadlessException.java b/jdk/src/share/classes/java/awt/HeadlessException.java index db53a351c6d..5809ffd9faf 100644 --- a/jdk/src/share/classes/java/awt/HeadlessException.java +++ b/jdk/src/share/classes/java/awt/HeadlessException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -38,10 +38,24 @@ public class HeadlessException extends UnsupportedOperationException { * JDK 1.4 serialVersionUID */ private static final long serialVersionUID = 167183644944358563L; + + /** + * Constructs new {@code HeadlessException} + */ public HeadlessException() {} + + /** + * Create a new instance with the specified detailed error message. + * + * @param msg the error message + */ public HeadlessException(String msg) { super(msg); } + + /** + * {@inheritDoc} + */ public String getMessage() { String superMessage = super.getMessage(); String headlessMessage = GraphicsEnvironment.getHeadlessMessage(); diff --git a/jdk/src/share/classes/java/awt/ItemSelectable.java b/jdk/src/share/classes/java/awt/ItemSelectable.java index d19afb3ab0d..e11b70ef48f 100644 --- a/jdk/src/share/classes/java/awt/ItemSelectable.java +++ b/jdk/src/share/classes/java/awt/ItemSelectable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -39,6 +39,8 @@ public interface ItemSelectable { /** * Returns the selected items or null if no * items are selected. + * + * @return the list of selected objects, or {@code null} */ public Object[] getSelectedObjects(); diff --git a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java index 8758a2b50e3..57a8f733ce7 100644 --- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java +++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java @@ -1459,6 +1459,7 @@ public abstract class KeyboardFocusManager * Returns an array of all the PropertyChangeListeners * associated with the named property. * + * @param propertyName the property name * @return all of the PropertyChangeListeners associated with * the named property or an empty array if no such listeners have * been added. @@ -1628,6 +1629,7 @@ public abstract class KeyboardFocusManager * Returns an array of all the VetoableChangeListeners * associated with the named property. * + * @param propertyName the property name * @return all of the VetoableChangeListeners associated with * the named property or an empty array if no such listeners have * been added. diff --git a/jdk/src/share/classes/java/awt/Label.java b/jdk/src/share/classes/java/awt/Label.java index 20ccdcd4c86..c8aab9569ff 100644 --- a/jdk/src/share/classes/java/awt/Label.java +++ b/jdk/src/share/classes/java/awt/Label.java @@ -193,7 +193,8 @@ public class Label extends Component implements Accessible { * Gets the current alignment of this label. Possible values are * Label.LEFT, Label.RIGHT, and * Label.CENTER. - * @see java.awt.Label#setAlignment + * @return the alignment of this label + * @see java.awt.Label#setAlignment */ public int getAlignment() { return alignment; @@ -321,6 +322,9 @@ public class Label extends Component implements Accessible { */ private static final long serialVersionUID = -3568967560160480438L; + /** + * Constructor for the accessible label. + */ public AccessibleAWTLabel() { super(); } diff --git a/jdk/src/share/classes/java/awt/LayoutManager.java b/jdk/src/share/classes/java/awt/LayoutManager.java index 5a00db263e6..d7abfbb1c29 100644 --- a/jdk/src/share/classes/java/awt/LayoutManager.java +++ b/jdk/src/share/classes/java/awt/LayoutManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -61,7 +61,9 @@ public interface LayoutManager { /** * Calculates the preferred size dimensions for the specified * container, given the components it contains. - * @param parent the container to be laid out + * + * @param parent the container to be laid out + * @return the preferred dimension for the container * * @see #minimumLayoutSize */ @@ -70,7 +72,10 @@ public interface LayoutManager { /** * Calculates the minimum size dimensions for the specified * container, given the components it contains. - * @param parent the component to be laid out + * + * @param parent the component to be laid out + * @return the minimum dimension for the container + * * @see #preferredLayoutSize */ Dimension minimumLayoutSize(Container parent); diff --git a/jdk/src/share/classes/java/awt/LayoutManager2.java b/jdk/src/share/classes/java/awt/LayoutManager2.java index ae6516e17b8..347295052e4 100644 --- a/jdk/src/share/classes/java/awt/LayoutManager2.java +++ b/jdk/src/share/classes/java/awt/LayoutManager2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -55,8 +55,11 @@ public interface LayoutManager2 extends LayoutManager { /** * Calculates the maximum size dimensions for the specified container, * given the components it contains. + * * @see java.awt.Component#getMaximumSize * @see LayoutManager + * @param target the target container + * @return the maximum size of the container */ public Dimension maximumLayoutSize(Container target); @@ -66,6 +69,9 @@ public interface LayoutManager2 extends LayoutManager { * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. + * + * @param target the target container + * @return the x-axis alignment preference */ public float getLayoutAlignmentX(Container target); @@ -75,12 +81,16 @@ public interface LayoutManager2 extends LayoutManager { * components. The value should be a number between 0 and 1 * where 0 represents alignment along the origin, 1 is aligned * the furthest away from the origin, 0.5 is centered, etc. + * + * @param target the target container + * @return the y-axis alignment preference */ public float getLayoutAlignmentY(Container target); /** * Invalidates the layout, indicating that if the layout manager * has cached information it should be discarded. + * @param target the target container */ public void invalidateLayout(Container target); diff --git a/jdk/src/share/classes/java/awt/List.java b/jdk/src/share/classes/java/awt/List.java index df638c26724..ede6f643157 100644 --- a/jdk/src/share/classes/java/awt/List.java +++ b/jdk/src/share/classes/java/awt/List.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -282,6 +282,9 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Returns the number of items in the list. + * + * @return the number of items in the list * @deprecated As of JDK version 1.1, * replaced by getItemCount(). */ @@ -333,7 +336,10 @@ public class List extends Component implements ItemSelectable, Accessible { } /** - * @deprecated replaced by add(String). + * Adds the specified item to the end of the list. + * + * @param item the item to be added + * @deprecated replaced by add(String). */ @Deprecated public void addItem(String item) { @@ -358,7 +364,12 @@ public class List extends Component implements ItemSelectable, Accessible { } /** - * @deprecated replaced by add(String, int). + * Adds the specified item to the the list + * at the position indicated by the index. + * + * @param item the item to be added + * @param index the position at which to add the item + * @deprecated replaced by add(String, int). */ @Deprecated public synchronized void addItem(String item, int index) { @@ -455,8 +466,11 @@ public class List extends Component implements ItemSelectable, Accessible { } /** - * @deprecated replaced by remove(String) - * and remove(int). + * Removes the item at the specified position. + * + * @param position the index of the item to delete + * @deprecated replaced by remove(String) + * and remove(int). */ @Deprecated public void delItem(int position) { @@ -646,6 +660,10 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Determines if the specified item in the list is selected. + * + * @param index specifies the item to be checked + * @return {@code true} if the item is selected; otherwise {@code false} * @deprecated As of JDK version 1.1, * replaced by isIndexSelected(int). */ @@ -672,6 +690,7 @@ public class List extends Component implements ItemSelectable, Accessible { /** * Determines whether this list allows multiple selections. + * * @return true if this list allows multiple * selections; otherwise, false * @see #setMultipleMode @@ -682,6 +701,10 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Determines whether this list allows multiple selections. + * + * @return {@code true} if this list allows multiple + * selections; otherwise {@code false} * @deprecated As of JDK version 1.1, * replaced by isMultipleMode(). */ @@ -709,6 +732,9 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Enables or disables multiple selection mode for this list. + * + * @param b {@code true} to enable multiple mode, {@code false} otherwise * @deprecated As of JDK version 1.1, * replaced by setMultipleMode(boolean). */ @@ -760,6 +786,11 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Returns the preferred size of this component + * assuming it has the specified number of rows. + * + * @param rows the number of rows + * @return the preferred dimensions for displaying this list * @deprecated As of JDK version 1.1, * replaced by getPreferredSize(int). */ @@ -810,6 +841,11 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Returns the minimum dimensions for the list + * with the specified number of rows. + * + * @param rows the number of rows in the list + * @return the minimum dimensions for displaying this list * @deprecated As of JDK version 1.1, * replaced by getMinimumSize(int). */ @@ -1146,6 +1182,10 @@ public class List extends Component implements ItemSelectable, Accessible { } /** + * Deletes the list items in the specified index range. + * + * @param start the beginning index of the range to delete + * @param end the ending index of the range to delete * @deprecated As of JDK version 1.1, * Not for public use in the future. * This method is expected to be retained only as a package @@ -1290,6 +1330,9 @@ public class List extends Component implements ItemSelectable, Accessible { */ private static final long serialVersionUID = 7924617370136012829L; + /** + * Constructs new {@code AccessibleAWTList} + */ public AccessibleAWTList() { super(); List.this.addActionListener(this); @@ -1491,6 +1534,13 @@ public class List extends Component implements ItemSelectable, Accessible { private List parent; private int indexInParent; + /** + * Constructs new {@code AccessibleAWTListChild} with the given + * parent {@code List} and 0-based index of this object in the parent. + * + * @param parent the parent {@code List} + * @param indexInParent the index in the parent + */ public AccessibleAWTListChild(List parent, int indexInParent) { this.parent = parent; this.setAccessibleParent(parent); diff --git a/jdk/src/share/classes/java/awt/MediaTracker.java b/jdk/src/share/classes/java/awt/MediaTracker.java index b8df6320cfa..dd8f9e0825f 100644 --- a/jdk/src/share/classes/java/awt/MediaTracker.java +++ b/jdk/src/share/classes/java/awt/MediaTracker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -643,9 +643,11 @@ public class MediaTracker implements java.io.Serializable { * image is considered to have finished loading. Use the * statusID, isErrorID, and * isErrorAny methods to check for errors. - * @param id the identifier of the images to check - * @param ms the length of time, in milliseconds, to wait - * for the loading to complete + * @param id the identifier of the images to check + * @param ms the length of time, in milliseconds, to wait + * for the loading to complete + * @return {@code true} if the loading completed in time; + * otherwise {@code false} * @see java.awt.MediaTracker#waitForAll * @see java.awt.MediaTracker#waitForID(int) * @see java.awt.MediaTracker#statusID diff --git a/jdk/src/share/classes/java/awt/Menu.java b/jdk/src/share/classes/java/awt/Menu.java index 177f208be05..3c8154338ac 100644 --- a/jdk/src/share/classes/java/awt/Menu.java +++ b/jdk/src/share/classes/java/awt/Menu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -213,7 +213,7 @@ public class Menu extends MenuItem implements MenuContainer, Accessible { /** * Get the number of items in this menu. - * @return the number of items in this menu. + * @return the number of items in this menu * @since 1.1 */ public int getItemCount() { @@ -221,6 +221,9 @@ public class Menu extends MenuItem implements MenuContainer, Accessible { } /** + * Returns the number of items in this menu. + * + * @return the number of items in this menu * @deprecated As of JDK version 1.1, * replaced by getItemCount(). */ diff --git a/jdk/src/share/classes/java/awt/MenuBar.java b/jdk/src/share/classes/java/awt/MenuBar.java index 4e48c7c38ce..4fa4723c417 100644 --- a/jdk/src/share/classes/java/awt/MenuBar.java +++ b/jdk/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, 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 @@ -279,6 +279,9 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible } /** + * Gets the number of menus on the menu bar. + * + * @return the number of menus on the menu bar. * @deprecated As of JDK version 1.1, * replaced by getMenuCount(). */ @@ -338,10 +341,11 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible * or null if none of the menu items being managed * by this menu bar is associated with the specified menu * shortcut. - * @param s the specified menu shortcut. - * @see java.awt.MenuItem - * @see java.awt.MenuShortcut - * @since 1.1 + * @param s the specified menu shortcut. + * @return the menu item for the specified shortcut. + * @see java.awt.MenuItem + * @see java.awt.MenuShortcut + * @since 1.1 */ public MenuItem getShortcutMenuItem(MenuShortcut s) { int nmenus = getMenuCount(); diff --git a/jdk/src/share/classes/java/awt/MenuComponent.java b/jdk/src/share/classes/java/awt/MenuComponent.java index 28fb9ab209e..4ea95bf5969 100644 --- a/jdk/src/share/classes/java/awt/MenuComponent.java +++ b/jdk/src/share/classes/java/awt/MenuComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -220,6 +220,7 @@ public abstract class MenuComponent implements java.io.Serializable { /** * @deprecated As of JDK version 1.1, * programs should not directly manipulate peers. + * @return the peer for this component */ @Deprecated public MenuComponentPeer getPeer() { diff --git a/jdk/src/share/classes/java/awt/MenuContainer.java b/jdk/src/share/classes/java/awt/MenuContainer.java index 8b43f992f4f..8ba5e70245b 100644 --- a/jdk/src/share/classes/java/awt/MenuContainer.java +++ b/jdk/src/share/classes/java/awt/MenuContainer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -31,10 +31,25 @@ package java.awt; */ public interface MenuContainer { + + /** + * Returns the font in use by this container. + * + * @return the menu font + */ Font getFont(); + + /** + * Removes the specified menu component from the menu. + * + * @param comp the menu component to remove + */ void remove(MenuComponent comp); /** + * Posts an event to the listeners. + * + * @param evt the event to dispatch * @deprecated As of JDK version 1.1 * replaced by dispatchEvent(AWTEvent). */ diff --git a/jdk/src/share/classes/java/awt/MenuItem.java b/jdk/src/share/classes/java/awt/MenuItem.java index a81c1314700..ab797f4dd1a 100644 --- a/jdk/src/share/classes/java/awt/MenuItem.java +++ b/jdk/src/share/classes/java/awt/MenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -264,6 +264,9 @@ public class MenuItem extends MenuComponent implements Accessible { /** * Checks whether this menu item is enabled. + * + * @return {@code true} if the item is enabled; + * otherwise {@code false} * @see java.awt.MenuItem#setEnabled * @since 1.0 */ @@ -296,6 +299,10 @@ public class MenuItem extends MenuComponent implements Accessible { } /** + * Sets whether or not this menu item can be chosen. + * + * @param b if {@code true}, enables this menu item; + * otherwise disables * @deprecated As of JDK version 1.1, * replaced by setEnabled(boolean). */ @@ -494,8 +501,10 @@ public class MenuItem extends MenuComponent implements Accessible { /** * Gets the command name of the action event that is fired * by this menu item. - * @see java.awt.MenuItem#setActionCommand - * @since 1.1 + * + * @return the action command name + * @see java.awt.MenuItem#setActionCommand + * @since 1.1 */ public String getActionCommand() { return getActionCommandImpl(); diff --git a/jdk/src/share/classes/java/awt/PrintGraphics.java b/jdk/src/share/classes/java/awt/PrintGraphics.java index 91e5173f81f..74c2f84a31e 100644 --- a/jdk/src/share/classes/java/awt/PrintGraphics.java +++ b/jdk/src/share/classes/java/awt/PrintGraphics.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1997, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -35,6 +35,8 @@ public interface PrintGraphics { /** * Returns the PrintJob object from which this PrintGraphics * object originated. + * + * @return the print job for this object */ public PrintJob getPrintJob(); diff --git a/jdk/src/share/classes/java/awt/PrintJob.java b/jdk/src/share/classes/java/awt/PrintJob.java index 996d7653526..fcc6afebf2a 100644 --- a/jdk/src/share/classes/java/awt/PrintJob.java +++ b/jdk/src/share/classes/java/awt/PrintJob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -42,6 +42,7 @@ public abstract class PrintJob { * object is disposed. This graphics object will also implement * the PrintGraphics interface. * @see PrintGraphics + * @return the graphics context for printing the next page */ public abstract Graphics getGraphics(); @@ -49,6 +50,8 @@ public abstract class PrintJob { * Returns the dimensions of the page in pixels. * The resolution of the page is chosen so that it * is similar to the screen resolution. + * + * @return the page dimension */ public abstract Dimension getPageDimension(); @@ -56,11 +59,16 @@ public abstract class PrintJob { * Returns the resolution of the page in pixels per inch. * Note that this doesn't have to correspond to the physical * resolution of the printer. + * + * @return the page resolution */ public abstract int getPageResolution(); /** * Returns true if the last page will be printed first. + * + * @return {@code true} if the last page will be printed first; + * otherwise {@code false} */ public abstract boolean lastPageFirst(); diff --git a/jdk/src/share/classes/java/awt/Robot.java b/jdk/src/share/classes/java/awt/Robot.java index cc734dd45a2..8de89ee8ed9 100644 --- a/jdk/src/share/classes/java/awt/Robot.java +++ b/jdk/src/share/classes/java/awt/Robot.java @@ -498,6 +498,8 @@ public class Robot { /** * Returns the number of milliseconds this Robot sleeps after generating an event. + * + * @return the delay duration in milliseconds */ public synchronized int getAutoDelay() { return autoDelay; @@ -505,7 +507,10 @@ public class Robot { /** * Sets the number of milliseconds this Robot sleeps after generating an event. - * @throws IllegalArgumentException If ms is not between 0 and 60,000 milliseconds inclusive + * + * @param ms the delay duration in milliseconds + * @throws IllegalArgumentException If {@code ms} + * is not between 0 and 60,000 milliseconds inclusive */ public synchronized void setAutoDelay(int ms) { checkDelayArgument(ms); @@ -523,9 +528,11 @@ public class Robot { * Sleeps for the specified time. * To catch any InterruptedExceptions that occur, * Thread.sleep() may be used instead. - * @param ms time to sleep in milliseconds - * @throws IllegalArgumentException if ms is not between 0 and 60,000 milliseconds inclusive - * @see java.lang.Thread#sleep + * + * @param ms time to sleep in milliseconds + * @throws IllegalArgumentException if {@code ms} + * is not between 0 and 60,000 milliseconds inclusive + * @see java.lang.Thread#sleep */ public synchronized void delay(int ms) { checkDelayArgument(ms); diff --git a/jdk/src/share/classes/java/awt/ScrollPane.java b/jdk/src/share/classes/java/awt/ScrollPane.java index 70ca48f4d74..fb5401d06f6 100644 --- a/jdk/src/share/classes/java/awt/ScrollPane.java +++ b/jdk/src/share/classes/java/awt/ScrollPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -323,7 +323,9 @@ public class ScrollPane extends Container implements Accessible { * represents the state of the vertical scrollbar. * The declared return type of this method is * Adjustable to maintain backward compatibility. + * * @see java.awt.ScrollPaneAdjustable + * @return the vertical scrollbar state */ public Adjustable getVAdjustable() { return vAdjustable; @@ -334,7 +336,9 @@ public class ScrollPane extends Container implements Accessible { * represents the state of the horizontal scrollbar. * The declared return type of this method is * Adjustable to maintain backward compatibility. + * * @see java.awt.ScrollPaneAdjustable + * @return the horizontal scrollbar state */ public Adjustable getHAdjustable() { return hAdjustable; @@ -657,6 +661,9 @@ public class ScrollPane extends Container implements Accessible { * Indicates whether or not scrolling will take place in response to * the mouse wheel. Wheel scrolling is enabled by default. * + * @return {@code true} if the wheel scrolling enabled; + * otherwise {@code false} + * * @see #setWheelScrollingEnabled(boolean) * @since 1.4 */ diff --git a/jdk/src/share/classes/java/awt/Scrollbar.java b/jdk/src/share/classes/java/awt/Scrollbar.java index bf119ae2779..28c84efb923 100644 --- a/jdk/src/share/classes/java/awt/Scrollbar.java +++ b/jdk/src/share/classes/java/awt/Scrollbar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -656,6 +656,9 @@ public class Scrollbar extends Component implements Adjustable, Accessible { } /** + * Returns the visible amount of this scroll bar. + * + * @return the visible amount of this scroll bar * @deprecated As of JDK version 1.1, * replaced by getVisibleAmount(). */ @@ -729,6 +732,10 @@ public class Scrollbar extends Component implements Adjustable, Accessible { } /** + * Sets the unit increment for this scroll bar. + * + * @param v the increment value + * * @deprecated As of JDK version 1.1, * replaced by setUnitIncrement(int). */ @@ -768,6 +775,9 @@ public class Scrollbar extends Component implements Adjustable, Accessible { } /** + * Returns the unit increment for this scrollbar. + * + * @return the unit increment for this scrollbar * @deprecated As of JDK version 1.1, * replaced by getUnitIncrement(). */ @@ -797,6 +807,9 @@ public class Scrollbar extends Component implements Adjustable, Accessible { } /** + * Sets the block increment for this scroll bar. + * + * @param v the block increment * @deprecated As of JDK version 1.1, * replaced by setBlockIncrement(). */ @@ -833,6 +846,10 @@ public class Scrollbar extends Component implements Adjustable, Accessible { } /** + * Returns the block increment of this scroll bar. + * + * @return the block increment of this scroll bar + * * @deprecated As of JDK version 1.1, * replaced by getBlockIncrement(). */ diff --git a/jdk/src/share/classes/java/awt/TextArea.java b/jdk/src/share/classes/java/awt/TextArea.java index dd90aa7414e..f29da08b537 100644 --- a/jdk/src/share/classes/java/awt/TextArea.java +++ b/jdk/src/share/classes/java/awt/TextArea.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -314,6 +314,11 @@ public class TextArea extends TextComponent { } /** + * Inserts the specified text at the specified position + * in this text area. + * + * @param str the non-{@code null} text to insert + * @param pos the position at which to insert * @deprecated As of JDK version 1.1, * replaced by insert(String, int). */ @@ -342,6 +347,9 @@ public class TextArea extends TextComponent { } /** + * Appends the given text to the text area's current text. + * + * @param str the text to append * @deprecated As of JDK version 1.1, * replaced by append(String). */ @@ -378,6 +386,15 @@ public class TextArea extends TextComponent { } /** + * Replaces a range of characters between + * the indicated start and end positions + * with the specified replacement text (the text at the end + * position will not be replaced). + * + * @param str the non-{@code null} text to use as + * the replacement + * @param start the start position + * @param end the end position * @deprecated As of JDK version 1.1, * replaced by replaceRange(String, int, int). */ @@ -492,6 +509,12 @@ public class TextArea extends TextComponent { } /** + * Determines the preferred size of the text area with the specified + * number of rows and columns. + * + * @param rows the number of rows + * @param columns the number of columns + * @return the preferred dimensions needed for the text area * @deprecated As of JDK version 1.1, * replaced by getPreferredSize(int, int). */ @@ -544,6 +567,12 @@ public class TextArea extends TextComponent { } /** + * Determines the minimum size of the text area with the specified + * number of rows and columns. + * + * @param rows the number of rows + * @param columns the number of columns + * @return the minimum size for the text area * @deprecated As of JDK version 1.1, * replaced by getMinimumSize(int, int). */ diff --git a/jdk/src/share/classes/java/awt/TextComponent.java b/jdk/src/share/classes/java/awt/TextComponent.java index 104fe02e53b..639438a2a1d 100644 --- a/jdk/src/share/classes/java/awt/TextComponent.java +++ b/jdk/src/share/classes/java/awt/TextComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -107,6 +107,9 @@ public class TextComponent extends Component implements Accessible { // the background color of non-editable TextComponents. boolean backgroundSetByClientCode = false; + /** + * A list of listeners that will receive events from this object. + */ transient protected TextListener textListener; /* diff --git a/jdk/src/share/classes/java/awt/TextField.java b/jdk/src/share/classes/java/awt/TextField.java index 3b4646896e1..ebebc828b96 100644 --- a/jdk/src/share/classes/java/awt/TextField.java +++ b/jdk/src/share/classes/java/awt/TextField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -272,6 +272,10 @@ public class TextField extends TextComponent { } /** + * Sets the character to be echoed when protected input is displayed. + * + * @param c the echo character for this text field + * * @deprecated As of JDK version 1.1, * replaced by setEchoChar(char). */ @@ -368,6 +372,12 @@ public class TextField extends TextComponent { } /** + * Returns the preferred size for this text field + * with the specified number of columns. + * + * @param columns the number of columns + * @return the preferred size for the text field + * * @deprecated As of JDK version 1.1, * replaced by getPreferredSize(int). */ @@ -407,8 +417,9 @@ public class TextField extends TextComponent { /** * Gets the minimum dimensions for a text field with * the specified number of columns. - * @param columns the number of columns in - * this text field. + * @param columns the number of columns in + * this text field. + * @return the minimum size for this text field * @since 1.1 */ public Dimension getMinimumSize(int columns) { @@ -416,6 +427,11 @@ public class TextField extends TextComponent { } /** + * Returns the minimum dimensions for a text field with + * the specified number of columns. + * + * @param columns the number of columns + * @return the minimum size for this text field * @deprecated As of JDK version 1.1, * replaced by getMinimumSize(int). */ diff --git a/jdk/src/share/classes/java/awt/Toolkit.java b/jdk/src/share/classes/java/awt/Toolkit.java index 7bc8c24f625..65b494ba52d 100644 --- a/jdk/src/share/classes/java/awt/Toolkit.java +++ b/jdk/src/share/classes/java/awt/Toolkit.java @@ -422,7 +422,8 @@ public abstract class Toolkit { * and allows the Component and Container classes to be extended directly * to create windowless components that are defined entirely in java. * - * @param target The Component to be created. + * @param target The Component to be created. + * @return the peer for the specified component */ protected LightweightPeer createComponent(Component target) { if (lightweightMarker == null) { @@ -1370,6 +1371,9 @@ public abstract class Toolkit { * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}. * + * @param keyCode the key code + * @return {@code true} if the given key is currently in its "on" state; + * otherwise {@code false} * @exception java.lang.IllegalArgumentException if keyCode * is not one of the valid key codes * @exception java.lang.UnsupportedOperationException if the host system doesn't @@ -1404,6 +1408,8 @@ public abstract class Toolkit { * involve event processing and therefore may not be immediately * observable through getLockingKeyState. * + * @param keyCode the key code + * @param on the state of the key * @exception java.lang.IllegalArgumentException if keyCode * is not one of the valid key codes * @exception java.lang.UnsupportedOperationException if the host system doesn't @@ -1429,6 +1435,9 @@ public abstract class Toolkit { /** * Give native peers the ability to query the native container * given a native component (eg the direct parent may be lightweight). + * + * @param c the component to fetch the container for + * @return the native container object for the component */ protected static Container getNativeContainer(Component c) { return c.getNativeContainer(); @@ -1449,6 +1458,7 @@ public abstract class Toolkit { * @param name a localized description of the cursor, for Java Accessibility use * @exception IndexOutOfBoundsException if the hotSpot values are outside * the bounds of the cursor + * @return the cursor created * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true * @see java.awt.GraphicsEnvironment#isHeadless @@ -1675,6 +1685,11 @@ public abstract class Toolkit { /** * Gets a property with the specified key and default. * This method returns defaultValue if the property is not found. + * + * @param key the key + * @param defaultValue the default value + * @return the value of the property or the default value + * if the property was not found */ public static String getProperty(String key, String defaultValue) { // first try platform specific bundle @@ -1738,6 +1753,9 @@ public abstract class Toolkit { * Creates the peer for a DragSourceContext. * Always throws InvalidDndOperationException if * GraphicsEnvironment.isHeadless() returns true. + * + * @param dge the {@code DragGestureEvent} + * @return the peer created * @see java.awt.GraphicsEnvironment#isHeadless */ public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException; @@ -1775,6 +1793,9 @@ public abstract class Toolkit { * representation for an underlying platform dependent desktop setting. * For more information on desktop properties supported by the AWT see * AWT Desktop Properties. + * + * @param propertyName the property name + * @return the value for the specified desktop property */ public final synchronized Object getDesktopProperty(String propertyName) { // This is a workaround for headless toolkits. It would be @@ -1818,6 +1839,9 @@ public abstract class Toolkit { /** * Sets the named desktop property to the specified value and fires a * property change event to notify any listeners that the value has changed. + * + * @param name the property name + * @param newValue the new property value */ protected final void setDesktopProperty(String name, Object newValue) { // This is a workaround for headless toolkits. It would be diff --git a/jdk/src/share/classes/java/awt/Window.java b/jdk/src/share/classes/java/awt/Window.java index 47bcdf301ca..629f1df75a4 100644 --- a/jdk/src/share/classes/java/awt/Window.java +++ b/jdk/src/share/classes/java/awt/Window.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -1452,6 +1452,8 @@ public class Window extends Container implements Accessible { /** * Returns the owner of this window. + * + * @return the owner of this window * @since 1.2 */ public Window getOwner() { @@ -1464,6 +1466,8 @@ public class Window extends Container implements Accessible { /** * Return an array containing all the windows this * window currently owns. + * + * @return the array of all the owned windows * @since 1.2 */ public Window[] getOwnedWindows() { @@ -1586,6 +1590,7 @@ public class Window extends Container implements Accessible { * dialogs such as component positions, {@code LayoutManager}s * or serialization. * + * @return the array of all the {@code Window}s created by the application * @see Frame#getFrames * @see Window#getOwnerlessWindows * @@ -1608,6 +1613,8 @@ public class Window extends Container implements Accessible { * dialogs such as component positions, {@code LayoutManager}s * or serialization. * + * @return the array of all the ownerless {@code Window}s + * created by this application * @see Frame#getFrames * @see Window#getWindows() * @@ -2849,6 +2856,7 @@ public class Window extends Container implements Accessible { * * This method can only be called while the window is not displayable. * + * @param type the window type * @throws IllegalComponentStateException if the window * is displayable. * @throws IllegalArgumentException if the type is {@code null} @@ -2874,6 +2882,7 @@ public class Window extends Container implements Accessible { /** * Returns the type of the window. * + * @return the type of the window * @see #setType * @since 1.7 */ From ea1f1d527dfe47a928360ec4aa715cf3194988b8 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 24 Jun 2014 10:46:08 -0700 Subject: [PATCH 05/30] 8048014: Update java.lang.SafeVararags for private methods Reviewed-by: lancea, abuckley --- jdk/src/share/classes/java/lang/SafeVarargs.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/lang/SafeVarargs.java b/jdk/src/share/classes/java/lang/SafeVarargs.java index 6fcd48e97d7..9f49bf7a73f 100644 --- a/jdk/src/share/classes/java/lang/SafeVarargs.java +++ b/jdk/src/share/classes/java/lang/SafeVarargs.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -45,7 +45,7 @@ import java.lang.annotation.*; *

  • the declaration is a fixed arity method or constructor * *
  • the declaration is a variable arity method that is neither - * {@code static} nor {@code final}. + * {@code static} nor {@code final} nor {@code private}. * * * From 8bca223cbdf11d63a4f6566ce97c7c61fc8de6b1 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 24 Jun 2014 19:58:03 +0200 Subject: [PATCH 06/30] 8047073: Some javax/management/ fails with JFR Reviewed-by: egahlin, dfuchs --- jdk/test/javax/management/MBeanServer/MBeanFallbackTest.java | 3 +-- jdk/test/javax/management/ObjectName/SerialCompatTest.java | 4 +--- jdk/test/javax/management/mxbean/MXBeanFallbackTest.java | 3 +-- jdk/test/javax/management/proxy/JMXProxyFallbackTest.java | 3 +-- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/jdk/test/javax/management/MBeanServer/MBeanFallbackTest.java b/jdk/test/javax/management/MBeanServer/MBeanFallbackTest.java index dcb5e1803a4..5fe115f7b04 100644 --- a/jdk/test/javax/management/MBeanServer/MBeanFallbackTest.java +++ b/jdk/test/javax/management/MBeanServer/MBeanFallbackTest.java @@ -35,7 +35,7 @@ import javax.management.ObjectName; * @author Jaroslav Bachorik * @run clean MBeanFallbackTest * @run build MBeanFallbackTest - * @run main MBeanFallbackTest + * @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true MBeanFallbackTest */ public class MBeanFallbackTest { private static interface PrivateMBean { @@ -51,7 +51,6 @@ public class MBeanFallbackTest { private static int failures = 0; public static void main(String[] args) throws Exception { - System.setProperty("jdk.jmx.mbeans.allowNonPublic", "true"); testPrivate(PrivateMBean.class, new Private()); if (failures == 0) diff --git a/jdk/test/javax/management/ObjectName/SerialCompatTest.java b/jdk/test/javax/management/ObjectName/SerialCompatTest.java index 50b65784aa4..0c183b204a0 100644 --- a/jdk/test/javax/management/ObjectName/SerialCompatTest.java +++ b/jdk/test/javax/management/ObjectName/SerialCompatTest.java @@ -28,7 +28,7 @@ * @author Eamonn McManus, Daniel Fuchs * @run clean SerialCompatTest * @run build SerialCompatTest - * @run main/othervm SerialCompatTest + * @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true -Djmx.serial.form=1.0 SerialCompatTest */ import java.io.*; @@ -223,8 +223,6 @@ public class SerialCompatTest { } public static void main(String[] args) throws Exception { - System.setProperty("jmx.serial.form", "1.0"); - /* Check that we really are in jmx.serial.form=1.0 mode. The property is frozen the first time the ObjectName class is referenced so checking that it is set to the correct diff --git a/jdk/test/javax/management/mxbean/MXBeanFallbackTest.java b/jdk/test/javax/management/mxbean/MXBeanFallbackTest.java index 388ffc9373d..cd10b6f6221 100644 --- a/jdk/test/javax/management/mxbean/MXBeanFallbackTest.java +++ b/jdk/test/javax/management/mxbean/MXBeanFallbackTest.java @@ -30,7 +30,7 @@ * @author Jaroslav Bachorik * @run clean MXBeanFallbackTest * @run build MXBeanFallbackTest - * @run main MXBeanFallbackTest + * @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true MXBeanFallbackTest */ import javax.management.MBeanServer; @@ -40,7 +40,6 @@ import javax.management.ObjectName; public class MXBeanFallbackTest { public static void main(String[] args) throws Exception { - System.setProperty("jdk.jmx.mbeans.allowNonPublic", "true"); testPrivateMXBean("Private", new Private()); if (failures == 0) diff --git a/jdk/test/javax/management/proxy/JMXProxyFallbackTest.java b/jdk/test/javax/management/proxy/JMXProxyFallbackTest.java index d1243593c11..2d96d062b30 100644 --- a/jdk/test/javax/management/proxy/JMXProxyFallbackTest.java +++ b/jdk/test/javax/management/proxy/JMXProxyFallbackTest.java @@ -36,7 +36,7 @@ import javax.management.ObjectName; * @author Jaroslav Bachorik * @run clean JMXProxyFallbackTest * @run build JMXProxyFallbackTest - * @run main JMXProxyFallbackTest + * @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true JMXProxyFallbackTest */ public class JMXProxyFallbackTest { private static interface PrivateMBean { @@ -56,7 +56,6 @@ public class JMXProxyFallbackTest { private static int failures = 0; public static void main(String[] args) throws Exception { - System.setProperty("jdk.jmx.mbeans.allowNonPublic", "true"); testPrivate(PrivateMBean.class); testPrivate(PrivateMXBean.class); From cc7e85e940804abf2706230710a6b9d3fe99fee4 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 24 Jun 2014 19:59:26 +0200 Subject: [PATCH 07/30] 8048005: Add test timing information to JMXStartStopTest Reviewed-by: egahlin, dfuchs --- .../sun/management/jmxremote/startstop/JMXStartStopTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java index 09c1fa9d080..f485358eb33 100644 --- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java @@ -290,11 +290,14 @@ public class JMXStartStopTest { public static void main(String args[]) throws Exception { for (Method m : JMXStartStopTest.class.getDeclaredMethods()) { if (m.getName().startsWith("test_")) { + long t1 = System.currentTimeMillis(); try { m.invoke(null); - System.out.println("=== PASSED\n"); + System.out.println("=== PASSED"); } catch (Throwable e) { failures.add(new Failure(e, m.getName() + " failed")); + } finally { + System.out.println("(took " + (System.currentTimeMillis() - t1) + "ms)\n"); } } } From 0caae2d748b8a47eda9e135fcec16258de8ac514 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 24 Jun 2014 14:05:47 -0700 Subject: [PATCH 08/30] 8046273: Add overrides lint warning to build of jdk repository Reviewed-by: tbell --- jdk/make/Setup.gmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/make/Setup.gmk b/jdk/make/Setup.gmk index c4119d787d8..13e513d3274 100644 --- a/jdk/make/Setup.gmk +++ b/jdk/make/Setup.gmk @@ -27,7 +27,7 @@ DISABLE_WARNINGS := -Xlint:all,-deprecation,-unchecked,-rawtypes,-cast,-serial,- # To build with all warnings enabled, do the following: # make JAVAC_WARNINGS="-Xlint:all -Xmaxwarns 10000" -JAVAC_WARNINGS := -Xlint:-unchecked,-deprecation,-overrides,auxiliaryclass,cast,classfile,dep-ann,divzero,empty,fallthrough,finally,overloads,serial,static,try,varargs -Werror +JAVAC_WARNINGS := -Xlint:-unchecked,-deprecation,auxiliaryclass,cast,classfile,dep-ann,divzero,empty,fallthrough,finally,overloads,overrides,serial,static,try,varargs -Werror # Any java code executed during a JDK build to build other parts of the JDK must be # executed by the bootstrap JDK (probably with -Xbootclasspath/p: ) and for this From bfe7a7abd1fcf44ecc7e4acb6ededd55f6b21ed3 Mon Sep 17 00:00:00 2001 From: Mandy Chung Date: Tue, 24 Jun 2014 16:22:57 -0700 Subject: [PATCH 09/30] 8047904: Runtime.loadLibrary throws SecurityException when security manager is installed Reviewed-by: alanb, psandoz --- .../share/classes/java/lang/ClassLoader.java | 23 +++++++------ jdk/src/share/classes/sun/misc/Launcher.java | 33 ++++++++++++------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/jdk/src/share/classes/java/lang/ClassLoader.java b/jdk/src/share/classes/java/lang/ClassLoader.java index 876b1855012..1652d6cc4eb 100644 --- a/jdk/src/share/classes/java/lang/ClassLoader.java +++ b/jdk/src/share/classes/java/lang/ClassLoader.java @@ -1859,18 +1859,17 @@ public abstract class ClassLoader { String name = NativeLibrary.findBuiltinLib(file.getName()); boolean isBuiltin = (name != null); if (!isBuiltin) { - boolean exists = AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - return file.exists() ? Boolean.TRUE : null; - }}) - != null; - if (!exists) { - return false; - } - try { - name = file.getCanonicalPath(); - } catch (IOException e) { + name = AccessController.doPrivileged( + new PrivilegedAction() { + public String run() { + try { + return file.exists() ? file.getCanonicalPath() : null; + } catch (IOException e) { + return null; + } + } + }); + if (name == null) { return false; } } diff --git a/jdk/src/share/classes/sun/misc/Launcher.java b/jdk/src/share/classes/sun/misc/Launcher.java index 89557f711b4..75310f5aa0e 100644 --- a/jdk/src/share/classes/sun/misc/Launcher.java +++ b/jdk/src/share/classes/sun/misc/Launcher.java @@ -207,7 +207,7 @@ public class Launcher { * look in the extension directory itself. */ public String findLibrary(String name) { - name = System.mapLibraryName(name); + final String libname = System.mapLibraryName(name); URL[] urls = super.getURLs(); File prevDir = null; for (int i = 0; i < urls.length; i++) { @@ -216,17 +216,26 @@ public class Launcher { if (dir != null && !dir.equals(prevDir)) { // Look in architecture-specific subdirectory first // Read from the saved system properties to avoid deadlock - String arch = VM.getSavedProperty("os.arch"); - if (arch != null) { - File file = new File(new File(dir, arch), name); - if (file.exists()) { - return file.getAbsolutePath(); - } - } - // Then check the extension directory - File file = new File(dir, name); - if (file.exists()) { - return file.getAbsolutePath(); + final String arch = VM.getSavedProperty("os.arch"); + String pathname = AccessController.doPrivileged( + new PrivilegedAction() { + public String run() { + if (arch != null) { + File file = new File(new File(dir, arch), libname); + if (file.exists()) { + return file.getAbsolutePath(); + } + } + // Then check the extension directory + File file = new File(dir, libname); + if (file.exists()) { + return file.getAbsolutePath(); + } + return null; + } + }); + if (pathname != null) { + return pathname; } } prevDir = dir; From 99a469d169d23b5a6cc1520032072b1ed0e3f860 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Wed, 25 Jun 2014 09:43:47 +0200 Subject: [PATCH 10/30] 8038826: sun/management/jmxremote/startstop/JMXStartStopTest.java fails with "should report port in use" Reviewed-by: sla --- .../jmxremote/startstop/JMXStartStopTest.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java index f485358eb33..4a058cb1f76 100644 --- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java @@ -38,7 +38,9 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +import java.util.function.IntUnaryOperator; import javax.management.*; import javax.management.remote.*; @@ -588,11 +590,11 @@ public class JMXStartStopTest { testConnect(pa.getPort1(), pa.getPort2()); - final boolean[] checks = new boolean[3]; + final AtomicInteger checks = new AtomicInteger(); jcmd( line -> { if (line.contains("java.lang.RuntimeException: Invalid agent state")) { - checks[0] = true; + checks.getAndUpdate((op) -> op | 1); } }, CMD_START, @@ -603,7 +605,7 @@ public class JMXStartStopTest { jcmd( line -> { if (line.contains("java.lang.RuntimeException: Invalid agent state")) { - checks[1] = true; + checks.getAndUpdate((op) -> op | 2); } }, CMD_START, @@ -614,12 +616,14 @@ public class JMXStartStopTest { jcmd(CMD_STOP); jcmd(CMD_STOP); + int busyPort; try (ServerSocket ss = new ServerSocket(0)) { + busyPort = ss.getLocalPort(); jcmd( line -> { - if (line.contains("Port already in use: " + ss.getLocalPort())) { - checks[2] = true; + if (line.contains("Port already in use: " + busyPort)) { + checks.getAndUpdate((op) -> op | 4); } }, CMD_START, @@ -627,19 +631,18 @@ public class JMXStartStopTest { "jmxremote.rmi.port=" + pa.getPort2(), "jmxremote.authenticate=false", "jmxremote.ssl=false"); - - if (!checks[0]) { - throw new Exception("Starting agent on port " + pa.getPort1() + " should " + - "report an invalid agent state"); - } - if (!checks[1]) { - throw new Exception("Starting agent on poprt " + pa.getPort2() + " should " + - "report an invalid agent state"); - } - if (!checks[2]) { - throw new Exception("Starting agent on port " + ss.getLocalPort() + " should " + - "report port in use"); - } + } + if ((checks.get() & 1) == 0) { + throw new Exception("Starting agent on port " + pa.getPort1() + " should " + + "report an invalid agent state"); + } + if ((checks.get() & 2) == 0) { + throw new Exception("Starting agent on poprt " + pa.getPort2() + " should " + + "report an invalid agent state"); + } + if ((checks.get() & 4) == 0) { + throw new Exception("Starting agent on port " + busyPort + " should " + + "report port in use"); } } finally { s.stop(); From ea1882be4f9759f79f47cd8b57699ebcb2adfbc3 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Wed, 25 Jun 2014 18:49:02 +0800 Subject: [PATCH 11/30] 8048073: Cannot read ccache entry with a realm-less service name Reviewed-by: xuelei --- .../internal/ccache/CCacheInputStream.java | 29 ++++++-- .../security/krb5/ccache/EmptyRealmCC.java | 68 +++++++++++++++++++ .../security/krb5/ccache/TimeInCCache.java | 6 +- 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 jdk/test/sun/security/krb5/ccache/EmptyRealmCC.java diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java index 6f745f4fd30..e7707e84807 100644 --- a/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java +++ b/jdk/src/share/classes/sun/security/krb5/internal/ccache/CCacheInputStream.java @@ -334,15 +334,29 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC * returns null. */ Credentials readCred(int version) throws IOException,RealmException, KrbApErrException, Asn1Exception { - PrincipalName cpname = readPrincipal(version); - if (DEBUG) + PrincipalName cpname = null; + try { + cpname = readPrincipal(version); + } catch (Exception e) { + // Do not return here. All data for this cred should be fully + // consumed so that we can read the next one. + } + if (DEBUG) { System.out.println(">>>DEBUG client principal is " + cpname); - PrincipalName spname = readPrincipal(version); - if (DEBUG) + } + PrincipalName spname = null; + try { + spname = readPrincipal(version); + } catch (Exception e) { + // same as above + } + if (DEBUG) { System.out.println(">>>DEBUG server principal is " + spname); + } EncryptionKey key = readKey(version); - if (DEBUG) + if (DEBUG) { System.out.println(">>>DEBUG key type: " + key.getEType()); + } long times[] = readTimes(); KerberosTime authtime = new KerberosTime(times[0]); KerberosTime starttime = @@ -375,6 +389,11 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC byte[] ticketData = readData(); byte[] ticketData2 = readData(); + // Skip this cred if either cpname or spname isn't created. + if (cpname == null || spname == null) { + return null; + } + try { return new Credentials(cpname, spname, key, authtime, starttime, endtime, renewTill, skey, tFlags, diff --git a/jdk/test/sun/security/krb5/ccache/EmptyRealmCC.java b/jdk/test/sun/security/krb5/ccache/EmptyRealmCC.java new file mode 100644 index 00000000000..315cc06a35e --- /dev/null +++ b/jdk/test/sun/security/krb5/ccache/EmptyRealmCC.java @@ -0,0 +1,68 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8048073 + * @summary Cannot read ccache entry with a realm-less service name + * @compile -XDignore.symbol.file EmptyRealmCC.java + * @run main EmptyRealmCC + */ +import java.nio.file.Files; +import java.nio.file.Paths; + +import sun.security.krb5.internal.ccache.CredentialsCache; + +public class EmptyRealmCC { + public static void main(String[] args) throws Exception { + byte[] ccache = TimeInCCache.ccache; + + // The service name starts at 0x52: + // + // 0050: 00 00 00 02 00 00 00 0A 4D 41 58 49 2E 4C + // ----------- ----------- + // 0060: 4F 43 41 4C 00 00 00 06 6B 72 62 74 67 74 00 00 + // ----------- ----- + // 0070: 00 0A 4D 41 58 49 2E 4C 4F 43 41 4C + // ----- + // + // which contains 2 (the length of names), a 10-byte realm, a 6-byte + // name[0], and a 10-byte name[1]. + + // We will empty the realm, and pack the realm string to another + // name (6-byte ".LOCAL"). Finally "krbtgt/MAXI.LOCAL@MAXI.LOCAL" + // becomes ".LOCAL/krbtgt/MAXI.LOCAL@". + + // length of names is now 3 + ccache[0x55] = 3; + // The empty realm + System.arraycopy(new byte[4], 0, ccache, 0x56, 4); + // Length of inserted name is 6 + System.arraycopy(new byte[]{0,0,0,6}, 0, ccache, 0x5A, 4); + + Files.write(Paths.get("tmpcc"), TimeInCCache.ccache); + if (CredentialsCache.getInstance("tmpcc").getCredsList() != null) { + throw new Exception("Nothing should be there"); + } + } +} diff --git a/jdk/test/sun/security/krb5/ccache/TimeInCCache.java b/jdk/test/sun/security/krb5/ccache/TimeInCCache.java index 1bb4e7dfb34..e81ff909b98 100644 --- a/jdk/test/sun/security/krb5/ccache/TimeInCCache.java +++ b/jdk/test/sun/security/krb5/ccache/TimeInCCache.java @@ -28,16 +28,14 @@ */ import java.io.ByteArrayInputStream; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Paths; import sun.security.krb5.internal.ccache.CCacheInputStream; import sun.security.krb5.internal.ccache.Credentials; public class TimeInCCache { - // Attention: this field is also used by CorruptedCC.java test + // Attention: this field is also used by 2 other tests: + // CorruptedCC.java and EmptyRealmCC.java public static byte[] ccache; static { From fd148509ce5d52f3161e22be6877f3768eed908e Mon Sep 17 00:00:00 2001 From: Michael McMahon Date: Wed, 25 Jun 2014 15:55:42 +0100 Subject: [PATCH 12/30] 8029607: Type of Service (TOS) cannot be set in IPv6 header Reviewed-by: alanb --- .../genconstants/ch/genSocketOptionRegistry.c | 1 + .../sun/nio/ch/DatagramChannelImpl.java | 23 ++++--------------- jdk/src/share/classes/sun/nio/ch/Net.java | 5 ++-- .../sun/nio/ch/ServerSocketChannelImpl.java | 9 ++++++++ .../classes/sun/nio/ch/SocketChannelImpl.java | 17 +++++++------- jdk/src/solaris/native/java/net/net_util_md.c | 8 ++++--- jdk/src/solaris/native/sun/nio/ch/Net.c | 9 +++++++- jdk/src/windows/native/sun/nio/ch/Net.c | 2 +- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/jdk/make/src/native/genconstants/ch/genSocketOptionRegistry.c b/jdk/make/src/native/genconstants/ch/genSocketOptionRegistry.c index d5ed5d7a87e..41bd5484ab7 100644 --- a/jdk/make/src/native/genconstants/ch/genSocketOptionRegistry.c +++ b/jdk/make/src/native/genconstants/ch/genSocketOptionRegistry.c @@ -110,6 +110,7 @@ int main(int argc, const char* argv[]) { emit_inet("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IP, IP_MULTICAST_LOOP); #ifdef AF_INET6 + emit_inet6("StandardSocketOptions.IP_TOS", IPPROTO_IPV6, IPV6_TCLASS); emit_inet6("StandardSocketOptions.IP_MULTICAST_IF", IPPROTO_IPV6, IPV6_MULTICAST_IF); emit_inet6("StandardSocketOptions.IP_MULTICAST_TTL", IPPROTO_IPV6, IPV6_MULTICAST_HOPS); emit_inet6("StandardSocketOptions.IP_MULTICAST_LOOP", IPPROTO_IPV6, IPV6_MULTICAST_LOOP); diff --git a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java index fe32f63880b..a34286bddb4 100644 --- a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java @@ -195,15 +195,8 @@ class DatagramChannelImpl synchronized (stateLock) { ensureOpen(); - if (name == StandardSocketOptions.IP_TOS) { - // IPv4 only; no-op for IPv6 - if (family == StandardProtocolFamily.INET) { - Net.setSocketOption(fd, family, name, value); - } - return this; - } - - if (name == StandardSocketOptions.IP_MULTICAST_TTL || + if (name == StandardSocketOptions.IP_TOS || + name == StandardSocketOptions.IP_MULTICAST_TTL || name == StandardSocketOptions.IP_MULTICAST_LOOP) { // options are protocol dependent @@ -256,16 +249,8 @@ class DatagramChannelImpl synchronized (stateLock) { ensureOpen(); - if (name == StandardSocketOptions.IP_TOS) { - // IPv4 only; always return 0 on IPv6 - if (family == StandardProtocolFamily.INET) { - return (T) Net.getSocketOption(fd, family, name); - } else { - return (T) Integer.valueOf(0); - } - } - - if (name == StandardSocketOptions.IP_MULTICAST_TTL || + if (name == StandardSocketOptions.IP_TOS || + name == StandardSocketOptions.IP_MULTICAST_TTL || name == StandardSocketOptions.IP_MULTICAST_LOOP) { return (T) Net.getSocketOption(fd, family, name); diff --git a/jdk/src/share/classes/sun/nio/ch/Net.java b/jdk/src/share/classes/sun/nio/ch/Net.java index 753e5417310..37823e98c55 100644 --- a/jdk/src/share/classes/sun/nio/ch/Net.java +++ b/jdk/src/share/classes/sun/nio/ch/Net.java @@ -352,7 +352,8 @@ public class Net { } boolean mayNeedConversion = (family == UNSPEC); - setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg); + boolean isIPv6 = (family == StandardProtocolFamily.INET6); + setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6); } static Object getSocketOption(FileDescriptor fd, ProtocolFamily family, @@ -499,7 +500,7 @@ public class Net { throws IOException; private static native void setIntOption0(FileDescriptor fd, boolean mayNeedConversion, - int level, int opt, int arg) + int level, int opt, int arg, boolean isIPv6) throws IOException; static native int poll(FileDescriptor fd, int events, long timeout) diff --git a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java index b35cf815272..a7cc1946904 100644 --- a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java @@ -133,6 +133,14 @@ class ServerSocketChannelImpl synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); + + if (name == StandardSocketOptions.IP_TOS) { + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + Net.setSocketOption(fd, family, name, value); + return this; + } + if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { @@ -177,6 +185,7 @@ class ServerSocketChannelImpl HashSet> set = new HashSet>(2); set.add(StandardSocketOptions.SO_RCVBUF); set.add(StandardSocketOptions.SO_REUSEADDR); + set.add(StandardSocketOptions.IP_TOS); return Collections.unmodifiableSet(set); } } diff --git a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java index 3277de9f6a3..a72fe07e4a1 100644 --- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -173,14 +173,14 @@ class SocketChannelImpl if (!isOpen()) throw new ClosedChannelException(); - // special handling for IP_TOS: no-op when IPv6 if (name == StandardSocketOptions.IP_TOS) { - if (!Net.isIPv6Available()) - Net.setSocketOption(fd, StandardProtocolFamily.INET, name, value); + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + Net.setSocketOption(fd, family, name, value); return this; - } else if (name == StandardSocketOptions.SO_REUSEADDR && - Net.useExclusiveBind()) - { + } + + if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { // SO_REUSEADDR emulated when using exclusive bind isReuseAddress = (Boolean)value; return this; @@ -215,8 +215,9 @@ class SocketChannelImpl // special handling for IP_TOS: always return 0 when IPv6 if (name == StandardSocketOptions.IP_TOS) { - return (Net.isIPv6Available()) ? (T) Integer.valueOf(0) : - (T) Net.getSocketOption(fd, StandardProtocolFamily.INET, name); + ProtocolFamily family = Net.isIPv6Available() ? + StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; + return (T) Net.getSocketOption(fd, family, name); } // no options that require special handling diff --git a/jdk/src/solaris/native/java/net/net_util_md.c b/jdk/src/solaris/native/java/net/net_util_md.c index e463d46276f..dedeedb669f 100644 --- a/jdk/src/solaris/native/java/net/net_util_md.c +++ b/jdk/src/solaris/native/java/net/net_util_md.c @@ -1317,7 +1317,7 @@ NET_SetSockOpt(int fd, int level, int opt, const void *arg, * or sending UDP packet. * 2. IPv6 on Linux: By default Linux ignores flowinfo * field so enable IPV6_FLOWINFO_SEND so that flowinfo - * will be examined. + * will be examined. We also set the IPv4 TOS option in this case. * 3. IPv4: set socket option based on ToS and Precedence * fields (otherwise get invalid argument) */ @@ -1333,8 +1333,10 @@ NET_SetSockOpt(int fd, int level, int opt, const void *arg, #if defined(AF_INET6) && defined(__linux__) if (ipv6_available()) { int optval = 1; - return setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, - (void *)&optval, sizeof(optval)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_FLOWINFO_SEND, + (void *)&optval, sizeof(optval)) < 0) { + return -1; + } } #endif diff --git a/jdk/src/solaris/native/sun/nio/ch/Net.c b/jdk/src/solaris/native/sun/nio/ch/Net.c index 92f6f19a43e..8887f59109c 100644 --- a/jdk/src/solaris/native/sun/nio/ch/Net.c +++ b/jdk/src/solaris/native/sun/nio/ch/Net.c @@ -435,7 +435,8 @@ Java_sun_nio_ch_Net_getIntOption0(JNIEnv *env, jclass clazz, jobject fdo, JNIEXPORT void JNICALL Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, - jboolean mayNeedConversion, jint level, jint opt, jint arg) + jboolean mayNeedConversion, jint level, + jint opt, jint arg, jboolean isIPv6) { int result; struct linger linger; @@ -478,6 +479,12 @@ Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, JNU_JAVANETPKG "SocketException", "sun.nio.ch.Net.setIntOption"); } +#ifdef __linux__ + if (level == IPPROTO_IPV6 && opt == IPV6_TCLASS && isIPv6) { + // set the V4 option also + setsockopt(fdval(env, fdo), IPPROTO_IP, IP_TOS, parg, arglen); + } +#endif } JNIEXPORT jint JNICALL diff --git a/jdk/src/windows/native/sun/nio/ch/Net.c b/jdk/src/windows/native/sun/nio/ch/Net.c index 9720d80ef62..fc96ea206ae 100644 --- a/jdk/src/windows/native/sun/nio/ch/Net.c +++ b/jdk/src/windows/native/sun/nio/ch/Net.c @@ -319,7 +319,7 @@ Java_sun_nio_ch_Net_getIntOption0(JNIEnv *env, jclass clazz, jobject fdo, JNIEXPORT void JNICALL Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, - jboolean mayNeedConversion, jint level, jint opt, jint arg) + jboolean mayNeedConversion, jint level, jint opt, jint arg, jboolean ipv6) { struct linger linger; char *parg; From 6c860a781a7da9ca6702de17d82bb230467bf4eb Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Wed, 25 Jun 2014 12:36:03 -0700 Subject: [PATCH 13/30] 8047795: Collections.checkedList checking bypassed by List.replaceAll Reviewed-by: psandoz, chegar --- .../share/classes/java/util/Collections.java | 23 +++++--- .../Collections/CheckedListReplaceAll.java | 50 +++++++++++++++++ .../Collections/CheckedMapReplaceAll.java | 54 +++++++++++++++++++ 3 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 jdk/test/java/util/Collections/CheckedListReplaceAll.java create mode 100644 jdk/test/java/util/Collections/CheckedMapReplaceAll.java diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java index e229f5f5dd4..0c0a105513e 100644 --- a/jdk/src/share/classes/java/util/Collections.java +++ b/jdk/src/share/classes/java/util/Collections.java @@ -3031,9 +3031,11 @@ public class Collections { final Collection c; final Class type; - void typeCheck(Object o) { + @SuppressWarnings("unchecked") + E typeCheck(Object o) { if (o != null && !type.isInstance(o)) throw new ClassCastException(badElementMsg(o)); + return (E) o; } private String badElementMsg(Object o) { @@ -3042,10 +3044,8 @@ public class Collections { } CheckedCollection(Collection c, Class type) { - if (c==null || type == null) - throw new NullPointerException(); - this.c = c; - this.type = type; + this.c = Objects.requireNonNull(c, "c"); + this.type = Objects.requireNonNull(type, "type"); } public int size() { return c.size(); } @@ -3091,7 +3091,7 @@ public class Collections { @SuppressWarnings("unchecked") Collection checkedCopyOf(Collection coll) { - Object[] a = null; + Object[] a; try { E[] z = zeroLengthElementArray(); a = coll.toArray(z); @@ -3487,10 +3487,19 @@ public class Collections { return new CheckedList<>(list.subList(fromIndex, toIndex), type); } + /** + * {@inheritDoc} + * + * @throws ClassCastException if the class of an element returned by the + * operator prevents it from being added to this collection. The + * exception may be thrown after some elements of the list have + * already been replaced. + */ @Override public void replaceAll(UnaryOperator operator) { - list.replaceAll(operator); + list.replaceAll(e -> typeCheck(operator.apply(e))); } + @Override public void sort(Comparator c) { list.sort(c); diff --git a/jdk/test/java/util/Collections/CheckedListReplaceAll.java b/jdk/test/java/util/Collections/CheckedListReplaceAll.java new file mode 100644 index 00000000000..8ac05d095f2 --- /dev/null +++ b/jdk/test/java/util/Collections/CheckedListReplaceAll.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. + */ + +/* + * @test + * @bug 8047795 + * @summary Ensure that replaceAll operator cannot add bad elements + * @author Mike Duigou + */ + +import java.util.*; +import java.util.function.UnaryOperator; + +public class CheckedListReplaceAll { + public static void main(String[] args) { + List unwrapped = Arrays.asList(new Object[]{1, 2, 3}); + List wrapped = Collections.checkedList(unwrapped, Integer.class); + + UnaryOperator evil = e -> (((int) e) % 2 != 0) ? e : "evil"; + + try { + wrapped.replaceAll(evil); + System.out.printf("Bwahaha! I have defeated you! %s\n", wrapped); + throw new RuntimeException("String added to checked List"); + } catch (ClassCastException thwarted) { + thwarted.printStackTrace(System.out); + System.out.println("Curses! Foiled again!"); + } + } +} diff --git a/jdk/test/java/util/Collections/CheckedMapReplaceAll.java b/jdk/test/java/util/Collections/CheckedMapReplaceAll.java new file mode 100644 index 00000000000..05c4da3ad5e --- /dev/null +++ b/jdk/test/java/util/Collections/CheckedMapReplaceAll.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8047795 + * @summary Ensure that replaceAll operator cannot add bad elements + * @author Mike Duigou + */ + +import java.util.*; +import java.util.function.BiFunction; + +public class CheckedMapReplaceAll { + public static void main(String[] args) { + Map unwrapped = new HashMap<>(); + unwrapped.put(1, 1.0); + unwrapped.put(2, 2.0); + unwrapped.put(3, 3.0); + + Map wrapped = Collections.checkedMap(unwrapped, Integer.class, Double.class); + + BiFunction evil = (k, v) -> (((int)k) % 2 != 0) ? v : "evil"; + + try { + wrapped.replaceAll(evil); + System.out.printf("Bwahaha! I have defeated you! %s\n", wrapped); + throw new RuntimeException("String added to checked Map"); + } catch (ClassCastException thwarted) { + thwarted.printStackTrace(System.out); + System.out.println("Curses! Foiled again!"); + } + } +} From 689a3bb8c1d77161e09078d8e764fdacfc9e53a1 Mon Sep 17 00:00:00 2001 From: Rocky Sloan Date: Thu, 26 Jun 2014 15:58:06 +0400 Subject: [PATCH 14/30] 8044281: Fix doclint warnings (missing javadoc tags) in javax.swing.table Reviewed-by: alexsch --- .../javax/swing/table/DefaultTableColumnModel.java | 2 ++ .../javax/swing/table/DefaultTableModel.java | 5 +++++ .../classes/javax/swing/table/JTableHeader.java | 10 ++++++++++ .../javax/swing/table/TableCellRenderer.java | 5 ++++- .../classes/javax/swing/table/TableColumn.java | 13 ++++++++++++- .../classes/javax/swing/table/TableColumnModel.java | 5 ++++- 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java b/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java index 96193cb35fd..7e02789f837 100644 --- a/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java +++ b/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java @@ -716,6 +716,8 @@ public class DefaultTableColumnModel implements TableColumnModel, /** * Creates a new default list selection model. + * + * @return a newly created default list selection model. */ protected ListSelectionModel createSelectionModel() { return new DefaultListSelectionModel(); diff --git a/jdk/src/share/classes/javax/swing/table/DefaultTableModel.java b/jdk/src/share/classes/javax/swing/table/DefaultTableModel.java index 74b88c1160d..251738ae40d 100644 --- a/jdk/src/share/classes/javax/swing/table/DefaultTableModel.java +++ b/jdk/src/share/classes/javax/swing/table/DefaultTableModel.java @@ -335,6 +335,8 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl * * @see #setColumnCount * @since 1.3 + * + * @param rowCount number of rows in the model */ public void setRowCount(int rowCount) { setNumRows(rowCount); @@ -577,6 +579,9 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl * element going to row 0, etc. This method will send a * tableChanged notification message to all the listeners. * + * @param columnName identifier of the newly created column + * @param columnData new data to be added to the column + * * @see #addColumn(Object, Vector) */ public void addColumn(Object columnName, Object[] columnData) { diff --git a/jdk/src/share/classes/javax/swing/table/JTableHeader.java b/jdk/src/share/classes/javax/swing/table/JTableHeader.java index 3995cccc288..5e923b1356d 100644 --- a/jdk/src/share/classes/javax/swing/table/JTableHeader.java +++ b/jdk/src/share/classes/javax/swing/table/JTableHeader.java @@ -336,6 +336,10 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * Returns the index of the column that point lies in, or -1 if it * lies out of bounds. * + * @param point if this point lies within a column, the index of + * that column will be returned; otherwise it is out of bounds + * and -1 is returned + * * @return the index of the column that point lies in, or -1 if it * lies out of bounds */ @@ -352,6 +356,8 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * When the column parameter is out of bounds this method uses the * same conventions as the JTable method getCellRect. * + * @param column index of the column + * * @return the rectangle containing the header tile at column * @see JTable#getCellRect */ @@ -883,6 +889,10 @@ public class JTableHeader extends JComponent implements TableColumnModelListener /** * Constructs an AccessiblJTableHeaaderEntry * @since 1.4 + * + * @param c the column index + * @param p the parent JTableHeader + * @param t the table JTable */ public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) { parent = p; diff --git a/jdk/src/share/classes/javax/swing/table/TableCellRenderer.java b/jdk/src/share/classes/javax/swing/table/TableCellRenderer.java index 892220bc47c..585d9221482 100644 --- a/jdk/src/share/classes/javax/swing/table/TableCellRenderer.java +++ b/jdk/src/share/classes/javax/swing/table/TableCellRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -86,6 +86,9 @@ public interface TableCellRenderer { * drawing the header, the value of * row is -1 * @param column the column index of the cell being drawn + * + * @return the component used for drawing the cell. + * * @see javax.swing.JComponent#isPaintingForPrint() */ Component getTableCellRendererComponent(JTable table, Object value, diff --git a/jdk/src/share/classes/javax/swing/table/TableColumn.java b/jdk/src/share/classes/javax/swing/table/TableColumn.java index 713bf5483dc..1f116c47832 100644 --- a/jdk/src/share/classes/javax/swing/table/TableColumn.java +++ b/jdk/src/share/classes/javax/swing/table/TableColumn.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -201,6 +201,11 @@ public class TableColumn extends Object implements Serializable { * Cover method, using a default width of 75, a null * renderer and a null editor. * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor) + * + * @param modelIndex the index of the column in the model + * that supplies the data for this column in the table; + * the model index remains the same even when columns + * are reordered in the view */ public TableColumn(int modelIndex) { this(modelIndex, 75, null, null); @@ -210,6 +215,12 @@ public class TableColumn extends Object implements Serializable { * Cover method, using a null renderer and a * null editor. * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor) + * + * @param modelIndex the index of the column in the model + * that supplies the data for this column in the table; + * the model index remains the same even when columns + * are reordered in the view + * @param width this column's preferred width and initial width */ public TableColumn(int modelIndex, int width) { this(modelIndex, width, null, null); diff --git a/jdk/src/share/classes/javax/swing/table/TableColumnModel.java b/jdk/src/share/classes/javax/swing/table/TableColumnModel.java index b6c308c0ea7..eaaa8447ef7 100644 --- a/jdk/src/share/classes/javax/swing/table/TableColumnModel.java +++ b/jdk/src/share/classes/javax/swing/table/TableColumnModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -162,6 +162,9 @@ public interface TableColumnModel * model. If the column index for a given X coordinate in 2D space is * required, JTable.columnAtPoint can be used instead. * + * @param xPosition width from the start of the first column in + * the model. + * * @return the index of the column; or -1 if no column is found * @see javax.swing.JTable#columnAtPoint */ From 1d0d27c3127392217b63cf4350e0fc0fd45ea608 Mon Sep 17 00:00:00 2001 From: Rocky Sloan Date: Thu, 26 Jun 2014 15:59:57 +0400 Subject: [PATCH 15/30] 8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth Reviewed-by: alexsch --- .../javax/swing/plaf/synth/SynthButtonUI.java | 9 ++++++++- .../javax/swing/plaf/synth/SynthGraphicsUtils.java | 13 ++++++++++++- .../javax/swing/plaf/synth/SynthSeparatorUI.java | 14 +++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java index 38900d04b43..4bfa159602c 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -513,6 +513,13 @@ public class SynthButtonUI extends BasicButtonUI implements /** * Returns the Icon used in calculating the * preferred/minimum/maximum size. + * + * @param b specifies the {@code AbstractButton} + * used when calculating the preferred/minimum/maximum + * size. + * + * @return the Icon used in calculating the + * preferred/minimum/maximum size. */ protected Icon getSizingIcon(AbstractButton b) { Icon icon = getEnabledIcon(b, b.getIcon()); diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java index 9f68e956a48..8464dd25e49 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -137,6 +137,9 @@ public class SynthGraphicsUtils { * @param iconR Rectangle to place icon bounds in * @param textR Rectangle to place text in * @param iconTextGap gap between icon and text + * + * @return by reference, the location to + * place the icon and text. */ public String layoutText(SynthContext ss, FontMetrics fm, String text, Icon icon, int hAlign, @@ -166,6 +169,8 @@ public class SynthGraphicsUtils { * @param font Font to use * @param metrics FontMetrics, may be ignored * @param text Text to get size of. + * + * @return the size of the passed in string. */ public int computeStringWidth(SynthContext ss, Font font, FontMetrics metrics, String text) { @@ -187,6 +192,8 @@ public class SynthGraphicsUtils { * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. + * + * @return the minimum size needed to properly render an icon and text. */ public Dimension getMinimumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, @@ -218,6 +225,8 @@ public class SynthGraphicsUtils { * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. + * + * @return the maximum size needed to properly render an icon and text. */ public Dimension getMaximumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, @@ -263,6 +272,8 @@ public class SynthGraphicsUtils { * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. + * + * @return the preferred size needed to properly render an icon and text. */ public Dimension getPreferredSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthSeparatorUI.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthSeparatorUI.java index 158e16bd5c9..a222a428080 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthSeparatorUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthSeparatorUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -78,6 +78,9 @@ public class SynthSeparatorUI extends SeparatorUI /** * Installs default setting. This method is called when a * {@code LookAndFeel} is installed. + * + * @param c specifies the {@code JSeparator} for the installed + * {@code LookAndFeel}. */ public void installDefaults(JSeparator c) { updateStyle(c); @@ -109,6 +112,9 @@ public class SynthSeparatorUI extends SeparatorUI /** * Uninstalls default setting. This method is called when a * {@code LookAndFeel} is uninstalled. + * + * @param c specifies the {@code JSeparator} for the (un)installed + * {@code LookAndFeel}. */ public void uninstallDefaults(JSeparator c) { SynthContext context = getContext(c, ENABLED); @@ -121,6 +127,9 @@ public class SynthSeparatorUI extends SeparatorUI /** * Installs listeners. This method is called when a * {@code LookAndFeel} is installed. + * + * @param c specifies the {@code JSeparator} for the installed + * {@code LookAndFeel}. */ public void installListeners(JSeparator c) { c.addPropertyChangeListener(this); @@ -129,6 +138,9 @@ public class SynthSeparatorUI extends SeparatorUI /** * Uninstalls listeners. This method is called when a * {@code LookAndFeel} is uninstalled. + * + * @param c specifies the {@code JSeparator} for the (un)installed + * {@code LookAndFeel}. */ public void uninstallListeners(JSeparator c) { c.removePropertyChangeListener(this); From 72fb4c3adf1b6691bf79d54b2e6e77be9fe07970 Mon Sep 17 00:00:00 2001 From: Naoto Sato Date: Thu, 26 Jun 2014 10:48:43 -0700 Subject: [PATCH 16/30] 8039317: Read currency.data as a resource Reviewed-by: alanb, chegar --- jdk/make/GenerateData.gmk | 2 +- jdk/make/profile-includes.txt | 1 - jdk/src/share/classes/java/util/Currency.java | 10 +++------- jdk/test/java/util/Currency/CheckDataVersion.java | 3 ++- jdk/test/java/util/Currency/CurrencyTest.java | 4 ++-- jdk/test/java/util/Currency/ValidateISO4217.java | 3 ++- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/jdk/make/GenerateData.gmk b/jdk/make/GenerateData.gmk index 28faec4826a..437dd0b1d38 100644 --- a/jdk/make/GenerateData.gmk +++ b/jdk/make/GenerateData.gmk @@ -62,7 +62,7 @@ GENDATA += $(GENDATA_UNINAME) ########################################################################################## -GENDATA_CURDATA := $(JDK_OUTPUTDIR)/lib/currency.data +GENDATA_CURDATA := $(JDK_OUTPUTDIR)/classes/java/util/currency.data $(GENDATA_CURDATA): $(JDK_TOPDIR)/make/data/currency/CurrencyData.properties $(BUILD_TOOLS) $(MKDIR) -p $(@D) diff --git a/jdk/make/profile-includes.txt b/jdk/make/profile-includes.txt index 2d013fc26fe..17728a7f3d9 100644 --- a/jdk/make/profile-includes.txt +++ b/jdk/make/profile-includes.txt @@ -56,7 +56,6 @@ PROFILE_1_JRE_LIB_FILES := \ $(OPENJDK_TARGET_CPU_LEGACY_LIB)/server/Xusage.txt \ calendars.properties \ classlist \ - currency.data \ ext/localedata.jar \ ext/meta-index \ ext/sunec.jar \ diff --git a/jdk/src/share/classes/java/util/Currency.java b/jdk/src/share/classes/java/util/Currency.java index 2c4a2e720be..5af9c7193ca 100644 --- a/jdk/src/share/classes/java/util/Currency.java +++ b/jdk/src/share/classes/java/util/Currency.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -212,13 +212,9 @@ public final class Currency implements Serializable { AccessController.doPrivileged(new PrivilegedAction() { @Override public Void run() { - String homeDir = System.getProperty("java.home"); try { - String dataFile = homeDir + File.separator + - "lib" + File.separator + "currency.data"; try (DataInputStream dis = new DataInputStream( - new BufferedInputStream( - new FileInputStream(dataFile)))) { + new BufferedInputStream(getClass().getResourceAsStream("/java/util/currency.data")))) { if (dis.readInt() != MAGIC_NUMBER) { throw new InternalError("Currency data is possibly corrupted"); } @@ -248,7 +244,7 @@ public final class Currency implements Serializable { // look for the properties file for overrides String propsFile = System.getProperty("java.util.currency.data"); if (propsFile == null) { - propsFile = homeDir + File.separator + "lib" + + propsFile = System.getProperty("java.home") + File.separator + "lib" + File.separator + "currency.properties"; } try { diff --git a/jdk/test/java/util/Currency/CheckDataVersion.java b/jdk/test/java/util/Currency/CheckDataVersion.java index be8b9417c68..70320cbb330 100644 --- a/jdk/test/java/util/Currency/CheckDataVersion.java +++ b/jdk/test/java/util/Currency/CheckDataVersion.java @@ -64,7 +64,8 @@ class CheckDataVersion { public Object run() { try { String sep = File.separator; - DataInputStream dis = new DataInputStream(new FileInputStream(System.getProperty("java.home")+sep+"lib"+sep+"currency.data")); + DataInputStream dis = new DataInputStream( + new BufferedInputStream(getClass().getResourceAsStream("/java/util/currency.data"))); int magic = dis.readInt(); if (magic != 0x43757244) { throw new RuntimeException("The magic number in the JRE's currency data is incorrect. Expected: 0x43757244, Got: 0x"+magic); diff --git a/jdk/test/java/util/Currency/CurrencyTest.java b/jdk/test/java/util/Currency/CurrencyTest.java index 6971442bfb0..372071e9371 100644 --- a/jdk/test/java/util/Currency/CurrencyTest.java +++ b/jdk/test/java/util/Currency/CurrencyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -23,7 +23,7 @@ /* * @test * @bug 4290801 4692419 4693631 5101540 5104960 6296410 6336600 6371531 - * 6488442 7036905 + * 6488442 7036905 8039317 * @summary Basic tests for Currency class. */ diff --git a/jdk/test/java/util/Currency/ValidateISO4217.java b/jdk/test/java/util/Currency/ValidateISO4217.java index bf433a1c8ed..17c76f79290 100644 --- a/jdk/test/java/util/Currency/ValidateISO4217.java +++ b/jdk/test/java/util/Currency/ValidateISO4217.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -23,6 +23,7 @@ /* * @test * @bug 4691089 4819436 4942982 5104960 6544471 6627549 7066203 7195759 + * 8039317 * @summary Validate ISO 4217 data for Currency class. */ From 589ee38cbdb09bade6a06873e805ac217a8f3398 Mon Sep 17 00:00:00 2001 From: Ivan Gerasimov Date: Fri, 27 Jun 2014 08:03:35 +0400 Subject: [PATCH 17/30] 8048080: (smartcardio) javax.smartcardio.Card.openLogicalChannel() dosn't work on MacOSX Reviewed-by: valeriep --- .../security/smartcardio/MUSCLE/pcsclite.h | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/jdk/src/solaris/native/sun/security/smartcardio/MUSCLE/pcsclite.h b/jdk/src/solaris/native/sun/security/smartcardio/MUSCLE/pcsclite.h index 02e7035b31c..251d83de930 100644 --- a/jdk/src/solaris/native/sun/security/smartcardio/MUSCLE/pcsclite.h +++ b/jdk/src/solaris/native/sun/security/smartcardio/MUSCLE/pcsclite.h @@ -75,6 +75,13 @@ typedef struct } SCARD_READERSTATE_A; +typedef struct _SCARD_IO_REQUEST +{ + unsigned long dwProtocol; /* Protocol identifier */ + unsigned long cbPciLength; /* Protocol Control Inf Length */ +} +SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST; + #else // __APPLE__ #pragma pack(1) @@ -88,6 +95,13 @@ typedef struct unsigned char rgbAtr[MAX_ATR_SIZE]; } SCARD_READERSTATE_A; + +typedef struct _SCARD_IO_REQUEST +{ + uint32_t dwProtocol; /* Protocol identifier */ + uint32_t cbPciLength; /* Protocol Control Inf Length */ +} +SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST; #pragma pack() #endif // __APPLE__ @@ -95,13 +109,6 @@ SCARD_READERSTATE_A; typedef SCARD_READERSTATE_A SCARD_READERSTATE, *PSCARD_READERSTATE_A, *LPSCARD_READERSTATE_A; -typedef struct _SCARD_IO_REQUEST -{ - unsigned long dwProtocol; /* Protocol identifier */ - unsigned long cbPciLength; /* Protocol Control Inf Length */ -} -SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST; - typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST; extern SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, From a8306dd34f5939e299964597e5e9cde922f112b3 Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Mon, 16 Jun 2014 09:44:54 -0700 Subject: [PATCH 18/30] 8047721: @since should have JDK version Reviewed-by: darcy, wetmore --- jdk/src/share/classes/java/lang/Package.java | 1 + jdk/src/share/classes/javax/crypto/CipherInputStream.java | 7 ------- jdk/src/share/classes/javax/crypto/CipherOutputStream.java | 5 ----- jdk/src/share/classes/javax/naming/InitialContext.java | 2 +- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/jdk/src/share/classes/java/lang/Package.java b/jdk/src/share/classes/java/lang/Package.java index f59176f558e..95abe98cd4b 100644 --- a/jdk/src/share/classes/java/lang/Package.java +++ b/jdk/src/share/classes/java/lang/Package.java @@ -107,6 +107,7 @@ import java.lang.annotation.Annotation; * loader to be found. * * @see ClassLoader#definePackage + * @since 1.2 */ public class Package implements java.lang.reflect.AnnotatedElement { /** diff --git a/jdk/src/share/classes/javax/crypto/CipherInputStream.java b/jdk/src/share/classes/javax/crypto/CipherInputStream.java index 0e80a6013d5..f9be4611d83 100644 --- a/jdk/src/share/classes/javax/crypto/CipherInputStream.java +++ b/jdk/src/share/classes/javax/crypto/CipherInputStream.java @@ -170,7 +170,6 @@ public class CipherInputStream extends FilterInputStream { * @return the next byte of data, or -1 if the end of the * stream is reached. * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public int read() throws IOException { if (ostart >= ofinish) { @@ -196,7 +195,6 @@ public class CipherInputStream extends FilterInputStream { * the stream has been reached. * @exception IOException if an I/O error occurs. * @see java.io.InputStream#read(byte[], int, int) - * @since JCE1.2 */ public int read(byte b[]) throws IOException { return read(b, 0, b.length); @@ -217,7 +215,6 @@ public class CipherInputStream extends FilterInputStream { * the stream has been reached. * @exception IOException if an I/O error occurs. * @see java.io.InputStream#read() - * @since JCE1.2 */ public int read(byte b[], int off, int len) throws IOException { if (ostart >= ofinish) { @@ -254,7 +251,6 @@ public class CipherInputStream extends FilterInputStream { * @param n the number of bytes to be skipped. * @return the actual number of bytes skipped. * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public long skip(long n) throws IOException { int available = ofinish - ostart; @@ -277,7 +273,6 @@ public class CipherInputStream extends FilterInputStream { * @return the number of bytes that can be read from this input stream * without blocking. * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public int available() throws IOException { return (ofinish - ostart); @@ -292,7 +287,6 @@ public class CipherInputStream extends FilterInputStream { * stream. * * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public void close() throws IOException { if (closed) { @@ -321,7 +315,6 @@ public class CipherInputStream extends FilterInputStream { * mark and reset methods. * @see java.io.InputStream#mark(int) * @see java.io.InputStream#reset() - * @since JCE1.2 */ public boolean markSupported() { return false; diff --git a/jdk/src/share/classes/javax/crypto/CipherOutputStream.java b/jdk/src/share/classes/javax/crypto/CipherOutputStream.java index 6b8d2734901..40e7dc49a6a 100644 --- a/jdk/src/share/classes/javax/crypto/CipherOutputStream.java +++ b/jdk/src/share/classes/javax/crypto/CipherOutputStream.java @@ -114,7 +114,6 @@ public class CipherOutputStream extends FilterOutputStream { * * @param b the byte. * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public void write(int b) throws IOException { ibuffer[0] = (byte) b; @@ -138,7 +137,6 @@ public class CipherOutputStream extends FilterOutputStream { * @exception NullPointerException if b is null. * @exception IOException if an I/O error occurs. * @see javax.crypto.CipherOutputStream#write(byte[], int, int) - * @since JCE1.2 */ public void write(byte b[]) throws IOException { write(b, 0, b.length); @@ -152,7 +150,6 @@ public class CipherOutputStream extends FilterOutputStream { * @param off the start offset in the data. * @param len the number of bytes to write. * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public void write(byte b[], int off, int len) throws IOException { obuffer = cipher.update(b, off, len); @@ -174,7 +171,6 @@ public class CipherOutputStream extends FilterOutputStream { * the cipher's block size, no bytes will be written out. * * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public void flush() throws IOException { if (obuffer != null) { @@ -198,7 +194,6 @@ public class CipherOutputStream extends FilterOutputStream { * stream. * * @exception IOException if an I/O error occurs. - * @since JCE1.2 */ public void close() throws IOException { if (closed) { diff --git a/jdk/src/share/classes/javax/naming/InitialContext.java b/jdk/src/share/classes/javax/naming/InitialContext.java index 7d5b6b45374..867af4ca598 100644 --- a/jdk/src/share/classes/javax/naming/InitialContext.java +++ b/jdk/src/share/classes/javax/naming/InitialContext.java @@ -125,7 +125,7 @@ import com.sun.naming.internal.ResourceManager; * @see Context * @see NamingManager#setInitialContextFactoryBuilder * NamingManager.setInitialContextFactoryBuilder - * @since JNDI 1.1 / Java 2 Platform, Standard Edition, v 1.3 + * @since 1.3, JNDI 1.1 */ public class InitialContext implements Context { From efbff37c1a061b96bb2b44c277b9816967b32c8a Mon Sep 17 00:00:00 2001 From: Mike Duigou Date: Fri, 27 Jun 2014 10:26:39 -0700 Subject: [PATCH 19/30] 8048207: Collections.checkedQueue.offer() calls add on wrapped queue Reviewed-by: psandoz --- .../share/classes/java/util/Collections.java | 23 +--- .../java/util/Collections/CheckedQueue.java | 118 ++++++------------ 2 files changed, 46 insertions(+), 95 deletions(-) diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java index 0c0a105513e..f6a65c7b106 100644 --- a/jdk/src/share/classes/java/util/Collections.java +++ b/jdk/src/share/classes/java/util/Collections.java @@ -3077,10 +3077,7 @@ public class Collections { public void remove() { it.remove(); }}; } - public boolean add(E e) { - typeCheck(e); - return c.add(e); - } + public boolean add(E e) { return c.add(typeCheck(e)); } private E[] zeroLengthElementArray; // Lazily initialized @@ -3187,11 +3184,7 @@ public class Collections { public E peek() {return queue.peek();} public E poll() {return queue.poll();} public E remove() {return queue.remove();} - - public boolean offer(E e) { - typeCheck(e); - return add(e); - } + public boolean offer(E e) {return queue.offer(typeCheck(e));} } /** @@ -3440,13 +3433,11 @@ public class Collections { public int lastIndexOf(Object o) { return list.lastIndexOf(o); } public E set(int index, E element) { - typeCheck(element); - return list.set(index, element); + return list.set(index, typeCheck(element)); } public void add(int index, E element) { - typeCheck(element); - list.add(index, element); + list.add(index, typeCheck(element)); } public boolean addAll(int index, Collection c) { @@ -3467,13 +3458,11 @@ public class Collections { public void remove() { i.remove(); } public void set(E e) { - typeCheck(e); - i.set(e); + i.set(typeCheck(e)); } public void add(E e) { - typeCheck(e); - i.add(e); + i.add(typeCheck(e)); } @Override diff --git a/jdk/test/java/util/Collections/CheckedQueue.java b/jdk/test/java/util/Collections/CheckedQueue.java index 6f28e12e9ef..fb47e2e5ca1 100644 --- a/jdk/test/java/util/Collections/CheckedQueue.java +++ b/jdk/test/java/util/Collections/CheckedQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -23,55 +23,40 @@ /* * @test - * @bug 5020931 + * @bug 5020931 8048207 * @summary Unit test for Collections.checkedQueue + * @run testng CheckedQueue */ -import java.lang.reflect.Method; import java.util.Collections; -import java.util.Iterator; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; +import org.testng.annotations.Test; +import static org.testng.Assert.fail; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; + + public class CheckedQueue { - static int status = 0; - - public static void main(String[] args) throws Exception { - new CheckedQueue(); - } - - public CheckedQueue() throws Exception { - run(); - } - - private void run() throws Exception { - Method[] methods = this.getClass().getDeclaredMethods(); - - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; - String methodName = method.getName(); - - if (methodName.startsWith("test")) { - try { - Object obj = method.invoke(this, new Object[0]); - } catch(Exception e) { - throw new Exception(this.getClass().getName() + "." + - methodName + " test failed, test exception " - + "follows\n" + e.getCause()); - } - } - } - } /** * This test adds items to a queue. */ - private void test00() { + @Test + public void testAdd() { int arrayLength = 10; - ArrayBlockingQueue abq = new ArrayBlockingQueue(arrayLength); + Queue abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class); for (int i = 0; i < arrayLength; i++) { - abq.add(new String(Integer.toString(i))); + abq.add(Integer.toString(i)); + } + + try { + abq.add("full"); + } catch (IllegalStateException full) { + } } @@ -80,23 +65,17 @@ public class CheckedQueue { * {@code String}s gets the checked queue, and attempt to add an Integer to * the checked queue. */ - private void test01() throws Exception { + @Test(expectedExceptions = ClassCastException.class) + public void testAddFail1() { int arrayLength = 10; ArrayBlockingQueue abq = new ArrayBlockingQueue(arrayLength + 1); for (int i = 0; i < arrayLength; i++) { - abq.add(new String(Integer.toString(i))); + abq.add(Integer.toString(i)); } Queue q = Collections.checkedQueue(abq, String.class); - - try { - q.add(new Integer(0)); - throw new Exception(this.getClass().getName() + "." + "test01 test" - + " failed, should throw ClassCastException."); - } catch(ClassCastException cce) { - // Do nothing. - } + q.add(0); } /** @@ -104,47 +83,40 @@ public class CheckedQueue { * {@code String}, gets the checked queue, and attempt to add an Integer to * the checked queue. */ - private void test02() throws Exception { + @Test(expectedExceptions = ClassCastException.class) + public void testAddFail2() { ArrayBlockingQueue abq = new ArrayBlockingQueue(1); Queue q = Collections.checkedQueue(abq, String.class); - try { - q.add(new Integer(0)); - throw new Exception(this.getClass().getName() + "." + "test02 test" - + " failed, should throw ClassCastException."); - } catch(ClassCastException e) { - // Do nothing. - } + q.add(0); } /** * This test tests the Collections.checkedQueue method call for nulls in * each and both of the parameters. */ - private void test03() throws Exception { + @Test + public void testArgs() { ArrayBlockingQueue abq = new ArrayBlockingQueue(1); Queue q; try { q = Collections.checkedQueue(null, String.class); - throw new Exception(this.getClass().getName() + "." + "test03 test" - + " failed, should throw NullPointerException."); + fail( "should throw NullPointerException."); } catch(NullPointerException npe) { // Do nothing } try { q = Collections.checkedQueue(abq, null); - throw new Exception(this.getClass().getName() + "." + "test03 test" - + " failed, should throw NullPointerException."); + fail( "should throw NullPointerException."); } catch(Exception e) { // Do nothing } try { q = Collections.checkedQueue(null, null); - throw new Exception(this.getClass().getName() + "." + "test03 test" - + " failed, should throw NullPointerException."); + fail( "should throw NullPointerException."); } catch(Exception e) { // Do nothing } @@ -153,38 +125,28 @@ public class CheckedQueue { /** * This test tests the CheckedQueue.offer method. */ - private void test04() throws Exception { + @Test + public void testOffer() { ArrayBlockingQueue abq = new ArrayBlockingQueue(1); Queue q = Collections.checkedQueue(abq, String.class); try { q.offer(null); - throw new Exception(this.getClass().getName() + "." + "test04 test" - + " failed, should throw NullPointerException."); + fail("should throw NullPointerException."); } catch (NullPointerException npe) { // Do nothing } try { - q.offer(new Integer(0)); - throw new Exception(this.getClass().getName() + "." + "test04 test" - + " failed, should throw ClassCastException."); + q.offer(0); + fail("should throw ClassCastException."); } catch (ClassCastException cce) { // Do nothing } - q.offer(new String("0")); - - try { - q.offer(new String("1")); - throw new Exception(this.getClass().getName() + "." + "test04 test" - + " failed, should throw IllegalStateException."); - } catch(IllegalStateException ise) { - // Do nothing - } - } - - private void test05() { + assertTrue(q.offer("0"), "queue should have room"); + // no room at the inn! + assertFalse(q.offer("1"), "queue should be full"); } } From c75f8957e82d11a0c952a118f71c094396f7db26 Mon Sep 17 00:00:00 2001 From: Andrei Eremeev Date: Mon, 30 Jun 2014 16:32:36 +0400 Subject: [PATCH 20/30] 8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch --- .../javax/swing/plaf/metal/MetalBorders.java | 75 +++++++- .../javax/swing/plaf/metal/MetalButtonUI.java | 35 ++++ .../swing/plaf/metal/MetalCheckBoxIcon.java | 13 ++ .../swing/plaf/metal/MetalCheckBoxUI.java | 7 + .../swing/plaf/metal/MetalComboBoxButton.java | 70 +++++++ .../swing/plaf/metal/MetalComboBoxEditor.java | 3 + .../swing/plaf/metal/MetalComboBoxUI.java | 24 +++ .../swing/plaf/metal/MetalDesktopIconUI.java | 9 + .../swing/plaf/metal/MetalFileChooserUI.java | 127 ++++++++++-- .../swing/plaf/metal/MetalIconFactory.java | 180 +++++++++++++++++- .../metal/MetalInternalFrameTitlePane.java | 26 +++ .../plaf/metal/MetalInternalFrameUI.java | 20 ++ .../javax/swing/plaf/metal/MetalLabelUI.java | 6 + .../plaf/metal/MetalPopupMenuSeparatorUI.java | 6 + .../swing/plaf/metal/MetalProgressBarUI.java | 6 + .../swing/plaf/metal/MetalRadioButtonUI.java | 34 ++++ .../swing/plaf/metal/MetalScrollBarUI.java | 27 ++- .../swing/plaf/metal/MetalScrollButton.java | 43 ++--- .../swing/plaf/metal/MetalScrollPaneUI.java | 12 ++ .../swing/plaf/metal/MetalSeparatorUI.java | 6 + .../javax/swing/plaf/metal/MetalSliderUI.java | 57 +++++- .../swing/plaf/metal/MetalSplitPaneUI.java | 13 +- .../swing/plaf/metal/MetalTabbedPaneUI.java | 104 +++++++++- .../swing/plaf/metal/MetalTextFieldUI.java | 6 + .../swing/plaf/metal/MetalToggleButtonUI.java | 33 ++++ .../swing/plaf/metal/MetalToolBarUI.java | 27 ++- .../swing/plaf/metal/MetalToolTipUI.java | 24 +++ .../javax/swing/plaf/metal/MetalTreeUI.java | 68 ++++--- 28 files changed, 981 insertions(+), 80 deletions(-) diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalBorders.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalBorders.java index 8f1ee4fb4d3..a49a4a8bb48 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalBorders.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalBorders.java @@ -56,6 +56,9 @@ public class MetalBorders { static Object NO_BUTTON_ROLLOVER = new StringUIClientPropertyKey("NoButtonRollover"); + /** + * The class represents the 3D border. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class Flush3DBorder extends AbstractBorder implements UIResource{ public void paintBorder(Component c, Graphics g, int x, int y, @@ -73,9 +76,15 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JButton}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class ButtonBorder extends AbstractBorder implements UIResource { + /** + * The border insets. + */ protected static Insets borderInsets = new Insets( 3, 3, 3, 3 ); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { @@ -188,6 +197,9 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JInternalFrame}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class InternalFrameBorder extends AbstractBorder implements UIResource { private static final int corner = 14; @@ -470,6 +482,9 @@ public class MetalBorders { } } + /** + * The class represents the border of an option dialog. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class OptionDialogBorder extends AbstractBorder implements UIResource { int titleHeight = 0; @@ -532,8 +547,15 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JMenuBar}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class MenuBarBorder extends AbstractBorder implements UIResource { + + /** + * The border insets. + */ protected static Insets borderInsets = new Insets( 1, 0, 1, 0 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { @@ -569,8 +591,15 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JMenuItem}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class MenuItemBorder extends AbstractBorder implements UIResource { + + /** + * The border insets. + */ protected static Insets borderInsets = new Insets( 2, 2, 2, 2 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { @@ -617,8 +646,15 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JPopupMenu}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class PopupMenuBorder extends AbstractBorder implements UIResource { + + /** + * The border insets. + */ protected static Insets borderInsets = new Insets( 3, 1, 2, 1 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { @@ -642,6 +678,9 @@ public class MetalBorders { } } + /** + * The class represents the border of a rollover {@code Button}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class RolloverButtonBorder extends ButtonBorder { @@ -693,9 +732,15 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JToolBar}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants { + /** + * The instance of {@code MetalBumps}. + */ protected MetalBumps bumps = new MetalBumps( 10, 10, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), @@ -779,7 +824,9 @@ public class MetalBorders { private static Border buttonBorder; /** - * Returns a border instance for a JButton + * Returns a border instance for a {@code JButton}. + * + * @return a border instance for a {@code JButton} * @since 1.3 */ public static Border getButtonBorder() { @@ -794,7 +841,9 @@ public class MetalBorders { private static Border textBorder; /** - * Returns a border instance for a text component + * Returns a border instance for a text component. + * + * @return a border instance for a text component * @since 1.3 */ public static Border getTextBorder() { @@ -809,7 +858,9 @@ public class MetalBorders { private static Border textFieldBorder; /** - * Returns a border instance for a JTextField + * Returns a border instance for a {@code JTextField}. + * + * @return a border instance for a {@code JTextField} * @since 1.3 */ public static Border getTextFieldBorder() { @@ -821,6 +872,9 @@ public class MetalBorders { return textFieldBorder; } + /** + * The class represents the border of a {@code JTestField}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class TextFieldBorder extends Flush3DBorder { @@ -846,6 +900,9 @@ public class MetalBorders { } } + /** + * The class represents the border of a {@code JScrollPane}. + */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class ScrollPaneBorder extends AbstractBorder implements UIResource { public void paintBorder(Component c, Graphics g, int x, int y, @@ -892,7 +949,9 @@ public class MetalBorders { private static Border toggleButtonBorder; /** - * Returns a border instance for a JToggleButton + * Returns a border instance for a {@code JToggleButton}. + * + * @return a border instance for a {@code JToggleButton} * @since 1.3 */ public static Border getToggleButtonBorder() { @@ -942,6 +1001,10 @@ public class MetalBorders { */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class TableHeaderBorder extends javax.swing.border.AbstractBorder { + + /** + * The border insets. + */ protected Insets editorBorderInsets = new Insets( 2, 2, 2, 0 ); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { @@ -964,7 +1027,9 @@ public class MetalBorders { } /** - * Returns a border instance for a Desktop Icon + * Returns a border instance for a Desktop Icon. + * + * @return a border instance for a Desktop Icon * @since 1.3 */ public static Border getDesktopIconBorder() { diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalButtonUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalButtonUI.java index 233949e3df1..db31cc126a9 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalButtonUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalButtonUI.java @@ -52,10 +52,22 @@ import javax.swing.plaf.*; */ @SuppressWarnings("serial") // Same-version serialization only public class MetalButtonUI extends BasicButtonUI { + // NOTE: These are not really needed, but at this point we can't pull // them. Their values are updated purely for historical reasons. + /** + * The color of the focused button. + */ protected Color focusColor; + + /** + * The color of the selected button. + */ protected Color selectColor; + + /** + * The color of the disabled color. + */ protected Color disabledTextColor; private static final Object METAL_BUTTON_UI_KEY = new Object(); @@ -63,6 +75,13 @@ public class MetalButtonUI extends BasicButtonUI { // ******************************** // Create PLAF // ******************************** + + /** + * Returns an instance of {@code MetalButtonUI}. + * + * @param c a component + * @return an instance of {@code MetalButtonUI} + */ public static ComponentUI createUI(JComponent c) { AppContext appContext = AppContext.getAppContext(); MetalButtonUI metalButtonUI = @@ -96,17 +115,33 @@ public class MetalButtonUI extends BasicButtonUI { // ******************************** // Default Accessors // ******************************** + + /** + * Returns the color of the selected button. + * + * @return the color of the selected button + */ protected Color getSelectColor() { selectColor = UIManager.getColor(getPropertyPrefix() + "select"); return selectColor; } + /** + * Returns the color of a disabled text. + * + * @return the color of a disabled text + */ protected Color getDisabledTextColor() { disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); return disabledTextColor; } + /** + * Returns the color of the focused button. + * + * @return the color of the focused button + */ protected Color getFocusColor() { focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); return focusColor; diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxIcon.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxIcon.java index 0962c8e943a..c262f460fe7 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxIcon.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxIcon.java @@ -49,6 +49,11 @@ import javax.swing.plaf.*; @SuppressWarnings("serial") // Same-version serialization only public class MetalCheckBoxIcon implements Icon, UIResource, Serializable { + /** + * Returns the size of the control. + * + * @return the size of the control + */ protected int getControlSize() { return 13; } public void paintIcon(Component c, Graphics g, int x, int y) { @@ -91,6 +96,14 @@ public class MetalCheckBoxIcon implements Icon, UIResource, Serializable { } } + /** + * Paints {@code MetalCheckBoxIcon}. + * + * @param c a component + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + */ protected void drawCheck(Component c, Graphics g, int x, int y) { int controlSize = getControlSize(); g.fillRect( x+3, y+5, 2, controlSize-8 ); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxUI.java index b80ec636ac2..e18d44a37a0 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalCheckBoxUI.java @@ -67,6 +67,13 @@ public class MetalCheckBoxUI extends MetalRadioButtonUI { // ******************************** // Create PlAF // ******************************** + + /** + * Returns an instance of {@code MetalCheckBoxUI}. + * + * @param b a component + * @return a new instance of {@code MetalCheckBoxUI} + */ public static ComponentUI createUI(JComponent b) { AppContext appContext = AppContext.getAppContext(); MetalCheckBoxUI checkboxUI = diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxButton.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxButton.java index 6a6d1ed860e..15b889e9d34 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxButton.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxButton.java @@ -50,19 +50,72 @@ import java.io.Serializable; */ @SuppressWarnings("serial") // Same-version serialization only public class MetalComboBoxButton extends JButton { + + /** + * The instance of {@code JComboBox}. + */ protected JComboBox comboBox; + + /** + * The instance of {@code JList}. + */ protected JList listBox; + + /** + * The instance of {@code CellRendererPane}. + */ protected CellRendererPane rendererPane; + + /** + * The icon. + */ protected Icon comboIcon; + + /** + * The {@code iconOnly} value. + */ protected boolean iconOnly = false; + /** + * Returns the {@code JComboBox}. + * + * @return the {@code JComboBox} + */ public final JComboBox getComboBox() { return comboBox;} + + /** + * Sets the {@code JComboBox}. + * + * @param cb the {@code JComboBox} + */ public final void setComboBox( JComboBox cb ) { comboBox = cb;} + /** + * Returns the icon of the {@code JComboBox}. + * + * @return the icon of the {@code JComboBox} + */ public final Icon getComboIcon() { return comboIcon;} + + /** + * Sets the icon of the {@code JComboBox}. + * + * @param i the icon of the {@code JComboBox} + */ public final void setComboIcon( Icon i ) { comboIcon = i;} + /** + * Returns the {@code isIconOnly} value. + * + * @return the {@code isIconOnly} value + */ public final boolean isIconOnly() { return iconOnly;} + + /** + * If {@code isIconOnly} is {@code true} then only icon is painted. + * + * @param isIconOnly if {@code true} then only icon is painted + */ public final void setIconOnly( boolean isIconOnly ) { iconOnly = isIconOnly;} MetalComboBoxButton() { @@ -75,6 +128,14 @@ public class MetalComboBoxButton extends JButton { setModel( model ); } + /** + * Constructs a new instance of {@code MetalComboBoxButton}. + * + * @param cb an instance of {@code JComboBox} + * @param i an icon + * @param pane an instance of {@code CellRendererPane} + * @param list an instance of {@code JList} + */ public MetalComboBoxButton( JComboBox cb, Icon i, CellRendererPane pane, JList list ) { this(); @@ -85,6 +146,15 @@ public class MetalComboBoxButton extends JButton { setEnabled( comboBox.isEnabled() ); } + /** + * Constructs a new instance of {@code MetalComboBoxButton}. + * + * @param cb an instance of {@code JComboBox} + * @param i an icon + * @param onlyIcon if {@code true} only icon is painted + * @param pane an instance of {@code CellRendererPane} + * @param list an instance of {@code JList} + */ public MetalComboBoxButton( JComboBox cb, Icon i, boolean onlyIcon, CellRendererPane pane, JList list ) { this( cb, i, pane, list ); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java index 4c95250013b..e9f4aeb4c9d 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java @@ -50,6 +50,9 @@ import javax.swing.plaf.basic.BasicComboBoxEditor; @SuppressWarnings("serial") // Same-version serialization only public class MetalComboBoxEditor extends BasicComboBoxEditor { + /** + * Constructs a new instance of {@code MetalComboBoxEditor}. + */ public MetalComboBoxEditor() { super(); //editor.removeFocusListener(this); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java index eb9afb93439..c95e6b5c6ce 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java @@ -54,6 +54,12 @@ import java.beans.*; @SuppressWarnings("serial") // Same-version serialization only public class MetalComboBoxUI extends BasicComboBoxUI { + /** + * Constructs an instance of {@code MetalComboBoxUI}. + * + * @param c a component + * @return an instance of {@code MetalComboBoxUI} + */ public static ComponentUI createUI(JComponent c) { return new MetalComboBoxUI(); } @@ -234,6 +240,7 @@ public class MetalComboBoxUI extends BasicComboBoxUI { * override. All the functionality of this method is in the * MetalPropertyChangeListener. * + * @param e an instance of {@code PropertyChangeEvent} * @deprecated As of Java 2 platform v1.4. */ @Deprecated @@ -251,11 +258,23 @@ public class MetalComboBoxUI extends BasicComboBoxUI { public void layoutContainer( Container parent ) { layoutComboBox( parent, this ); } + + /** + * Lays out the parent container. + * + * @param parent a container + */ public void superLayout( Container parent ) { super.layoutContainer( parent ); } } + /** + * Lays out the {@code JComboBox} in the {@code parent} container. + * + * @param parent a container + * @param manager an instance of {@code MetalComboBoxLayoutManager} + */ // This is here because of a bug in the compiler. // When a protected-inner-class-savvy compiler comes out we // should move this into MetalComboBoxLayoutManager. @@ -367,6 +386,11 @@ public class MetalComboBoxUI extends BasicComboBoxUI { @Deprecated public class MetalComboPopup extends BasicComboPopup { + /** + * Constructs a new instance of {@code MetalComboPopup}. + * + * @param cBox an instance of {@code JComboBox} + */ public MetalComboPopup( JComboBox cBox) { super( cBox ); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalDesktopIconUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalDesktopIconUI.java index 074a3b5eb79..ec3921b5671 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalDesktopIconUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalDesktopIconUI.java @@ -48,10 +48,19 @@ public class MetalDesktopIconUI extends BasicDesktopIconUI TitleListener titleListener; private int width; + /** + * Constructs a new instance of {@code MetalDesktopIconUI}. + * + * @param c a component + * @return a new instance of {@code MetalDesktopIconUI} + */ public static ComponentUI createUI(JComponent c) { return new MetalDesktopIconUI(); } + /** + * Constructs a new instance of {@code MetalDesktopIconUI}. + */ public MetalDesktopIconUI() { } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index dc15fe68498..06fb070113b 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -138,13 +138,21 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } - // - // ComponentUI Interface Implementation methods - // + /** + * Constructs a new instance of {@code MetalFileChooserUI}. + * + * @param c a component + * @return a new instance of {@code MetalFileChooserUI} + */ public static ComponentUI createUI(JComponent c) { return new MetalFileChooserUI((JFileChooser) c); } + /** + * Constructs a new instance of {@code MetalFileChooserUI}. + * + * @param filechooser a {@code JFileChooser} + */ public MetalFileChooserUI(JFileChooser filechooser) { super(filechooser); } @@ -446,6 +454,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel }); } + /** + * Returns the button panel. + * + * @return the button panel + */ protected JPanel getButtonPanel() { if (buttonPanel == null) { buttonPanel = new JPanel(); @@ -453,6 +466,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { return buttonPanel; } + /** + * Returns the bottom panel. + * + * @return the bottom panel + */ protected JPanel getBottomPanel() { if(bottomPanel == null) { bottomPanel = new JPanel(); @@ -503,20 +521,42 @@ public class MetalFileChooserUI extends BasicFileChooserUI { SwingUtilities.replaceUIActionMap(fc, actionMap); } + /** + * Returns an instance of {@code ActionMap}. + * + * @return an instance of {@code ActionMap} + */ protected ActionMap getActionMap() { return createActionMap(); } + /** + * Constructs an instance of {@code ActionMap}. + * + * @return an instance of {@code ActionMap} + */ protected ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); FilePane.addActionsToMap(map, filePane.getActions()); return map; } + /** + * Constructs a details view. + * + * @param fc a {@code JFileChooser} + * @return the list + */ protected JPanel createList(JFileChooser fc) { return filePane.createList(); } + /** + * Constructs a details view. + * + * @param fc a {@code JFileChooser} + * @return the details view + */ protected JPanel createDetailsView(JFileChooser fc) { return filePane.createDetailsView(); } @@ -533,7 +573,12 @@ public class MetalFileChooserUI extends BasicFileChooserUI { // Obsolete class, not used in this version. protected class SingleClickListener extends MouseAdapter { - public SingleClickListener(JList list) { + /** + * Constructs an instance of {@code SingleClickListener}. + * + * @param list an instance of {@code JList} + */ + public SingleClickListener(JList list) { } } @@ -788,11 +833,16 @@ public class MetalFileChooserUI extends BasicFileChooserUI { }; } - + /** + * Removes control buttons from bottom panel. + */ protected void removeControlButtons() { getBottomPanel().remove(getButtonPanel()); } + /** + * Adds control buttons to bottom panel. + */ protected void addControlButtons() { getBottomPanel().add(getButtonPanel()); } @@ -842,15 +892,31 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } + /** + * Returns the directory name. + * + * @return the directory name + */ public String getDirectoryName() { // PENDING(jeff) - get the name from the directory combobox return null; } + /** + * Sets the directory name. + * + * @param dirname the directory name + */ public void setDirectoryName(String dirname) { // PENDING(jeff) - set the name in the directory combobox } + /** + * Constructs a new instance of {@code DirectoryComboBoxRenderer}. + * + * @param fc a {@code JFileChooser} + * @return a new instance of {@code DirectoryComboBoxRenderer} + */ protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) { return new DirectoryComboBoxRenderer(); } @@ -906,9 +972,12 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } - // - // DataModel for DirectoryComboxbox - // + /** + * Constructs a new instance of {@code DataModel} for {@code DirectoryComboBox}. + * + * @param fc a {@code JFileChooser} + * @return a new instance of {@code DataModel} for {@code DirectoryComboBox} + */ protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) { return new DirectoryComboBoxModel(); } @@ -924,6 +993,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI { JFileChooser chooser = getFileChooser(); FileSystemView fsv = chooser.getFileSystemView(); + /** + * Constructs an instance of {@code DirectoryComboBoxModel}. + */ public DirectoryComboBoxModel() { // Add the current directory to the model, and make it the // selectedDirectory @@ -1017,6 +1089,12 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } + /** + * Returns the depth of {@code i}-th file. + * + * @param i an index + * @return the depth of {@code i}-th file + */ public int getDepth(int i) { return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0; } @@ -1039,9 +1117,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } - // - // Renderer for Types ComboBox - // + /** + * Constructs a {@code Renderer} for types {@code ComboBox}. + * + * @return a {@code Renderer} for types {@code ComboBox} + */ protected FilterComboBoxRenderer createFilterComboBoxRenderer() { return new FilterComboBoxRenderer(); } @@ -1065,9 +1145,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } - // - // DataModel for Types Comboxbox - // + /** + * Constructs a {@code DataModel} for types {@code ComboBox}. + * + * @return a {@code DataModel} for types {@code ComboBox} + */ protected FilterComboBoxModel createFilterComboBoxModel() { return new FilterComboBoxModel(); } @@ -1077,7 +1159,15 @@ public class MetalFileChooserUI extends BasicFileChooserUI { */ @SuppressWarnings("serial") // Same-version serialization only protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { + + /** + * An array of file filters. + */ protected FileFilter[] filters; + + /** + * Constructs an instance of {@code FilterComboBoxModel}. + */ protected FilterComboBoxModel() { super(); filters = getFileChooser().getChoosableFileFilters(); @@ -1142,6 +1232,11 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } } + /** + * Invokes when {@code ListSelectionEvent} occurs. + * + * @param e an instance of {@code ListSelectionEvent} + */ public void valueChanged(ListSelectionEvent e) { JFileChooser fc = getFileChooser(); File f = fc.getSelectedFile(); @@ -1155,6 +1250,10 @@ public class MetalFileChooserUI extends BasicFileChooserUI { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class DirectoryComboBoxAction extends AbstractAction { + + /** + * Constructs a new instance of {@code DirectoryComboBoxAction}. + */ protected DirectoryComboBoxAction() { super("DirectoryComboBoxAction"); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java index 4e0b3535208..8cd0bd04ace 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java @@ -90,10 +90,22 @@ public class MetalIconFactory implements Serializable { private static Icon oceanVerticalSliderThumb; // Constants + /** + * {@code DARK} is used for the property {@code Tree.expandedIcon}. + */ public static final boolean DARK = false; + + /** + * {@code LIGHT} is used for the property {@code Tree.collapsedIcon}. + */ public static final boolean LIGHT = true; // Accessor functions for Icons. Does the caching work. + /** + * Returns the instance of {@code FileChooserDetailViewIcon}. + * + * @return the instance of {@code FileChooserDetailViewIcon} + */ public static Icon getFileChooserDetailViewIcon() { if (fileChooserDetailViewIcon == null) { fileChooserDetailViewIcon = new FileChooserDetailViewIcon(); @@ -101,6 +113,11 @@ public class MetalIconFactory implements Serializable { return fileChooserDetailViewIcon; } + /** + * Returns the instance of {@code FileChooserHomeFolderIcon}. + * + * @return the instance of {@code FileChooserHomeFolderIcon} + */ public static Icon getFileChooserHomeFolderIcon() { if (fileChooserHomeFolderIcon == null) { fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon(); @@ -108,6 +125,11 @@ public class MetalIconFactory implements Serializable { return fileChooserHomeFolderIcon; } + /** + * Returns the instance of {@code FileChooserListViewIcon}. + * + * @return the instance of {@code FileChooserListViewIcon} + */ public static Icon getFileChooserListViewIcon() { if (fileChooserListViewIcon == null) { fileChooserListViewIcon = new FileChooserListViewIcon(); @@ -115,6 +137,11 @@ public class MetalIconFactory implements Serializable { return fileChooserListViewIcon; } + /** + * Returns the instance of {@code FileChooserNewFolderIcon}. + * + * @return the instance of {@code FileChooserNewFolderIcon} + */ public static Icon getFileChooserNewFolderIcon() { if (fileChooserNewFolderIcon == null) { fileChooserNewFolderIcon = new FileChooserNewFolderIcon(); @@ -122,6 +149,11 @@ public class MetalIconFactory implements Serializable { return fileChooserNewFolderIcon; } + /** + * Returns the instance of {@code FileChooserUpFolderIcon}. + * + * @return the instance of {@code FileChooserUpFolderIcon} + */ public static Icon getFileChooserUpFolderIcon() { if (fileChooserUpFolderIcon == null) { fileChooserUpFolderIcon = new FileChooserUpFolderIcon(); @@ -129,14 +161,31 @@ public class MetalIconFactory implements Serializable { return fileChooserUpFolderIcon; } + /** + * Constructs a new instance of {@code InternalFrameAltMaximizeIcon}. + * + * @param size the size of the icon + * @return a new instance of {@code InternalFrameAltMaximizeIcon} + */ public static Icon getInternalFrameAltMaximizeIcon(int size) { return new InternalFrameAltMaximizeIcon(size); } + /** + * Constructs a new instance of {@code InternalFrameCloseIcon}. + * + * @param size the size of the icon + * @return a new instance of {@code InternalFrameCloseIcon} + */ public static Icon getInternalFrameCloseIcon(int size) { return new InternalFrameCloseIcon(size); } + /** + * Returns the instance of {@code InternalFrameDefaultMenuIcon}. + * + * @return the instance of {@code InternalFrameDefaultMenuIcon} + */ public static Icon getInternalFrameDefaultMenuIcon() { if (internalFrameDefaultMenuIcon == null) { internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon(); @@ -144,14 +193,31 @@ public class MetalIconFactory implements Serializable { return internalFrameDefaultMenuIcon; } + /** + * Constructs a new instance of {@code InternalFrameMaximizeIcon}. + * + * @param size the size of the icon + * @return a new instance of {@code InternalFrameMaximizeIcon} + */ public static Icon getInternalFrameMaximizeIcon(int size) { return new InternalFrameMaximizeIcon(size); } + /** + * Constructs a new instance of {@code InternalFrameMinimizeIcon}. + * + * @param size the size of the icon + * @return a new instance of {@code InternalFrameMinimizeIcon} + */ public static Icon getInternalFrameMinimizeIcon(int size) { return new InternalFrameMinimizeIcon(size); } + /** + * Returns the instance of {@code RadioButtonIcon}. + * + * @return the instance of {@code RadioButtonIcon} + */ public static Icon getRadioButtonIcon() { if (radioButtonIcon == null) { radioButtonIcon = new RadioButtonIcon(); @@ -161,6 +227,8 @@ public class MetalIconFactory implements Serializable { /** * Returns a checkbox icon. + * + * @return a checkbox icon * @since 1.3 */ public static Icon getCheckBoxIcon() { @@ -170,6 +238,11 @@ public class MetalIconFactory implements Serializable { return checkBoxIcon; } + /** + * Returns the instance of {@code TreeComputerIcon}. + * + * @return the instance of {@code TreeComputerIcon} + */ public static Icon getTreeComputerIcon() { if ( treeComputerIcon == null ) { treeComputerIcon = new TreeComputerIcon(); @@ -177,6 +250,11 @@ public class MetalIconFactory implements Serializable { return treeComputerIcon; } + /** + * Returns the instance of {@code TreeFloppyDriveIcon}. + * + * @return the instance of {@code TreeFloppyDriveIcon} + */ public static Icon getTreeFloppyDriveIcon() { if ( treeFloppyDriveIcon == null ) { treeFloppyDriveIcon = new TreeFloppyDriveIcon(); @@ -184,10 +262,20 @@ public class MetalIconFactory implements Serializable { return treeFloppyDriveIcon; } + /** + * Constructs a new instance of {@code TreeFolderIcon}. + * + * @return a new instance of {@code TreeFolderIcon} + */ public static Icon getTreeFolderIcon() { return new TreeFolderIcon(); } + /** + * Returns the instance of {@code TreeHardDriveIcon}. + * + * @return the instance of {@code TreeHardDriveIcon} + */ public static Icon getTreeHardDriveIcon() { if ( treeHardDriveIcon == null ) { treeHardDriveIcon = new TreeHardDriveIcon(); @@ -195,14 +283,30 @@ public class MetalIconFactory implements Serializable { return treeHardDriveIcon; } + /** + * Constructs a new instance of {@code TreeLeafIcon}. + * + * @return a new instance of {@code TreeLeafIcon} + */ public static Icon getTreeLeafIcon() { return new TreeLeafIcon(); } + /** + * Constructs a new instance of {@code TreeControlIcon}. + * + * @param isCollapsed if {@code true} the icon is collapsed + * @return a new instance of {@code TreeControlIcon} + */ public static Icon getTreeControlIcon( boolean isCollapsed ) { return new TreeControlIcon( isCollapsed ); } + /** + * Returns an icon to be used by {@code JMenu}. + * + * @return an icon to be used by {@code JMenu} + */ public static Icon getMenuArrowIcon() { if (menuArrowIcon == null) { menuArrowIcon = new MenuArrowIcon(); @@ -220,6 +324,11 @@ public class MetalIconFactory implements Serializable { return null; } + /** + * Returns an icon to be used by {@code JMenuItem}. + * + * @return an icon to be used by {@code JMenuItem} + */ public static Icon getMenuItemArrowIcon() { if (menuItemArrowIcon == null) { menuItemArrowIcon = new MenuItemArrowIcon(); @@ -227,6 +336,11 @@ public class MetalIconFactory implements Serializable { return menuItemArrowIcon; } + /** + * Returns an icon to be used by {@code JCheckBoxMenuItem}. + * + * @return an icon to be used by {@code JCheckBoxMenuItem} + */ public static Icon getCheckBoxMenuItemIcon() { if (checkBoxMenuItemIcon == null) { checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); @@ -234,6 +348,11 @@ public class MetalIconFactory implements Serializable { return checkBoxMenuItemIcon; } + /** + * Returns an icon to be used by {@code JRadioButtonMenuItem}. + * + * @return an icon to be used by {@code JRadioButtonMenuItem} + */ public static Icon getRadioButtonMenuItemIcon() { if (radioButtonMenuItemIcon == null) { radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); @@ -241,6 +360,11 @@ public class MetalIconFactory implements Serializable { return radioButtonMenuItemIcon; } + /** + * Returns a thumb icon to be used by horizontal slider. + * + * @return a thumb icon to be used by horizontal slider + */ public static Icon getHorizontalSliderThumbIcon() { if (MetalLookAndFeel.usingOcean()) { if (oceanHorizontalSliderThumb == null) { @@ -253,6 +377,11 @@ public class MetalIconFactory implements Serializable { return new HorizontalSliderThumbIcon(); } + /** + * Returns a thumb icon to be used by vertical slider. + * + * @return a thumb icon to be used by vertical slider + */ public static Icon getVerticalSliderThumbIcon() { if (MetalLookAndFeel.usingOcean()) { if (oceanVerticalSliderThumb == null) { @@ -1621,7 +1750,18 @@ public class MetalIconFactory implements Serializable { } + /** + * Returns a shift of the icon. + * + * @return a shift of the icon + */ public int getShift() { return 0; } + + /** + * Returns an additional height of the icon. + * + * @return an additional height of the icon + */ public int getAdditionalHeight() { return 0; } public int getIconWidth() { return folderIcon16Size.width; } @@ -1719,7 +1859,18 @@ public class MetalIconFactory implements Serializable { } + /** + * Returns a shift of the icon. + * + * @return a shift of the icon + */ public int getShift() { return 0; } + + /** + * Returns an additional height of the icon. + * + * @return an additional height of the icon + */ public int getAdditionalHeight() { return 0; } public int getIconWidth() { return fileIcon16Size.width; } @@ -1727,6 +1878,9 @@ public class MetalIconFactory implements Serializable { } + /** + * The class represents a tree leaf icon. + */ public static class TreeLeafIcon extends FileIcon16 { public int getShift() { return 2; } public int getAdditionalHeight() { return 4; } @@ -1748,12 +1902,20 @@ public class MetalIconFactory implements Serializable { */ @SuppressWarnings("serial") // Same-version serialization only public static class TreeControlIcon implements Icon, Serializable { - // This data member should not have been exposed. It's called - // isLight, but now it really means isCollapsed. Since we can't change - // any APIs... that's life. + + /** + * if {@code true} the icon is collapsed. + * NOTE: This data member should not have been exposed. It's called + * {@code isLight}, but now it really means {@code isCollapsed}. + * Since we can't change any APIs... that's life. + */ protected boolean isLight; - + /** + * Constructs an instance of {@code TreeControlIcon}. + * + * @param isCollapsed if {@code true} the icon is collapsed + */ public TreeControlIcon( boolean isCollapsed ) { isLight = isCollapsed; } @@ -1811,6 +1973,14 @@ public class MetalIconFactory implements Serializable { } } + /** + * Paints the {@code TreeControlIcon}. + * + * @param c a component + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + */ public void paintMe(Component c, Graphics g, int x, int y) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); @@ -1823,7 +1993,7 @@ public class MetalIconFactory implements Serializable { g.drawLine( xoff + 6, 4, xoff + 9, 4 ); // top g.drawLine( xoff + 10, 5, xoff + 10, 5 ); // top right dot g.drawLine( xoff + 11, 6, xoff + 11, 9 ); // right - g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // botom right dot + g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // bottom right dot g.drawLine( xoff + 6, 11, xoff + 9, 11 ); // bottom g.drawLine( xoff + 5, 10, xoff + 5, 10 ); // bottom left dot diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java index bcf1abbcedc..b517b4ad3c8 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -46,8 +46,19 @@ import javax.swing.plaf.basic.BasicInternalFrameTitlePane; @SuppressWarnings("serial") // Superclass is not serializable across versions public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { + /** + * The value {@code isPalette} + */ protected boolean isPalette = false; + + /** + * The palette close icon. + */ protected Icon paletteCloseIcon; + + /** + * The height of the palette title. + */ protected int paletteTitleHeight; private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); @@ -94,6 +105,11 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { private Color activeBumpsShadow = MetalLookAndFeel. getPrimaryControlDarkShadow(); + /** + * Constructs a new instance of {@code MetalInternalFrameTitlePane} + * + * @param f an instance of {@code JInternalFrame} + */ public MetalInternalFrameTitlePane(JInternalFrame f) { super( f ); } @@ -307,6 +323,11 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { } } + /** + * Paints palette. + * + * @param g a instance of {@code Graphics} + */ public void paintPalette(Graphics g) { boolean leftToRight = MetalUtils.isLeftToRight(frame); @@ -471,6 +492,11 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { bumps.paintIcon(this, g, bumpXOffset, bumpYOffset); } + /** + * If {@code b} is {@code true}, sets palette icons. + * + * @param b if {@code true}, sets palette icons + */ public void setPalette(boolean b) { isPalette = b; diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameUI.java index c8b75e88ac8..94daa93f3b0 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameUI.java @@ -47,6 +47,9 @@ public class MetalInternalFrameUI extends BasicInternalFrameUI { private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); + /** + * The property {@code JInternalFrame.isPalette}. + */ protected static String IS_PALETTE = "JInternalFrame.isPalette"; private static String IS_PALETTE_KEY = "JInternalFrame.isPalette"; private static String FRAME_TYPE = "JInternalFrame.frameType"; @@ -54,10 +57,22 @@ public class MetalInternalFrameUI extends BasicInternalFrameUI { private static String PALETTE_FRAME = "palette"; private static String OPTION_DIALOG = "optionDialog"; + + /** + * Constructs a new {@code MetalInternalFrameUI} instance. + * + * @param b an internal frame + */ public MetalInternalFrameUI(JInternalFrame b) { super(b); } + /** + * Constructs a new {@code MetalInternalFrameUI} instance. + * + * @param c a component + * @return a new {@code MetalInternalFrameUI} instance + */ public static ComponentUI createUI(JComponent c) { return new MetalInternalFrameUI( (JInternalFrame) c); } @@ -152,6 +167,11 @@ public class MetalInternalFrameUI extends BasicInternalFrameUI { } } + /** + * If {@code isPalette} is {@code true}, sets palette border and title + * + * @param isPalette if {@code true}, sets palette border and title + */ // this should be deprecated - jcs public void setPalette(boolean isPalette) { if (isPalette) { diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalLabelUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalLabelUI.java index 6d62d1d640e..977b0789df6 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalLabelUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalLabelUI.java @@ -56,6 +56,12 @@ public class MetalLabelUI extends BasicLabelUI private static final Object METAL_LABEL_UI_KEY = new Object(); + /** + * Returns an instance of {@code MetalLabelUI}. + * + * @param c a component + * @return an instance of {@code MetalLabelUI} + */ public static ComponentUI createUI(JComponent c) { if (System.getSecurityManager() != null) { AppContext appContext = AppContext.getAppContext(); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java index c32d2679f9c..7a22550febc 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java @@ -43,6 +43,12 @@ import javax.swing.plaf.*; public class MetalPopupMenuSeparatorUI extends MetalSeparatorUI { + /** + * Constructs a new {@code MetalPopupMenuSeparatorUI} instance. + * + * @param c a component + * @return a new {@code MetalPopupMenuSeparatorUI} instance + */ public static ComponentUI createUI( JComponent c ) { return new MetalPopupMenuSeparatorUI(); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalProgressBarUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalProgressBarUI.java index aedede36688..42b0b3719a2 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalProgressBarUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalProgressBarUI.java @@ -50,6 +50,12 @@ public class MetalProgressBarUI extends BasicProgressBarUI { private Rectangle innards; private Rectangle box; + /** + * Constructs an instance of {@code MetalProgressBarUI}. + * + * @param c a component + * @return an instance of {@code MetalProgressBarUI} + */ public static ComponentUI createUI(JComponent c) { return new MetalProgressBarUI(); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java index 9b7beeacf98..660bfa84c8b 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java @@ -58,8 +58,19 @@ public class MetalRadioButtonUI extends BasicRadioButtonUI { private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object(); + /** + * The color of the focused radio button. + */ protected Color focusColor; + + /** + * The color of the selected radio button. + */ protected Color selectColor; + + /** + * The color of a disabled text. + */ protected Color disabledTextColor; private boolean defaults_initialized = false; @@ -67,6 +78,13 @@ public class MetalRadioButtonUI extends BasicRadioButtonUI { // ******************************** // Create PlAF // ******************************** + + /** + * Returns an instance of {@code MetalRadioButtonUI}. + * + * @param c a component + * @return an instance of {@code MetalRadioButtonUI} + */ public static ComponentUI createUI(JComponent c) { AppContext appContext = AppContext.getAppContext(); MetalRadioButtonUI metalRadioButtonUI = @@ -100,14 +118,30 @@ public class MetalRadioButtonUI extends BasicRadioButtonUI { // ******************************** // Default Accessors // ******************************** + + /** + * Returns the color of the selected {@code JRadioButton}. + * + * @return the color of the selected {@code JRadioButton} + */ protected Color getSelectColor() { return selectColor; } + /** + * Returns the color of the disabled text. + * + * @return the color of the disabled text + */ protected Color getDisabledTextColor() { return disabledTextColor; } + /** + * Returns the color of the focused {@code JRadioButton}. + * + * @return the color of the focused {@code JRadioButton} + */ protected Color getFocusColor() { return focusColor; } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java index 6d410d88b71..cb4fbd72590 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java @@ -59,17 +59,42 @@ public class MetalScrollBarUI extends BasicScrollBarUI private static Color thumbShadow; private static Color thumbHighlightColor; - + /** + * The metal bumps. + */ protected MetalBumps bumps; + /** + * The increase button. + */ protected MetalScrollButton increaseButton; + + /** + * The decrease button. + */ protected MetalScrollButton decreaseButton; + /** + * The width of the scroll bar. + */ protected int scrollBarWidth; + /** + * The property {@code JScrollBar.isFreeStanding}. + */ public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding"; + + /** + * The value of the property {@code JScrollBar.isFreeStanding}. + */ protected boolean isFreeStanding = true; + /** + * Constructs a new {@code MetalScrollBarUI} instance. + * + * @param c a component + * @return a new {@code MetalScrollBarUI} instance + */ public static ComponentUI createUI( JComponent c ) { return new MetalScrollBarUI(); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollButton.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollButton.java index edd40950ec4..31a874326b1 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollButton.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollButton.java @@ -59,6 +59,13 @@ public class MetalScrollButton extends BasicArrowButton private int buttonWidth; + /** + * Constructs an instance of {@code MetalScrollButton}. + * + * @param direction the direction + * @param width the width + * @param freeStanding the free standing value + */ public MetalScrollButton( int direction, int width, boolean freeStanding ) { super( direction ); @@ -70,6 +77,11 @@ public class MetalScrollButton extends BasicArrowButton isFreeStanding = freeStanding; } + /** + * Sets the free standing value. + * + * @param freeStanding the free standing value + */ public void setFreeStanding( boolean freeStanding ) { isFreeStanding = freeStanding; @@ -115,14 +127,10 @@ public class MetalScrollButton extends BasicArrowButton g.setColor( arrowColor ); int startY = ((h+1) - arrowHeight) / 2; int startX = (w / 2); - // System.out.println( "startX :" + startX + " startY :"+startY); + for (int line = 0; line < arrowHeight; line++) { g.drawLine( startX-line, startY+line, startX +line+1, startY+line); } - /* g.drawLine( 7, 6, 8, 6 ); - g.drawLine( 6, 7, 9, 7 ); - g.drawLine( 5, 8, 10, 8 ); - g.drawLine( 4, 9, 11, 9 );*/ if (isEnabled) { g.setColor( highlightColor ); @@ -167,17 +175,10 @@ public class MetalScrollButton extends BasicArrowButton int startY = (((h+1) - arrowHeight) / 2)+ arrowHeight-1; int startX = (w / 2); - // System.out.println( "startX2 :" + startX + " startY2 :"+startY); - for (int line = 0; line < arrowHeight; line++) { g.drawLine( startX-line, startY-line, startX +line+1, startY-line); } - /* g.drawLine( 4, 5, 11, 5 ); - g.drawLine( 5, 6, 10, 6 ); - g.drawLine( 6, 7, 9, 7 ); - g.drawLine( 7, 8, 8, 8 ); */ - if (isEnabled) { g.setColor( highlightColor ); @@ -219,18 +220,10 @@ public class MetalScrollButton extends BasicArrowButton int startX = (((w+1) - arrowHeight) / 2) + arrowHeight-1; int startY = (h / 2); - //System.out.println( "startX2 :" + startX + " startY2 :"+startY); - for (int line = 0; line < arrowHeight; line++) { g.drawLine( startX-line, startY-line, startX -line, startY+line+1); } - -/* g.drawLine( 5, 4, 5, 11 ); - g.drawLine( 6, 5, 6, 10 ); - g.drawLine( 7, 6, 7, 9 ); - g.drawLine( 8, 7, 8, 8 );*/ - if (isEnabled) { g.setColor( highlightColor ); @@ -274,11 +267,6 @@ public class MetalScrollButton extends BasicArrowButton g.drawLine( startX+line, startY-line, startX +line, startY+line+1); } - /* g.drawLine( 6, 7, 6, 8 ); - g.drawLine( 7, 6, 7, 9 ); - g.drawLine( 8, 5, 8, 10 ); - g.drawLine( 9, 4, 9, 11 );*/ - if (isEnabled) { g.setColor( highlightColor ); @@ -341,6 +329,11 @@ public class MetalScrollButton extends BasicArrowButton return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE ); } + /** + * Returns the width of the button. + * + * @return the width of the button + */ public int getButtonWidth() { return buttonWidth; } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollPaneUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollPaneUI.java index ffc5fc4df1c..c65eb52a657 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollPaneUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollPaneUI.java @@ -56,6 +56,12 @@ public class MetalScrollPaneUI extends BasicScrollPaneUI private PropertyChangeListener scrollBarSwapListener; + /** + * Constructs a new {@code MetalScrollPaneUI}. + * + * @param x a component + * @return a new {@code MetalScrollPaneUI} + */ public static ComponentUI createUI(JComponent x) { return new MetalScrollPaneUI(); } @@ -97,6 +103,7 @@ public class MetalScrollPaneUI extends BasicScrollPaneUI } /** + * @param scrollPane an instance of the {@code JScrollPane} * @deprecated - Replaced by {@link #uninstallListeners(JComponent)} */ @Deprecated @@ -136,6 +143,11 @@ public class MetalScrollPaneUI extends BasicScrollPaneUI } } + /** + * Returns a new {@code PropertyChangeListener} for scroll bar swap events. + * + * @return a new {@code PropertyChangeListener} for scroll bar swap events. + */ protected PropertyChangeListener createScrollBarSwapListener() { return new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSeparatorUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSeparatorUI.java index 9de133b902d..58b6e69e6fb 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSeparatorUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSeparatorUI.java @@ -53,6 +53,12 @@ import javax.swing.plaf.basic.BasicSeparatorUI; @SuppressWarnings("serial") // Same-version serialization only public class MetalSeparatorUI extends BasicSeparatorUI { + /** + * Constructs a new {@code MetalSeparatorUI} instance. + * + * @param c a component + * @return a new {@code MetalSeparatorUI} instance. + */ public static ComponentUI createUI( JComponent c ) { return new MetalSeparatorUI(); diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSliderUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSliderUI.java index 6e629938a65..bc21c7a5094 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSliderUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSliderUI.java @@ -53,13 +53,42 @@ import javax.swing.plaf.*; @SuppressWarnings("serial") // Same-version serialization only public class MetalSliderUI extends BasicSliderUI { + /** + * The buffer of a tick. + */ protected final int TICK_BUFFER = 4; + + /** + * The value of the property {@code JSlider.isFilled}. + * By default, {@code false} if the property is not set, + * {@code true} for Ocean theme. + */ protected boolean filledSlider = false; + // NOTE: these next five variables are currently unused. + /** + * The color of a thumb + */ protected static Color thumbColor; + + /** + * The color of highlighting. + */ protected static Color highlightColor; + + /** + * The color of dark shadow. + */ protected static Color darkShadowColor; + + /** + * The width of a track. + */ protected static int trackWidth; + + /** + * The length of a tick. + */ protected static int tickLength; private int safeLength; @@ -80,13 +109,24 @@ public class MetalSliderUI extends BasicSliderUI { private static Icon SAFE_HORIZ_THUMB_ICON; private static Icon SAFE_VERT_THUMB_ICON; - + /** + * Property for {@code JSlider.isFilled}. + */ protected final String SLIDER_FILL = "JSlider.isFilled"; + /** + * Constructs a {@code MetalSliderUI} instance. + * + * @param c a component + * @return a {@code MetalSliderUI} instance + */ public static ComponentUI createUI(JComponent c) { return new MetalSliderUI(); } + /** + * Constructs a {@code MetalSliderUI} instance. + */ public MetalSliderUI() { super( null ); } @@ -126,10 +166,19 @@ public class MetalSliderUI extends BasicSliderUI { prepareFilledSliderField(); } + /** + * Constructs {@code MetalPropertyListener}. + * + * @param slider a {@code JSlider} + * @return the {@code MetalPropertyListener} + */ protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { return new MetalPropertyListener(); } + /** + * {@code PropertyListener} for {@code JSlider.isFilled}. + */ protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill super.propertyChange( e ); @@ -485,6 +534,8 @@ public class MetalSliderUI extends BasicSliderUI { /** * Returns the shorter dimension of the track. + * + * @return the shorter dimension of the track */ protected int getTrackWidth() { // This strange calculation is here to keep the @@ -504,6 +555,8 @@ public class MetalSliderUI extends BasicSliderUI { /** * Returns the longer dimension of the slide bar. (The slide bar is only the * part that runs directly under the thumb) + * + * @return the longer dimension of the slide bar */ protected int getTrackLength() { if ( slider.getOrientation() == JSlider.HORIZONTAL ) { @@ -514,6 +567,8 @@ public class MetalSliderUI extends BasicSliderUI { /** * Returns the amount that the thumb goes past the slide bar. + * + * @return the amount that the thumb goes past the slide bar */ protected int getThumbOverhang() { return (int)(getThumbSize().getHeight()-getTrackWidth())/2; diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSplitPaneUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSplitPaneUI.java index d27ea2e4828..8d183126780 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalSplitPaneUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalSplitPaneUI.java @@ -49,15 +49,20 @@ public class MetalSplitPaneUI extends BasicSplitPaneUI /** - * Creates a new MetalSplitPaneUI instance - */ + * Creates a new {@code MetalSplitPaneUI} instance + * + * @param x a component + * @return a new {@code MetalSplitPaneUI} instance + */ public static ComponentUI createUI(JComponent x) { return new MetalSplitPaneUI(); } /** - * Creates the default divider. - */ + * Creates the default divider. + * + * @return the default divider + */ public BasicSplitPaneDivider createDefaultDivider() { return new MetalSplitPaneDivider(this); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java index 0a54a878534..76451154127 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTabbedPaneUI.java @@ -50,12 +50,27 @@ import javax.swing.plaf.basic.BasicTabbedPaneUI; @SuppressWarnings("serial") // Same-version serialization only public class MetalTabbedPaneUI extends BasicTabbedPaneUI { + /** + * The minimum width of a pane. + */ protected int minTabWidth = 40; // Background color for unselected tabs that don't have an explicitly // set color. private Color unselectedBackground; + + /** + * The color of tab's background. + */ protected Color tabAreaBackground; + + /** + * The color of the selected pane. + */ protected Color selectColor; + + /** + * The color of the highlight. + */ protected Color selectHighlight; private boolean tabsOpaque = true; @@ -65,6 +80,12 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { // Selected border color for ocean. private Color oceanSelectedBorderColor; + /** + * Constructs {@code MetalTabbedPaneUI}. + * + * @param x a component + * @return an instance of {@code MetalTabbedPaneUI} + */ public static ComponentUI createUI( JComponent x ) { return new MetalTabbedPaneUI(); } @@ -116,6 +137,19 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { } + /** + * Paints the top tab border. + * + * @param tabIndex a tab index + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + * @param w a width + * @param h a height + * @param btm bottom + * @param rght right + * @param isSelected a selection + */ protected void paintTopTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, @@ -286,6 +320,15 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { g.translate( -x, -y ); } + /** + * Returns {@code true} if the gap should be filled. + * + * @param currentRun the current run + * @param tabIndex the tab index + * @param x an X coordinate + * @param y an Y coordinate + * @return {@code true} if the gap should be filled + */ protected boolean shouldFillGap( int currentRun, int tabIndex, int x, int y ) { boolean result = false; @@ -322,6 +365,14 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { return result; } + /** + * Returns the color of the gap. + * + * @param currentRun the current run + * @param x an X coordinate + * @param y an Y coordinate + * @return the color of the gap + */ protected Color getColorForGap( int currentRun, int x, int y ) { final int shadowWidth = 4; int selectedIndex = tabPane.getSelectedIndex(); @@ -349,6 +400,19 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { return tabPane.getBackground(); } + /** + * Paints the left tab border. + * + * @param tabIndex a tab index + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + * @param w a width + * @param h a height + * @param btm bottom + * @param rght right + * @param isSelected a selection + */ protected void paintLeftTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, @@ -466,6 +530,19 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { } + /** + * Paints the bottom tab border. + * + * @param tabIndex a tab index + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + * @param w a width + * @param h a height + * @param btm bottom + * @param rght right + * @param isSelected a selection + */ protected void paintBottomTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, @@ -623,6 +700,19 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { g.translate( -x, -y ); } + /** + * Paints the right tab border. + * + * @param tabIndex a tab index + * @param g an instance of {@code Graphics} + * @param x an X coordinate + * @param y an Y coordinate + * @param w a width + * @param h a height + * @param btm bottom + * @param rght right + * @param isSelected a selection + */ protected void paintRightTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, @@ -842,6 +932,9 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { super.paint( g, c ); } + /** + * Paints highlights below tab. + */ protected void paintHighlightBelowTab( ) { } @@ -1158,7 +1251,13 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { return 0; } - // Don't rotate runs! + /** + * Returns {@code true} if tab runs should be rotated. + * + * @param tabPlacement a tab placement + * @param selectedRun a selected run + * @return {@code true} if tab runs should be rotated. + */ protected boolean shouldRotateTabRuns( int tabPlacement, int selectedRun ) { return false; } @@ -1200,6 +1299,9 @@ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { */ public class TabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout { + /** + * Constructs {@code TabbedPaneLayout}. + */ public TabbedPaneLayout() { MetalTabbedPaneUI.this.super(); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTextFieldUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTextFieldUI.java index 1eca55ed7d2..70db1ee921b 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTextFieldUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTextFieldUI.java @@ -50,6 +50,12 @@ import javax.swing.plaf.basic.*; @SuppressWarnings("serial") // Same-version serialization only public class MetalTextFieldUI extends BasicTextFieldUI { + /** + * Constructs {@code MetalTextFieldUI}. + * + * @param c a component + * @return the instance of {@code MetalTextFieldUI} + */ public static ComponentUI createUI(JComponent c) { return new MetalTextFieldUI(); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToggleButtonUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToggleButtonUI.java index d0d902eecee..d8375cec460 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToggleButtonUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToggleButtonUI.java @@ -60,8 +60,19 @@ public class MetalToggleButtonUI extends BasicToggleButtonUI { private static final Object METAL_TOGGLE_BUTTON_UI_KEY = new Object(); + /** + * The color of a focused toggle button. + */ protected Color focusColor; + + /** + * The color of a selected button. + */ protected Color selectColor; + + /** + * The color of a disabled text. + */ protected Color disabledTextColor; private boolean defaults_initialized = false; @@ -69,6 +80,13 @@ public class MetalToggleButtonUI extends BasicToggleButtonUI { // ******************************** // Create PLAF // ******************************** + + /** + * Constructs the {@code MetalToogleButtonUI}. + * + * @param b a component + * @return the {@code MetalToogleButtonUI}. + */ public static ComponentUI createUI(JComponent b) { AppContext appContext = AppContext.getAppContext(); MetalToggleButtonUI metalToggleButtonUI = @@ -101,14 +119,29 @@ public class MetalToggleButtonUI extends BasicToggleButtonUI { // ******************************** // Default Accessors // ******************************** + /** + * Returns the color of a selected button. + * + * @return the color of a selected button + */ protected Color getSelectColor() { return selectColor; } + /** + * Returns the color of a disabled text. + * + * @return the color of a disabled text + */ protected Color getDisabledTextColor() { return disabledTextColor; } + /** + * Returns the color of a focused toggle button. + * + * @return the color of a focused toggle button + */ protected Color getFocusColor() { return focusColor; } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java index 6fe5250cc18..b9899a3d877 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java @@ -158,6 +158,12 @@ public class MetalToolBarUI extends BasicToolBarUI return false; } + /** + * Constructs an instance of {@code MetalToolBarUI}. + * + * @param c a component + * @return an instance of {@code MetalToolBarUI} + */ public static ComponentUI createUI( JComponent c ) { return new MetalToolBarUI(); @@ -269,6 +275,11 @@ public class MetalToolBarUI extends BasicToolBarUI return new MetalDockingListener( toolBar ); } + /** + * Sets the offset of the mouse cursor inside the DragWindow. + * + * @param p the offset + */ protected void setDragOffset(Point p) { if (!GraphicsEnvironment.isHeadless()) { if (dragWindow == null) { @@ -346,17 +357,29 @@ public class MetalToolBarUI extends BasicToolBarUI } } - // No longer used. Cannot remove for compatibility reasons + /** + * No longer used. The class cannot be removed for compatibility reasons. + */ protected class MetalContainerListener extends BasicToolBarUI.ToolBarContListener {} - // No longer used. Cannot remove for compatibility reasons + /** + * No longer used. The class cannot be removed for compatibility reasons. + */ protected class MetalRolloverListener extends BasicToolBarUI.PropertyListener {} + /** + * {@code DockingListener} for {@code MetalToolBarUI}. + */ protected class MetalDockingListener extends DockingListener { private boolean pressedInBumps = false; + /** + * Constructs the {@code MetalDockingListener}. + * + * @param t an instance of {@code JToolBar} + */ public MetalDockingListener(JToolBar t) { super(t); } diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolTipUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolTipUI.java index 2a7a1b1e571..d851a162685 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolTipUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalToolTipUI.java @@ -58,13 +58,26 @@ public class MetalToolTipUI extends BasicToolTipUI { private Font smallFont; // Refer to note in getAcceleratorString about this field. private JToolTip tip; + + /** + * The space between strings. + */ public static final int padSpaceBetweenStrings = 12; private String acceleratorDelimiter; + /** + * Constructs an instance of the {@code MetalToolTipUI}. + */ public MetalToolTipUI() { super(); } + /** + * Returns an instance of the {@code MetalToolTipUI}. + * + * @param c a component + * @return an instance of the {@code MetalToolTipUI}. + */ public static ComponentUI createUI(JComponent c) { return sharedInstance; } @@ -148,6 +161,12 @@ public class MetalToolTipUI extends BasicToolTipUI { return d; } + /** + * If the accelerator is hidden, the method returns {@code true}, + * otherwise, returns {@code false}. + * + * @return {@code true} if the accelerator is hidden. + */ protected boolean isAcceleratorHidden() { Boolean b = (Boolean)UIManager.get("ToolTip.hideAccelerator"); return b != null && b.booleanValue(); @@ -162,6 +181,11 @@ public class MetalToolTipUI extends BasicToolTipUI { return retValue; } + /** + * Returns the accelerator string. + * + * @return the accelerator string. + */ // NOTE: This requires the tip field to be set before this is invoked. // As MetalToolTipUI is shared between all JToolTips the tip field is // set appropriately before this is invoked. Unfortunately this means diff --git a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTreeUI.java b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTreeUI.java index dee9e022f55..0e333ba630f 100644 --- a/jdk/src/share/classes/javax/swing/plaf/metal/MetalTreeUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/metal/MetalTreeUI.java @@ -93,20 +93,26 @@ public class MetalTreeUI extends BasicTreeUI { private int lineStyle = LEG_LINE_STYLE; private PropertyChangeListener lineStyleListener = new LineListener(); - // Boilerplate + /** + * Constructs the {@code MetalTreeUI}. + * + * @param x a component + * @return the instance of the {@code MetalTreeUI} + */ public static ComponentUI createUI(JComponent x) { return new MetalTreeUI(); } - public MetalTreeUI() - { + /** + * Constructs the {@code MetalTreeUI}. + */ + public MetalTreeUI() { super(); } - protected int getHorizontalLegBuffer() - { - return 3; - } + protected int getHorizontalLegBuffer() { + return 3; + } public void installUI( JComponent c ) { super.installUI( c ); @@ -123,24 +129,36 @@ public class MetalTreeUI extends BasicTreeUI { super.uninstallUI(c); } - /** this function converts between the string passed into the client property - * and the internal representation (currently and int) - * - */ + /** + * Converts between the string passed into the client property + * and the internal representation (currently and int) + * + * @param lineStyleFlag a flag + */ protected void decodeLineStyle(Object lineStyleFlag) { - if ( lineStyleFlag == null || - lineStyleFlag.equals(LEG_LINE_STYLE_STRING)){ - lineStyle = LEG_LINE_STYLE; // default case - } else { - if ( lineStyleFlag.equals(NO_STYLE_STRING) ) { - lineStyle = NO_LINE_STYLE; - } else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) { - lineStyle = HORIZ_LINE_STYLE; - } - } - + if ( lineStyleFlag == null || + lineStyleFlag.equals(LEG_LINE_STYLE_STRING)) { + lineStyle = LEG_LINE_STYLE; // default case + } else { + if ( lineStyleFlag.equals(NO_STYLE_STRING) ) { + lineStyle = NO_LINE_STYLE; + } else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) { + lineStyle = HORIZ_LINE_STYLE; + } + } } + /** + * Returns {@code true} if a point with X coordinate {@code mouseX} + * and Y coordinate {@code mouseY} is in expanded control. + * + * @param row a row + * @param rowLevel a row level + * @param mouseX X coordinate + * @param mouseY Y coordinate + * @return {@code true} if a point with X coordinate {@code mouseX} + * and Y coordinate {@code mouseY} is in expanded control. + */ protected boolean isLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY) { if(tree != null && !isLeaf(row)) { @@ -175,6 +193,12 @@ public class MetalTreeUI extends BasicTreeUI { } } + /** + * Paints the horizontal separators. + * + * @param g an instance of {@code Graphics} + * @param c a component + */ protected void paintHorizontalSeparators(Graphics g, JComponent c) { g.setColor( lineColor ); From f2399d7d549310b359e7ee54d1061922bac48527 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Mon, 30 Jun 2014 18:17:46 -0700 Subject: [PATCH 21/30] 8048839: Reverse sense of -Xlint options in build of jdk repo Reviewed-by: tbell, mikael --- jdk/make/Setup.gmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/make/Setup.gmk b/jdk/make/Setup.gmk index 13e513d3274..485c3b72b13 100644 --- a/jdk/make/Setup.gmk +++ b/jdk/make/Setup.gmk @@ -27,7 +27,7 @@ DISABLE_WARNINGS := -Xlint:all,-deprecation,-unchecked,-rawtypes,-cast,-serial,- # To build with all warnings enabled, do the following: # make JAVAC_WARNINGS="-Xlint:all -Xmaxwarns 10000" -JAVAC_WARNINGS := -Xlint:-unchecked,-deprecation,auxiliaryclass,cast,classfile,dep-ann,divzero,empty,fallthrough,finally,overloads,overrides,serial,static,try,varargs -Werror +JAVAC_WARNINGS := -Xlint:all,-deprecation,-rawtypes,-unchecked -Werror # Any java code executed during a JDK build to build other parts of the JDK must be # executed by the bootstrap JDK (probably with -Xbootclasspath/p: ) and for this From 4b31ce4a17de26f1083efd1ea0e36cbb8a3d53ec Mon Sep 17 00:00:00 2001 From: Staffan Larsen Date: Tue, 1 Jul 2014 10:40:14 +0200 Subject: [PATCH 22/30] 8048687: [TESTBUG] com/sun/jdi/ExclusiveBind.java "Could not find or load main class" Reviewed-by: jbachorik, egahlin, dholmes --- jdk/test/com/sun/jdi/ExclusiveBind.java | 4 +++- jdk/test/com/sun/jdi/VMConnection.java | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/jdk/test/com/sun/jdi/ExclusiveBind.java b/jdk/test/com/sun/jdi/ExclusiveBind.java index 40a42d0e16d..a4801fa4ab6 100644 --- a/jdk/test/com/sun/jdi/ExclusiveBind.java +++ b/jdk/test/com/sun/jdi/ExclusiveBind.java @@ -68,7 +68,9 @@ public class ExclusiveBind { private static ProcessBuilder prepareLauncher(String address, boolean suspend, String class_name) throws Exception { List args = new ArrayList<>(); for(String dbgOption : VMConnection.getDebuggeeVMOptions().split(" ")) { - args.add(dbgOption); + if (!dbgOption.trim().isEmpty()) { + args.add(dbgOption); + } } String lib = "-agentlib:jdwp=transport=dt_socket,server=y,suspend="; if (suspend) { diff --git a/jdk/test/com/sun/jdi/VMConnection.java b/jdk/test/com/sun/jdi/VMConnection.java index e0d72758661..2df2e63057e 100644 --- a/jdk/test/com/sun/jdi/VMConnection.java +++ b/jdk/test/com/sun/jdi/VMConnection.java @@ -59,13 +59,13 @@ class VMConnection { retVal += "-classpath " + testClasses; String vmOpts = System.getProperty("test.vm.opts"); - System.out.println("vmOpts: "+vmOpts); - if (vmOpts != null) { + System.out.println("vmOpts: '" + vmOpts + "'"); + if (vmOpts != null && !vmOpts.trim().isEmpty()) { retVal += " " + vmOpts; } String javaOpts = System.getProperty("test.java.opts"); - System.out.println("javaOpts: "+javaOpts); - if (javaOpts != null) { + System.out.println("javaOpts: '" + javaOpts + "'"); + if (javaOpts != null && !javaOpts.trim().isEmpty()) { retVal += " " + javaOpts; } From 7b43631edcc97605a9e6873949f5fb12b1ff1a7e Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 1 Jul 2014 11:47:36 +0200 Subject: [PATCH 23/30] 8038794: java/lang/management/ThreadMXBean/SynchronizationStatistics.java fails intermittently Reviewed-by: sla --- .../SynchronizationStatistics.java | 133 ++++++++++++------ 1 file changed, 88 insertions(+), 45 deletions(-) diff --git a/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java b/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java index 6986adc6893..f998b7e2375 100644 --- a/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java +++ b/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java @@ -34,6 +34,7 @@ import java.lang.management.*; import java.util.concurrent.Phaser; +import java.util.function.Supplier; public class SynchronizationStatistics { private static class LockerThread extends Thread { @@ -86,6 +87,8 @@ public class SynchronizationStatistics { private static void testBlockingOnSimpleMonitor() throws Exception { System.out.println("testBlockingOnSimpleMonitor"); final Object lock1 = new Object(); + System.out.println("Lock1 = " + lock1); + final Phaser p = new Phaser(2); LockerThread lt = newLockerThread(new Runnable() { @Override @@ -110,12 +113,12 @@ public class SynchronizationStatistics { } p.arriveAndAwaitAdvance(); // phase[2] - testBlocked(ti, mbean.getThreadInfo(tid), lockName, lock1); + testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1); p.arriveAndDeregister(); // phase[3] lt.join(); - System.out.println("OK"); + printok(); } /** @@ -128,6 +131,9 @@ public class SynchronizationStatistics { final Object lock1 = new Object(); final Object lock2 = new Object(); + System.out.println("Lock1 = " + lock1); + System.out.println("Lock2 = " + lock2); + final Phaser p = new Phaser(2); LockerThread lt = newLockerThread(new Runnable() { @Override @@ -149,7 +155,6 @@ public class SynchronizationStatistics { lt.start(); long tid = lt.getId(); ThreadInfo ti = mbean.getThreadInfo(tid); - ThreadInfo ti1 = null; String lockName = null; synchronized(lock1) { p.arriveAndAwaitAdvance(); // phase[1] @@ -158,9 +163,7 @@ public class SynchronizationStatistics { } p.arriveAndAwaitAdvance(); // phase[2] - ti1 = mbean.getThreadInfo(tid); - testBlocked(ti, ti1, lockName, lock1); - ti = ti1; + ti = testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock1); synchronized(lock2) { p.arriveAndAwaitAdvance(); // phase [3] @@ -168,12 +171,12 @@ public class SynchronizationStatistics { lockName = mbean.getThreadInfo(tid).getLockName(); } p.arriveAndAwaitAdvance(); // phase [4] - testBlocked(ti, mbean.getThreadInfo(tid), lockName, lock2); + testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock2); p.arriveAndDeregister(); lt.join(); - System.out.println("OK"); + printok(); } /** @@ -209,13 +212,12 @@ public class SynchronizationStatistics { } p.arriveAndAwaitAdvance(); // phase[2] - ThreadInfo ti2 = mbean.getThreadInfo(lt.getId()); + testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 1); p.arriveAndDeregister(); // phase[3] lt.join(); - testWaited(ti1, ti2, 1); - System.out.println("OK"); + printok(); } /** @@ -256,12 +258,12 @@ public class SynchronizationStatistics { int phase = p.getPhase(); while ((p.arriveAndAwaitAdvance() - phase) < 3); // phase[2-4] - ThreadInfo ti2 = mbean.getThreadInfo(lt.getId()); + testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3); p.arriveAndDeregister(); // phase[5] lt.join(); - testWaited(ti1, ti2, 3); - System.out.println("OK"); + + printok(); } /** @@ -331,44 +333,85 @@ public class SynchronizationStatistics { } p.arriveAndAwaitAdvance(); // phase[4] - ThreadInfo ti2 = mbean.getThreadInfo(lt.getId()); + testWaited(ti1, () -> mbean.getThreadInfo(lt.getId()), 3); p.arriveAndDeregister(); // phase[5] lt.join(); - testWaited(ti1, ti2, 3); - System.out.println("OK"); + printok(); } - private static void testWaited(ThreadInfo ti1, ThreadInfo ti2, int waited) throws Error { - long waitCntDiff = ti2.getWaitedCount() - ti1.getWaitedCount(); - long waitTimeDiff = ti2.getWaitedTime() - ti1.getWaitedTime(); - if (waitCntDiff < waited) { - throw new Error("Unexpected diff in waited count. Expecting at least " - + waited + " , got " + waitCntDiff); - } - if (waitTimeDiff <= 0) { - throw new Error("Unexpected diff in waited time. Expecting increasing " + - "value, got " + waitTimeDiff + "ms"); - } + private static void printok() { + System.out.println("OK\n"); } - private static void testBlocked(ThreadInfo ti1, ThreadInfo ti2, + private static void testWaited(ThreadInfo ti1, Supplier ti2, int waited) + throws InterruptedException { + boolean error; + do { + error = false; + ThreadInfo ti = ti2.get(); + long waitCntDiff = ti.getWaitedCount() - ti1.getWaitedCount(); + long waitTimeDiff = ti.getWaitedTime() - ti1.getWaitedTime(); + if (waitCntDiff < waited) { + System.err.println( + "Unexpected diff in waited count. Expecting at least " + + waited + " , got " + waitCntDiff + ); + error = true; + } + if (waitTimeDiff <= 0) { + System.err.println( + "Unexpected diff in waited time. Expecting increasing " + + "value, got " + waitTimeDiff + "ms" + ); + error = true; + } + if (error) { + System.err.println("Retrying in 20ms ..."); + Thread.sleep(20); + } + } while (error); + } + + private static ThreadInfo testBlocked(ThreadInfo ti1, Supplier ti2, String lockName, final Object lock) - throws Error { - long blkCntDiff = ti2.getBlockedCount() - ti1.getBlockedCount(); - long blkTimeDiff = ti2.getBlockedTime() - ti1.getBlockedTime(); - if (blkCntDiff < 1) { - throw new Error("Unexpected diff in blocked count. Expecting at least 1, " + - "got " + blkCntDiff); - } - if (blkTimeDiff < 0) { - throw new Error("Unexpected diff in blocked time. Expecting a positive " + - "number, got " + blkTimeDiff); - } - if (!lockName.equals(lock.toString())) { - throw new Error("Unexpected blocked monitor name. Expecting " + - lock.toString() + ", got " + - lockName); - } + throws InterruptedException { + boolean error; + ThreadInfo ti = null; + do { + error = false; + ti = ti2.get(); + long blkCntDiff = ti.getBlockedCount() - ti1.getBlockedCount(); + long blkTimeDiff = ti.getBlockedTime() - ti1.getBlockedTime(); + + System.out.println("testBlocked: [" + blkCntDiff + ", " + blkTimeDiff + ", " + lockName + "]"); + + if (blkCntDiff < 1) { + System.err.println( + "Unexpected diff in blocked count. Expecting at least 1, " + + "got " + blkCntDiff + ); + error = true; + } + if (blkTimeDiff < 0) { + System.err.println( + "Unexpected diff in blocked time. Expecting a positive " + + "number, got " + blkTimeDiff + ); + error = true; + } + if (!lockName.equals(lock.toString())) { + System.err.println( + "Unexpected blocked monitor name. Expecting " + + lock.toString() + ", got " + lockName + ); + error = true; + } + if (error) { + System.err.println("Retrying in 20ms ..."); + Thread.sleep(20); + } + } while (error); + return ti; } } From e614cf24ef8d2c4957bb132bd40ea8901258f731 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 1 Jul 2014 15:00:33 +0200 Subject: [PATCH 24/30] 8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid() Reviewed-by: sla --- .../com/sun/tools/attach/Application.java | 38 ++------ jdk/test/com/sun/tools/attach/BasicTests.java | 15 ++- .../com/sun/tools/attach/PermissionTest.java | 18 ++-- jdk/test/com/sun/tools/attach/RunnerUtil.java | 84 ++-------------- jdk/test/com/sun/tools/attach/Shutdown.java | 45 --------- .../tools/attach/StartManagementAgent.java | 13 +-- .../com/sun/tools/attach/TempDirTest.java | 14 ++- .../jdk/testlibrary/ProcessThread.java | 81 +++++++++++++++- .../bootstrap/CustomLauncherTest.java | 13 +-- .../bootstrap/LocalManagementTest.java | 15 ++- .../jmxremote/bootstrap/TestApplication.java | 15 +-- .../startstop/JMXStartStopDoSomething.java | 1 - .../jmxremote/startstop/JMXStartStopTest.java | 16 ++-- jdk/test/sun/tools/jstat/JStatInterval.java | 9 +- jdk/test/sun/tools/jstatd/JstatdTest.java | 96 +++++++------------ 15 files changed, 172 insertions(+), 301 deletions(-) delete mode 100644 jdk/test/com/sun/tools/attach/Shutdown.java diff --git a/jdk/test/com/sun/tools/attach/Application.java b/jdk/test/com/sun/tools/attach/Application.java index ecc7193af0b..485b8527c75 100644 --- a/jdk/test/com/sun/tools/attach/Application.java +++ b/jdk/test/com/sun/tools/attach/Application.java @@ -23,41 +23,21 @@ /* * A simple "Application" used by the Attach API unit tests. This application is - * launched by the test. It binds to a random port and shuts down when somebody - * connects to that port. - * Used port and pid are written both to stdout and to a specified file. + * launched by the test. */ -import java.net.Socket; -import java.net.ServerSocket; -import java.io.PrintWriter; -import jdk.testlibrary.ProcessTools; +import java.io.BufferedReader; +import java.io.InputStreamReader; public class Application { + public static final String READY_MSG="ready"; + public static final String SHUTDOWN_MSG="shutdown"; + public static void main(String args[]) throws Exception { - // bind to a random port - if (args.length < 1) { - System.err.println("First argument should be path to output file."); - } - String outFileName = args[0]; - - ServerSocket ss = new ServerSocket(0); - int port = ss.getLocalPort(); - int pid = ProcessTools.getProcessId(); - - System.out.println("shutdownPort=" + port); - System.out.println("pid=" + pid); + System.out.println(READY_MSG); System.out.flush(); - try (PrintWriter writer = new PrintWriter(outFileName)) { - writer.println("shutdownPort=" + port); - writer.println("pid=" + pid); - writer.println("done"); - writer.flush(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { + while (!br.readLine().equals(SHUTDOWN_MSG)); } - - // wait for test harness to connect - Socket s = ss.accept(); - s.close(); - ss.close(); } } diff --git a/jdk/test/com/sun/tools/attach/BasicTests.java b/jdk/test/com/sun/tools/attach/BasicTests.java index f380c28b3a7..e462cf6463f 100644 --- a/jdk/test/com/sun/tools/attach/BasicTests.java +++ b/jdk/test/com/sun/tools/attach/BasicTests.java @@ -38,7 +38,7 @@ import jdk.testlibrary.ProcessThread; * @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757 * @summary Basic unit tests for the VM attach mechanism. * @library /lib/testlibrary - * @run build jdk.testlibrary.* Agent BadAgent RedefineAgent Application Shutdown RedefineDummy RunnerUtil + * @run build jdk.testlibrary.* Agent BadAgent RedefineAgent Application RedefineDummy RunnerUtil * @run main BasicTests * * This test will perform a number of basic attach tests. @@ -55,21 +55,18 @@ public class BasicTests { * 5. Shut down the Application. */ public static void main(String args[]) throws Throwable { - final String pidFile = "TestsBasic.Application.pid"; ProcessThread processThread = null; - RunnerUtil.ProcessInfo info = null; try { buildJars(); - processThread = RunnerUtil.startApplication(pidFile); - info = RunnerUtil.readProcessInfo(pidFile); - runTests(info.pid); + processThread = RunnerUtil.startApplication(); + runTests(processThread.getPid()); } catch (Throwable t) { System.out.println("TestBasic got unexpected exception: " + t); t.printStackTrace(); throw t; } finally { // Make sure the Application process is stopped. - RunnerUtil.stopApplication(info.shutdownPort, processThread); + RunnerUtil.stopApplication(processThread); } } @@ -78,7 +75,7 @@ public class BasicTests { * The reason for running the tests in a separate process * is that we need to modify the class path. */ - private static void runTests(int pid) throws Throwable { + private static void runTests(long pid) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. @@ -92,7 +89,7 @@ public class BasicTests { "-classpath", classpath, "BasicTests$TestMain", - Integer.toString(pid), + Long.toString(pid), testClassDir + "Agent.jar", testClassDir + "BadAgent.jar", testClassDir + "RedefineAgent.jar" }; diff --git a/jdk/test/com/sun/tools/attach/PermissionTest.java b/jdk/test/com/sun/tools/attach/PermissionTest.java index 5ac458a3754..471f6fc5953 100644 --- a/jdk/test/com/sun/tools/attach/PermissionTest.java +++ b/jdk/test/com/sun/tools/attach/PermissionTest.java @@ -23,7 +23,6 @@ import com.sun.tools.attach.VirtualMachine; import com.sun.tools.attach.AttachNotSupportedException; -import java.util.Properties; import java.io.File; import jdk.testlibrary.OutputAnalyzer; import jdk.testlibrary.ProcessTools; @@ -34,7 +33,7 @@ import jdk.testlibrary.ProcessThread; * @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757 * @summary Basic unit tests for the VM attach mechanism. * @library /lib/testlibrary - * @run build jdk.testlibrary.* Application Shutdown + * @run build jdk.testlibrary.* Application * @run main PermissionTest * * Unit test for Attach API - @@ -51,20 +50,17 @@ public class PermissionTest { * 4. Shut down the Application. */ public static void main(String args[]) throws Throwable { - final String pidFile ="TestPermission.Application.pid"; ProcessThread processThread = null; - RunnerUtil.ProcessInfo info = null; try { - processThread = RunnerUtil.startApplication(pidFile); - info = RunnerUtil.readProcessInfo(pidFile); - runTests(info.pid); + processThread = RunnerUtil.startApplication(); + runTests(processThread.getPid()); } catch (Throwable t) { System.out.println("TestPermission got unexpected exception: " + t); t.printStackTrace(); throw t; } finally { // Make sure the Application process is stopped. - RunnerUtil.stopApplication(info.shutdownPort, processThread); + RunnerUtil.stopApplication(processThread); } } @@ -72,7 +68,7 @@ public class PermissionTest { * Runs the actual test the nested class TestMain. * The test is run in a separate process because we need to add to the classpath. */ - private static void runTests(int pid) throws Throwable { + private static void runTests(long pid) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. @@ -88,7 +84,7 @@ public class PermissionTest { "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.deny", testSrc), "PermissionTest$TestMain", - Integer.toString(pid), + Long.toString(pid), "true" }; OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); @@ -100,7 +96,7 @@ public class PermissionTest { "-Djava.security.manager", String.format("-Djava.security.policy=%sjava.policy.allow", testSrc), "PermissionTest$TestMain", - Integer.toString(pid), + Long.toString(pid), "false" }; output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); diff --git a/jdk/test/com/sun/tools/attach/RunnerUtil.java b/jdk/test/com/sun/tools/attach/RunnerUtil.java index 0fd27894170..de2b70b2b36 100644 --- a/jdk/test/com/sun/tools/attach/RunnerUtil.java +++ b/jdk/test/com/sun/tools/attach/RunnerUtil.java @@ -25,10 +25,7 @@ import java.io.IOException; import java.io.File; import java.nio.file.Files; import java.util.Arrays; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import jdk.testlibrary.OutputAnalyzer; import jdk.testlibrary.ProcessTools; import jdk.testlibrary.Utils; import jdk.testlibrary.ProcessThread; @@ -49,12 +46,12 @@ public class RunnerUtil { * * The Application will write its pid and shutdownPort in the given outFile. */ - public static ProcessThread startApplication(String outFile, String... additionalOpts) throws Throwable { + public static ProcessThread startApplication(String... additionalOpts) throws Throwable { String classpath = System.getProperty("test.class.path", "."); - String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application", outFile }); + String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application" }); String[] args = Utils.addTestJavaOpts(myArgs); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); - ProcessThread pt = new ProcessThread("runApplication", pb); + ProcessThread pt = new ProcessThread("runApplication", (line) -> line.equals(Application.READY_MSG), pb); pt.start(); return pt; } @@ -81,23 +78,16 @@ public class RunnerUtil { * * If the nice shutdown fails, then an Exception is thrown and the test should fail. * - * @param port The shut down port. * @param processThread The process to stop. */ - public static void stopApplication(int port, ProcessThread processThread) throws Throwable { + public static void stopApplication(ProcessThread processThread) throws Throwable { if (processThread == null) { System.out.println("RunnerUtil.stopApplication ignored since proc is null"); return; } try { - System.out.println("RunnerUtil.stopApplication waiting to for shutdown"); - OutputAnalyzer output = ProcessTools.executeTestJvm( - "-classpath", - System.getProperty("test.class.path", "."), - "Shutdown", - Integer.toString(port)); - // Verify that both the Shutdown command and the Application finished ok. - output.shouldHaveExitValue(0); + System.out.println("RunnerUtil.stopApplication waiting for shutdown"); + processThread.sendMessage(Application.SHUTDOWN_MSG); processThread.joinAndThrow(); processThread.getOutput().shouldHaveExitValue(0); } catch (Throwable t) { @@ -119,59 +109,6 @@ public class RunnerUtil { } } - /** - * Read process info for the running Application. - * The Application writes its info to a file with this format: - * shutdownPort=42994 - * pid=19597 - * done - * - * The final "done" is used to make sure the complete file has been written - * before we try to read it. - * This function will wait until the file is available. - * - * @param filename Path to file to read. - * @return The ProcessInfo containing pid and shutdownPort. - */ - public static ProcessInfo readProcessInfo(String filename) throws Throwable { - System.out.println("Reading port and pid from file: " + filename); - File file = new File(filename); - String content = null; - - // Read file or wait for it to be created. - long startTime = System.currentTimeMillis(); - long lastWarningTime = 0; - while (true) { - content = readFile(file); - if (content != null && content.indexOf("done") >= 0) { - break; - } - Thread.sleep(100); - long elapsedTime = (System.currentTimeMillis() - startTime) / 1000; - if (elapsedTime > lastWarningTime) { - lastWarningTime = elapsedTime; - System.out.println("Waited " + elapsedTime + " seconds for file."); - } - } - - ProcessInfo info = new ProcessInfo(); - // search for a line with format: key=nnn - Pattern pattern = Pattern.compile("(\\w*)=([0-9]+)\\r?\\n"); - Matcher matcher = pattern.matcher(content); - while (matcher.find()) { - String key = matcher.group(1); - int value = Integer.parseInt(matcher.group(2)); - if ("pid".equals(key)) { - info.pid = value; - } else if ("shutdownPort".equals(key)) { - info.shutdownPort = value; - } - } - System.out.println("processInfo.pid:" + info.pid); - System.out.println("processInfo.shutdownPort:" + info.shutdownPort); - return info; - } - /** * Read the content of a file. * @param file The file to read. @@ -190,13 +127,4 @@ public class RunnerUtil { throw e; } } - - /** - * Helper class with info of the running Application. - */ - public static class ProcessInfo { - public int pid = -1; - public int shutdownPort = -1; - } - } diff --git a/jdk/test/com/sun/tools/attach/Shutdown.java b/jdk/test/com/sun/tools/attach/Shutdown.java deleted file mode 100644 index 2361aa405e4..00000000000 --- a/jdk/test/com/sun/tools/attach/Shutdown.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2005, 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. - */ - -/* - * - * - * Utility used by the unit tests for the attach mechanism. Connects to a - * given port which triggers the listener to shutdown. - */ -import java.net.Socket; -import java.net.InetSocketAddress; -import java.io.IOException; - -public class Shutdown { - public static void main(String args[]) throws IOException { - int port = Integer.parseInt(args[0]); - - System.out.println("Connecting to port " + port + - " to shutdown Application ..."); - - Socket s = new Socket(); - s.connect( new InetSocketAddress(port) ); - s.close(); - } -} diff --git a/jdk/test/com/sun/tools/attach/StartManagementAgent.java b/jdk/test/com/sun/tools/attach/StartManagementAgent.java index c760755110e..adb71048f04 100644 --- a/jdk/test/com/sun/tools/attach/StartManagementAgent.java +++ b/jdk/test/com/sun/tools/attach/StartManagementAgent.java @@ -40,7 +40,7 @@ import jdk.testlibrary.Utils; * @test * @summary Test for VirtualMachine.startManagementAgent and VirtualMachine.startLocalManagementAgent * @library /lib/testlibrary - * @run build Application Shutdown + * @run build Application jdk.testlibrary.* * @run main StartManagementAgent */ @@ -51,20 +51,17 @@ import jdk.testlibrary.Utils; */ public class StartManagementAgent { public static void main(String[] args) throws Throwable { - final String pidFile = "StartManagementAgent.Application.pid"; ProcessThread processThread = null; - RunnerUtil.ProcessInfo info = null; try { - processThread = RunnerUtil.startApplication(pidFile); - info = RunnerUtil.readProcessInfo(pidFile); - runTests(info.pid); + processThread = RunnerUtil.startApplication(); + runTests(processThread.getPid()); } catch (Throwable t) { System.out.println("StartManagementAgent got unexpected exception: " + t); t.printStackTrace(); throw t; } finally { // Make sure the Application process is stopped. - RunnerUtil.stopApplication(info.shutdownPort, processThread); + RunnerUtil.stopApplication(processThread); } } @@ -104,7 +101,7 @@ public class StartManagementAgent { private static final int MAX_RETRIES = 10; - public static void runTests(int pid) throws Exception { + public static void runTests(long pid) throws Exception { VirtualMachine vm = VirtualMachine.attach(""+pid); try { diff --git a/jdk/test/com/sun/tools/attach/TempDirTest.java b/jdk/test/com/sun/tools/attach/TempDirTest.java index ee240018175..86e3edda742 100644 --- a/jdk/test/com/sun/tools/attach/TempDirTest.java +++ b/jdk/test/com/sun/tools/attach/TempDirTest.java @@ -38,7 +38,7 @@ import jdk.testlibrary.ProcessThread; * @bug 8033104 * @summary Test to make sure attach and jvmstat works correctly when java.io.tmpdir is set * @library /lib/testlibrary - * @run build jdk.testlibrary.* Application Shutdown RunnerUtil + * @run build jdk.testlibrary.* Application RunnerUtil * @run main/timeout=200 TempDirTest */ @@ -90,22 +90,20 @@ public class TempDirTest { final String pidFile = "TempDirTest.Application.pid-" + counter++; ProcessThread processThread = null; - RunnerUtil.ProcessInfo info = null; try { String[] tmpDirArg = null; if (targetTmpDir != null) { tmpDirArg = new String[] {"-Djava.io.tmpdir=" + targetTmpDir}; } - processThread = RunnerUtil.startApplication(pidFile, tmpDirArg); - info = RunnerUtil.readProcessInfo(pidFile); - launchTests(info.pid, clientTmpDir); + processThread = RunnerUtil.startApplication(tmpDirArg); + launchTests(processThread.getPid(), clientTmpDir); } catch (Throwable t) { System.out.println("TempDirTest got unexpected exception: " + t); t.printStackTrace(); throw t; } finally { // Make sure the Application process is stopped. - RunnerUtil.stopApplication(info.shutdownPort, processThread); + RunnerUtil.stopApplication(processThread); } elapsedTime = (System.currentTimeMillis() - startTime) / 1000; @@ -119,7 +117,7 @@ public class TempDirTest { * is that we need to modify the class path and * the -Djava.io.tmpdir property. */ - private static void launchTests(int pid, Path clientTmpDir) throws Throwable { + private static void launchTests(long pid, Path clientTmpDir) throws Throwable { final String sep = File.separator; // Need to add jdk/lib/tools.jar to classpath. @@ -139,7 +137,7 @@ public class TempDirTest { "-classpath", classpath, "TempDirTest$TestMain", - Integer.toString(pid) }); + Long.toString(pid) }); OutputAnalyzer output = ProcessTools.executeTestJvm(args); output.shouldHaveExitValue(0); } diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java index dc6b32cdbc7..8c0ddb33822 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java @@ -23,11 +23,11 @@ package jdk.testlibrary; -import static jdk.testlibrary.Asserts.assertNotEquals; -import static jdk.testlibrary.Asserts.assertTrue; +import java.io.PrintWriter; -import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.Predicate; /** * The helper class for starting and stopping {@link Process} in a separate thread. @@ -54,6 +54,29 @@ public class ProcessThread extends TestThread { super(new ProcessRunnable(pb), threadName); } + + /** + * Creates a new {@code ProcessThread} object. + * + * @param threadName The name of thread + * @param waitfor A predicate to determine whether the target process has been initialized + * @param cmd The string array of program and its arguments to pass to {@link ProcessBuilder} + */ + public ProcessThread(String threadName, Predicate waitfor, String... cmd) { + super(new ProcessRunnable(new ProcessBuilder(cmd), threadName, waitfor), threadName); + } + + /** + * Creates a new {@code ProcessThread} object. + * + * @param threadName The name of thread. + * @param waitfor A predicate to determine whether the target process has been initialized + * @param pb The ProcessBuilder to execute. + */ + public ProcessThread(String threadName, Predicate waitfor, ProcessBuilder pb) { + super(new ProcessRunnable(pb, threadName, waitfor), threadName); + } + /** * Stops {@link Process} started by {@code ProcessRunnable}. * @@ -70,6 +93,18 @@ public class ProcessThread extends TestThread { return ((ProcessRunnable) getRunnable()).getOutput(); } + /** + * Returns the PID associated with this process thread + * @return The PID associated with this process thread + */ + public long getPid() throws InterruptedException { + return ((ProcessRunnable)getRunnable()).getPid(); + } + + public void sendMessage(String message) throws InterruptedException { + ((ProcessRunnable)getRunnable()).sendMessage(message); + } + /** * {@link Runnable} interface for starting and stopping {@link Process}. */ @@ -79,6 +114,8 @@ public class ProcessThread extends TestThread { private final CountDownLatch latch; private volatile Process process; private volatile OutputAnalyzer output; + private final Predicate waitfor; + private final String name; /** * Creates a new {@code ProcessRunnable} object. @@ -86,9 +123,21 @@ public class ProcessThread extends TestThread { * @param pb The {@link ProcessBuilder} to run. */ public ProcessRunnable(ProcessBuilder pb) { - super(); + this(pb, "", null); + } + + /** + * Creates a new {@code ProcessRunnable} object. + * + * @param pb The {@link ProcessBuilder} to run. + * @param name An optional process name; may be null + * @param waitfor A predicate to determine whether the target process has been initialized; may be null + */ + public ProcessRunnable(ProcessBuilder pb, String name, Predicate waitfor) { this.processBuilder = pb; this.latch = new CountDownLatch(1); + this.name = name; + this.waitfor = waitfor; } /** @@ -99,7 +148,9 @@ public class ProcessThread extends TestThread { */ @Override public void xrun() throws Throwable { - this.process = processBuilder.start(); + this.process = ProcessTools.startProcess( + name, processBuilder, waitfor, -1, TimeUnit.SECONDS + ); // Release when process is started latch.countDown(); @@ -138,6 +189,26 @@ public class ProcessThread extends TestThread { public OutputAnalyzer getOutput() { return output; } + + /** + * Returns the PID associated with this process runnable + * @return The PID associated with this process runnable + */ + public long getPid() throws InterruptedException { + return getProcess().getPid(); + } + + public void sendMessage(String message) throws InterruptedException { + try (PrintWriter pw = new PrintWriter(this.getProcess().getOutputStream())) { + pw.println(message); + pw.flush(); + } + } + + private Process getProcess() throws InterruptedException { + latch.await(); + return process; + } } } diff --git a/jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java b/jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java index 9745169b639..ac0911a52ca 100644 --- a/jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java +++ b/jdk/test/sun/management/jmxremote/bootstrap/CustomLauncherTest.java @@ -122,7 +122,6 @@ public class CustomLauncherTest { ); final AtomicReference port = new AtomicReference<>(); - final AtomicReference pid = new AtomicReference<>(); serverPrc = ProcessTools.startProcess( "Launcher", @@ -130,12 +129,10 @@ public class CustomLauncherTest { (String line) -> { if (line.startsWith("port:")) { port.set(line.split("\\:")[1]); - } else if (line.startsWith("pid:")) { - pid.set(line.split("\\:")[1]); - } else if (line.startsWith("waiting")) { + } else if (line.startsWith("waiting")) { return true; - } - return false; + } + return false; }, 5, TimeUnit.SECONDS @@ -143,7 +140,7 @@ public class CustomLauncherTest { System.out.println("Attaching test manager:"); System.out.println("========================="); - System.out.println(" PID : " + pid.get()); + System.out.println(" PID : " + serverPrc.getPid()); System.out.println(" shutdown port : " + port.get()); ProcessBuilder client = ProcessTools.createJavaProcessBuilder( @@ -156,7 +153,7 @@ public class CustomLauncherTest { File.separator + "tools.jar", "TestManager", - pid.get(), + String.valueOf(serverPrc.getPid()), port.get(), "true" ); diff --git a/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java b/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java index b0d44c34325..87ab6a9245e 100644 --- a/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java +++ b/jdk/test/sun/management/jmxremote/bootstrap/LocalManagementTest.java @@ -109,7 +109,6 @@ public class LocalManagementTest { Process serverPrc = null, clientPrc = null; try { final AtomicReference port = new AtomicReference<>(); - final AtomicReference pid = new AtomicReference<>(); serverPrc = ProcessTools.startProcess( "TestApplication(" + testId + ")", @@ -117,12 +116,10 @@ public class LocalManagementTest { (String line) -> { if (line.startsWith("port:")) { port.set(line.split("\\:")[1]); - } else if (line.startsWith("pid:")) { - pid.set(line.split("\\:")[1]); - } else if (line.startsWith("waiting")) { - return true; - } - return false; + } else if (line.startsWith("waiting")) { + return true; + } + return false; }, 5, TimeUnit.SECONDS @@ -130,7 +127,7 @@ public class LocalManagementTest { System.out.println("Attaching test manager:"); System.out.println("========================="); - System.out.println(" PID : " + pid.get()); + System.out.println(" PID : " + serverPrc.getPid()); System.out.println(" shutdown port : " + port.get()); ProcessBuilder client = ProcessTools.createJavaProcessBuilder( @@ -143,7 +140,7 @@ public class LocalManagementTest { File.separator + "tools.jar", "TestManager", - pid.get(), + String.valueOf(serverPrc.getPid()), port.get(), "true" ); diff --git a/jdk/test/sun/management/jmxremote/bootstrap/TestApplication.java b/jdk/test/sun/management/jmxremote/bootstrap/TestApplication.java index 5d6ca2b6a27..e4fdc439538 100644 --- a/jdk/test/sun/management/jmxremote/bootstrap/TestApplication.java +++ b/jdk/test/sun/management/jmxremote/bootstrap/TestApplication.java @@ -26,16 +26,13 @@ * * A test "application" used by unit tests - * LocalManagementTest.java, CustomLauncherTest.java. - * This application binds to some random port, prints its pid and - * the port number to standard output, waits for somebody to connect, - * and then shuts down. + * This application binds to some random port, prints the port number + * to standard output, waits for somebody to connect, and then shuts down. */ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; -import jdk.testlibrary.ProcessTools; - public class TestApplication { public static void main(String[] args) throws IOException { // Some tests require the application to exit immediately @@ -47,16 +44,8 @@ public class TestApplication { ServerSocket ss = new ServerSocket(0); int port = ss.getLocalPort(); - int pid = -1; - try { - pid = ProcessTools.getProcessId(); - } catch (Exception e) { - e.printStackTrace(); - } - // signal test that we are started - do not remove these lines!! System.out.println("port:" + port); - System.out.println("pid:" + pid); System.out.println("waiting for the manager ..."); System.out.flush(); diff --git a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java index e6b1f43a752..5a04a6d718b 100644 --- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java @@ -31,7 +31,6 @@ public class JMXStartStopDoSomething { } public static void main(String args[]) throws Exception { - System.out.println("pid:" + ProcessTools.getProcessId()); System.out.println("main enter"); System.out.flush(); doSomething(); diff --git a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java index 4a058cb1f76..2f53118e6b9 100644 --- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java @@ -134,13 +134,13 @@ public class JMXStartStopTest { } - private static void testConnectLocal(int pid) + private static void testConnectLocal(long pid) throws Exception { String jmxUrlStr = null; try { - jmxUrlStr = sun.management.ConnectorAddressLink.importFrom(pid); + jmxUrlStr = sun.management.ConnectorAddressLink.importFrom((int)pid); dbg_print("Local Service URL: " +jmxUrlStr); if ( jmxUrlStr == null ) { throw new Exception("No Service URL. Local agent not started?"); @@ -318,7 +318,7 @@ public class JMXStartStopTest { private final ProcessBuilder pb; private final String name; private final AtomicBoolean started = new AtomicBoolean(false); - private volatile int pid = -1; + private volatile long pid = -1; public Something(ProcessBuilder pb, String name) { this.pb = pb; @@ -331,15 +331,11 @@ public class JMXStartStopTest { p = ProcessTools.startProcess( "JMXStartStopDoSomething", pb, - (line) -> { - if (line.toLowerCase().startsWith("pid:")) { - pid = Integer.parseInt(line.split("\\:")[1]); - } - return line.equals("main enter"); - }, + (line) -> line.equals("main enter"), 5, TimeUnit.SECONDS ); + pid = p.getPid(); } catch (TimeoutException e) { p.destroy(); p.waitFor(); @@ -348,7 +344,7 @@ public class JMXStartStopTest { } } - public int getPid() { + public long getPid() { return pid; } diff --git a/jdk/test/sun/tools/jstat/JStatInterval.java b/jdk/test/sun/tools/jstat/JStatInterval.java index 8c1203be4c8..4a67ba7b9dc 100644 --- a/jdk/test/sun/tools/jstat/JStatInterval.java +++ b/jdk/test/sun/tools/jstat/JStatInterval.java @@ -42,14 +42,12 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; public class JStatInterval { - private static final String PID = "PID"; private static final String READY = "READY"; private static final String ERROR = "!ERROR"; public static class Application { public static void main(String[] args) { try { - System.out.println(PID + ":" + ProcessTools.getProcessId()); System.out.println(READY); System.out.flush(); int exitCode = System.in.read(); @@ -69,15 +67,12 @@ public class JStatInterval { "-XX:+UsePerfData", Application.class.getName() ); - AtomicInteger pid = new AtomicInteger(-1); AtomicBoolean error = new AtomicBoolean(false); Process app = ProcessTools.startProcess( "application", pb, line -> { - if (line.startsWith(PID)) { - pid.set(Integer.parseInt(line.split("\\:")[1])); - } else if (line.equals(READY)) { + if (line.equals(READY)) { return true; } else if (line.equals(ERROR)) { error.set(true); @@ -92,7 +87,7 @@ public class JStatInterval { throw new Error("Unable to start the monitored application."); } - String pidStr = String.valueOf(pid.get()); + String pidStr = String.valueOf(app.getPid()); JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat"); l.addToolArg("-compiler"); l.addToolArg(pidStr); diff --git a/jdk/test/sun/tools/jstatd/JstatdTest.java b/jdk/test/sun/tools/jstatd/JstatdTest.java index 0c003cfcb5e..5d01eb2397d 100644 --- a/jdk/test/sun/tools/jstatd/JstatdTest.java +++ b/jdk/test/sun/tools/jstatd/JstatdTest.java @@ -22,12 +22,12 @@ */ import java.io.File; +import java.io.IOException; import java.net.UnknownHostException; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.util.Arrays; -import java.util.regex.Pattern; import static jdk.testlibrary.Asserts.*; import jdk.testlibrary.JDKToolLauncher; @@ -69,7 +69,7 @@ public final class JstatdTest { private boolean useDefaultPort = true; private String port; private String serverName; - private String jstatdPid; + private Long jstatdPid; private boolean withExternalRegistry = false; public void setServerName(String serverName) { @@ -84,67 +84,26 @@ public final class JstatdTest { this.withExternalRegistry = withExternalRegistry; } - /** - * Parse pid from jps output - */ - private String parsePid(String tool, OutputAnalyzer output) throws Exception { - String[] lines = output.getOutput().split(Utils.NEW_LINE); - String pid = null; - int count = 0; - String processName = tool; - if (tool == "rmiregistry") { - processName = "registryimpl"; - } + private Long waitOnTool(ProcessThread thread) throws Throwable { + long pid = thread.getPid(); - Pattern toolInJpsPattern = - Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*"); - for (String line : lines) { - if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) { - pid = line.split(" ")[0]; - count++; + Throwable t = thread.getUncaught(); + if (t != null) { + if (t.getMessage().contains( + "java.rmi.server.ExportException: Port already in use")) { + System.out.println("Port already in use. Trying to restart with a new one..."); + Thread.sleep(100); + return null; + } else { + // Something unexpected has happened + throw new Throwable(t); } } - if (count > 1) { - throw new Exception("Expected one " + tool - + " process, got " + count + ". Test will be canceled."); - } + System.out.println(thread.getName() + " pid: " + pid); return pid; } - private String getToolPid(String tool) - throws Exception { - OutputAnalyzer output = runJps(); - return parsePid(tool, output); - } - - private String waitOnTool(String tool, TestThread thread) throws Throwable { - while (true) { - String pid = getToolPid(tool); - - if (pid != null) { - System.out.println(tool + " pid: " + pid); - return pid; - } - - Throwable t = thread.getUncaught(); - if (t != null) { - if (t.getMessage().contains( - "java.rmi.server.ExportException: Port already in use")) { - System.out.println("Port already in use. Trying to restart with a new one..."); - Thread.sleep(100); - return null; - } else { - // Something unexpected has happened - throw new Throwable(t); - } - } - - System.out.println("Waiting until " + tool + " is running..."); - Thread.sleep(100); - } - } - private void log(String caption, String... cmd) { System.out.println(Utils.NEW_LINE + caption + ":"); System.out.println(Arrays.toString(cmd).replace(",", "")); @@ -180,12 +139,29 @@ public final class JstatdTest { log("Start jps", cmd); ProcessBuilder processBuilder = new ProcessBuilder(cmd); - OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); + OutputAnalyzer output = waitForJstatdRMI(processBuilder); System.out.println(output.getOutput()); return output; } + private OutputAnalyzer waitForJstatdRMI(ProcessBuilder pb) throws IOException, InterruptedException { + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + while (output.getExitValue() != 0) { + String out = output.getOutput(); + + if (out.contains("RMI Registry not available") || + out.contains("RMI Server JStatRemoteHost not available")) { + Thread.sleep(100); + output = new OutputAnalyzer(pb.start()); + } else { + output.shouldHaveExitValue(0); + } + } + return output; + } + /** * Verifies output form jps contains pids and programs' name information. * The function will discard any lines that come before the first line with pid. @@ -235,7 +211,7 @@ public final class JstatdTest { log("Start jstat", cmd); ProcessBuilder processBuilder = new ProcessBuilder(cmd); - OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); + OutputAnalyzer output = waitForJstatdRMI(processBuilder); System.out.println(output.getOutput()); return output; @@ -323,7 +299,7 @@ public final class JstatdTest { try { jstatdThread.start(); // Make sure jstatd is up and running - jstatdPid = waitOnTool("jstatd", jstatdThread); + jstatdPid = waitOnTool(jstatdThread); if (jstatdPid == null) { // The port is already in use. Cancel and try with new one. jstatdThread.stopProcess(); @@ -344,7 +320,7 @@ public final class JstatdTest { try { while (jstatdThread == null) { if (!useDefaultPort || withExternalRegistry) { - port = Integer.toString(Utils.getFreePort()); + port = String.valueOf(Utils.getFreePort()); } if (withExternalRegistry) { From 829524e7d6d976c926cdb1ccd6aa6570be31dfab Mon Sep 17 00:00:00 2001 From: Staffan Larsen Date: Tue, 1 Jul 2014 16:08:45 +0200 Subject: [PATCH 25/30] 8048710: Use ServiceLoader for the jvmstat protocols Reviewed-by: alanb --- .../{remote => }/BufferedMonitoredVm.java | 2 +- .../sun.jvmstat.monitor.MonitoredHostService | 3 + .../sun/jvmstat/monitor/MonitoredHost.java | 107 ++++-------------- .../jvmstat/monitor/MonitoredHostService.java | 48 ++++++++ .../file/MonitoredHostFileService.java | 46 ++++++++ .../local/MonitoredHostLocalService.java | 46 ++++++++ .../protocol/rmi/MonitoredHostRmiService.java | 45 ++++++++ .../jdk/testlibrary/ProcessTools.java | 3 + 8 files changed, 216 insertions(+), 84 deletions(-) rename jdk/src/share/classes/sun/jvmstat/monitor/{remote => }/BufferedMonitoredVm.java (98%) create mode 100644 jdk/src/share/classes/sun/jvmstat/monitor/META-INF/services/sun.jvmstat.monitor.MonitoredHostService create mode 100644 jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHostService.java create mode 100644 jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/file/MonitoredHostFileService.java create mode 100644 jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/MonitoredHostLocalService.java create mode 100644 jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/rmi/MonitoredHostRmiService.java diff --git a/jdk/src/share/classes/sun/jvmstat/monitor/remote/BufferedMonitoredVm.java b/jdk/src/share/classes/sun/jvmstat/monitor/BufferedMonitoredVm.java similarity index 98% rename from jdk/src/share/classes/sun/jvmstat/monitor/remote/BufferedMonitoredVm.java rename to jdk/src/share/classes/sun/jvmstat/monitor/BufferedMonitoredVm.java index fbbfb80e1aa..56e9b16aadd 100644 --- a/jdk/src/share/classes/sun/jvmstat/monitor/remote/BufferedMonitoredVm.java +++ b/jdk/src/share/classes/sun/jvmstat/monitor/BufferedMonitoredVm.java @@ -23,7 +23,7 @@ * questions. */ -package sun.jvmstat.monitor.remote; +package sun.jvmstat.monitor; import sun.jvmstat.monitor.*; diff --git a/jdk/src/share/classes/sun/jvmstat/monitor/META-INF/services/sun.jvmstat.monitor.MonitoredHostService b/jdk/src/share/classes/sun/jvmstat/monitor/META-INF/services/sun.jvmstat.monitor.MonitoredHostService new file mode 100644 index 00000000000..b106c0fc9a9 --- /dev/null +++ b/jdk/src/share/classes/sun/jvmstat/monitor/META-INF/services/sun.jvmstat.monitor.MonitoredHostService @@ -0,0 +1,3 @@ +sun.jvmstat.perfdata.monitor.protocol.file.MonitoredHostFileService +sun.jvmstat.perfdata.monitor.protocol.local.MonitoredHostLocalService +sun.jvmstat.perfdata.monitor.protocol.rmi.MonitoredHostRmiService diff --git a/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHost.java b/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHost.java index dabd2fd0f44..037f49e53f6 100644 --- a/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHost.java +++ b/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHost.java @@ -25,9 +25,11 @@ package sun.jvmstat.monitor; -import java.util.*; -import java.net.*; -import java.lang.reflect.*; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; +import java.util.Set; import sun.jvmstat.monitor.event.HostListener; @@ -51,31 +53,6 @@ public abstract class MonitoredHost { private static Map monitoredHosts = new HashMap(); - /* - * The monitoring implementation override mechanism. The value of - * this property is used as the class name for the concrete MonitoredHost - * subclass that implements the monitoring APIs. Setting this property - * will cause the remaining override mechanisms to be ignored. When - * this mechanism is used, the HostIdentifier scheme name, which - * indicates the communications protocol, is not used to locate a - * the protocol specific package. However, the HostIdentifier is - * still passed to the corresponding single arg constructor. - * This property is not expected to be set in normal circumstances. - */ - private static final String IMPL_OVERRIDE_PROP_NAME = - "sun.jvmstat.monitor.MonitoredHost"; - - /* - * The monitoring package name override mechanism. The value - * the this property is used as base package name for the - * monitoring implementation package. This property is not - * expected to be set under normal circumstances. - */ - private static final String IMPL_PKG_PROP_NAME = - "sun.jvmstat.monitor.package"; - private static final String IMPL_PACKAGE = - System.getProperty(IMPL_PKG_PROP_NAME, "sun.jvmstat.perfdata"); - /* * The default optimized local protocol override mechanism. The value * of this property is used to construct the default package name @@ -100,15 +77,6 @@ public abstract class MonitoredHost { private static final String REMOTE_PROTOCOL = System.getProperty(REMOTE_PROTOCOL_PROP_NAME, "rmi"); - /* - * The default class name of the MonitoredHost implementation subclass. - * There is no override mechanism for this variable, other than the - * IMPL_OVERRIDE_PROP_NAME override, which is larger in scope. A concrete - * instance of this class is expected to be found in: - * .monitor.protocol.. - */ - private static final String MONITORED_HOST_CLASS = "MonitoredHostProvider"; - /** * The HostIdentifier for this MonitoredHost instance. */ @@ -165,6 +133,13 @@ public abstract class MonitoredHost { return getMonitoredHost(hostId); } + + /* + * Load the MonitoredHostServices + */ + private static ServiceLoader monitoredHostServiceLoader = + ServiceLoader.load(MonitoredHostService.class, MonitoredHostService.class.getClassLoader()); + /** * Factory method to construct a MonitoredHost instance to manage the * connection to the host indicated by hostId. @@ -177,11 +152,6 @@ public abstract class MonitoredHost { */ public static MonitoredHost getMonitoredHost(HostIdentifier hostId) throws MonitorException { - /* - * determine the class name to load. If the system property is set, - * use the indicated class. otherwise, use the default class. - */ - String classname = System.getProperty(IMPL_OVERRIDE_PROP_NAME); MonitoredHost mh = null; synchronized(monitoredHosts) { @@ -197,50 +167,21 @@ public abstract class MonitoredHost { hostId = resolveHostId(hostId); - if (classname == null) { - // construct the class name - classname = IMPL_PACKAGE + ".monitor.protocol." - + hostId.getScheme() + "." + MONITORED_HOST_CLASS; + for (MonitoredHostService mhs : monitoredHostServiceLoader) { + if (mhs.getScheme().equals(hostId.getScheme())) { + mh = mhs.getMonitoredHost(hostId); + } } - try { - // run the constructor taking a single String parameter. - Class c = Class.forName(classname); - - Constructor cons = c.getConstructor( - new Class[] { hostId.getClass() } - ); - - mh = (MonitoredHost)cons.newInstance(new Object[] { hostId } ); - - synchronized(monitoredHosts) { - monitoredHosts.put(mh.hostId, mh); - } - return mh; - } catch (ClassNotFoundException e) { - // from Class.forName(); - throw new IllegalArgumentException("Could not find " + classname - + ": " + e.getMessage(), e); - } catch (NoSuchMethodException e) { - // from Class.getConstructor(); - throw new IllegalArgumentException( - "Expected constructor missing in " + classname + ": " - + e.getMessage(), e); - } catch (IllegalAccessException e) { - // from Constructor.newInstance() - throw new IllegalArgumentException( - "Unexpected constructor access in " + classname + ": " - + e.getMessage(), e); - } catch (InstantiationException e) { - throw new IllegalArgumentException(classname + "is abstract: " - + e.getMessage(), e); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - if (cause instanceof MonitorException) { - throw (MonitorException)cause; - } - throw new RuntimeException("Unexpected exception", e); + if (mh == null) { + throw new IllegalArgumentException("Could not find MonitoredHost for scheme: " + hostId.getScheme()); } + + synchronized(monitoredHosts) { + monitoredHosts.put(mh.hostId, mh); + } + + return mh; } /** diff --git a/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHostService.java b/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHostService.java new file mode 100644 index 00000000000..27607a990cd --- /dev/null +++ b/jdk/src/share/classes/sun/jvmstat/monitor/MonitoredHostService.java @@ -0,0 +1,48 @@ +/* + * 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. 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 sun.jvmstat.monitor; + +public interface MonitoredHostService { + + /** + * Construct a MonitoredHost instance to manage the + * connection to the host indicated by hostId. + * + * @param hostId the identifier for the target host. + * @return MonitoredHost - The MonitoredHost object needed to attach to + * the target host. + * + * @throws MonitorException Thrown if monitoring errors occur. + */ + public MonitoredHost getMonitoredHost(HostIdentifier hostId) throws MonitorException; + + /** + * Get the scheme that this service supports. + * + * @return scheme name + */ + public String getScheme(); +} diff --git a/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/file/MonitoredHostFileService.java b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/file/MonitoredHostFileService.java new file mode 100644 index 00000000000..205fda6ff9a --- /dev/null +++ b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/file/MonitoredHostFileService.java @@ -0,0 +1,46 @@ +/* + * 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. 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 sun.jvmstat.perfdata.monitor.protocol.file; + +import sun.jvmstat.monitor.HostIdentifier; +import sun.jvmstat.monitor.MonitorException; +import sun.jvmstat.monitor.MonitoredHost; +import sun.jvmstat.monitor.MonitoredHostService; + +public final class MonitoredHostFileService implements MonitoredHostService { + + @Override + public MonitoredHost getMonitoredHost(HostIdentifier hostId) + throws MonitorException { + return new MonitoredHostProvider(hostId); + } + + @Override + public String getScheme() { + return "file"; + } + +} diff --git a/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/MonitoredHostLocalService.java b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/MonitoredHostLocalService.java new file mode 100644 index 00000000000..aa93b486e77 --- /dev/null +++ b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/local/MonitoredHostLocalService.java @@ -0,0 +1,46 @@ +/* + * 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. 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 sun.jvmstat.perfdata.monitor.protocol.local; + +import sun.jvmstat.monitor.HostIdentifier; +import sun.jvmstat.monitor.MonitorException; +import sun.jvmstat.monitor.MonitoredHost; +import sun.jvmstat.monitor.MonitoredHostService; + +public final class MonitoredHostLocalService implements MonitoredHostService { + + @Override + public MonitoredHost getMonitoredHost(HostIdentifier hostId) + throws MonitorException { + return new MonitoredHostProvider(hostId); + } + + @Override + public String getScheme() { + return "local"; + } + +} diff --git a/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/rmi/MonitoredHostRmiService.java b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/rmi/MonitoredHostRmiService.java new file mode 100644 index 00000000000..bbaa10932a6 --- /dev/null +++ b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/protocol/rmi/MonitoredHostRmiService.java @@ -0,0 +1,45 @@ +/* + * 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. 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 sun.jvmstat.perfdata.monitor.protocol.rmi; + +import sun.jvmstat.monitor.HostIdentifier; +import sun.jvmstat.monitor.MonitorException; +import sun.jvmstat.monitor.MonitoredHost; +import sun.jvmstat.monitor.MonitoredHostService; + +public final class MonitoredHostRmiService implements MonitoredHostService { + + @Override + public MonitoredHost getMonitoredHost(HostIdentifier hostId) throws MonitorException { + return new MonitoredHostProvider(hostId); + } + + @Override + public String getScheme() { + return "rmi"; + } + +} diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java index c949e0f6c11..042c8c65e0c 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java @@ -41,6 +41,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Predicate; import java.util.function.Consumer; +import java.util.stream.Collector; +import java.util.stream.Collectors; import sun.management.VMManagement; @@ -135,6 +137,7 @@ public final class ProcessTools { long timeout, TimeUnit unit) throws IOException, InterruptedException, TimeoutException { + System.out.println("["+name+"]:" + processBuilder.command().stream().collect(Collectors.joining(" "))); Process p = processBuilder.start(); StreamPumper stdout = new StreamPumper(p.getInputStream()); StreamPumper stderr = new StreamPumper(p.getErrorStream()); From 19c07ee15b6070a5af92c112d72e17c4c9c56d37 Mon Sep 17 00:00:00 2001 From: Sean Coffey Date: Tue, 1 Jul 2014 16:51:44 +0100 Subject: [PATCH 26/30] 7095856: OutputStreamHook doesn't handle null values Reviewed-by: lancea, msheppar --- .../corba/se/impl/io/CustomOutputStream.java | 192 ++++++++++++++++++ .../corba/se/impl/io/HookPutFieldsTest.java | 42 ++++ 2 files changed, 234 insertions(+) create mode 100644 jdk/test/com/sun/corba/se/impl/io/CustomOutputStream.java create mode 100644 jdk/test/com/sun/corba/se/impl/io/HookPutFieldsTest.java diff --git a/jdk/test/com/sun/corba/se/impl/io/CustomOutputStream.java b/jdk/test/com/sun/corba/se/impl/io/CustomOutputStream.java new file mode 100644 index 00000000000..4a057575def --- /dev/null +++ b/jdk/test/com/sun/corba/se/impl/io/CustomOutputStream.java @@ -0,0 +1,192 @@ +/* + * 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 java.io.Serializable; + +import org.omg.CORBA.Any; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.Principal; +import org.omg.CORBA_2_3.portable.OutputStream; +import org.omg.CORBA_2_3.portable.InputStream; + +public class CustomOutputStream extends OutputStream { + + @Override + public void write_value(Serializable value, Class clz) { + } + + @Override + public InputStream create_input_stream() { + return null; + } + + @Override + public void write_boolean(boolean value) { + } + + @Override + public void write_char(char value) { + } + + @Override + public void write_wchar(char value) { + } + + @Override + public void write_octet(byte value) { + } + + @Override + public void write_short(short value) { + } + + @Override + public void write_ushort(short value) { + } + + @Override + public void write_long(int value) { + } + + @Override + public void write_ulong(int value) { + } + + @Override + public void write_longlong(long value) { + } + + @Override + public void write_ulonglong(long value) { + } + + @Override + public void write_float(float value) { + } + + @Override + public void write_double(double value) { + } + + @Override + public void write_string(String value) { + } + + @Override + public void write_wstring(String value) { + } + + @Override + public void write_boolean_array(boolean[] value, int offset, + int length) { + } + + @Override + public void write_char_array(char[] value, int offset, + int length) { + } + + @Override + public void write_wchar_array(char[] value, int offset, + int length) { + } + + @Override + public void write_octet_array(byte[] value, int offset, + int length) { + } + + @Override + public void write_short_array(short[] value, int offset, + int length) { + } + + @Override + public void write_ushort_array(short[] value, int offset, + int length) { + } + + @Override + public void write_long_array(int[] value, int offset, + int length) { + } + + @Override + public void write_ulong_array(int[] value, int offset, + int length) { + } + + @Override + public void write_longlong_array(long[] value, int offset, + int length) { + } + + @Override + public void write_ulonglong_array(long[] value, int offset, + int length) { + } + + @Override + public void write_float_array(float[] value, int offset, + int length) { + } + + @Override + public void write_double_array(double[] value, int offset, + int length) { + } + + @Override + public void write_Object(org.omg.CORBA.Object value) { + } + + @Override + public void write_TypeCode(TypeCode value) { + } + + @Override + public void write_any(Any value) { + } + + @Override + public void write_Principal(Principal value) { + } + + @Override + public void write(int b) throws java.io.IOException { + } + + @Override + public void write_fixed(java.math.BigDecimal value) { + } + + @Override + public void write_Context(org.omg.CORBA.Context ctx, + org.omg.CORBA.ContextList contexts) { + } + + @Override + public org.omg.CORBA.ORB orb() { + return null; + } +} diff --git a/jdk/test/com/sun/corba/se/impl/io/HookPutFieldsTest.java b/jdk/test/com/sun/corba/se/impl/io/HookPutFieldsTest.java new file mode 100644 index 00000000000..cd7c50bdd37 --- /dev/null +++ b/jdk/test/com/sun/corba/se/impl/io/HookPutFieldsTest.java @@ -0,0 +1,42 @@ +/* + * 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. + */ + +/* + * @test + * @bug 7095856 + * @summary OutputStreamHook doesn't handle null values + */ + +import java.net.InetAddress; +import javax.rmi.CORBA.Util; +import javax.rmi.CORBA.ValueHandler; + +public class HookPutFieldsTest { + + public static void main(String[] args ) throws Exception { + CustomOutputStream os = new CustomOutputStream(); + InetAddress a = InetAddress.getByAddress(null, new byte[] {1,2,3,4}); + ValueHandler vh = Util.createValueHandler(); + vh.writeValue(os, a); + } +} From 3962277490e8a93ae691f2f36ea2c22641f669f1 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 1 Jul 2014 17:58:14 +0200 Subject: [PATCH 27/30] 8044427: [test] sun/management/jmxremote/startstop/JMXStartStopTest times out intermittently on Solaris/Sparcv9 Reviewed-by: sla --- .../sun/management/jmxremote/startstop/JMXStartStopTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java index 2f53118e6b9..046da3a46eb 100644 --- a/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java +++ b/jdk/test/sun/management/jmxremote/startstop/JMXStartStopTest.java @@ -40,7 +40,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import java.util.function.IntUnaryOperator; import javax.management.*; import javax.management.remote.*; @@ -54,7 +53,7 @@ import jdk.testlibrary.JDKToolLauncher; * @bug 7110104 * @library /lib/testlibrary * @build jdk.testlibrary.* JMXStartStopTest JMXStartStopDoSomething - * @run main/othervm JMXStartStopTest + * @run main/othervm/timeout=600 JMXStartStopTest * @summary Makes sure that enabling/disabling the management agent through * JCMD achieves the desired results */ From 4da668378d30a0b749e0138efbc7a3c1efa376bf Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 1 Jul 2014 15:12:59 +0100 Subject: [PATCH 28/30] 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes Reviewed-by: chegar, psandoz, prappo --- jdk/src/macosx/classes/sun/font/CStrike.java | 2 +- .../imageio/plugins/gif/GIFImageReader.java | 2 +- .../imageio/plugins/jpeg/JPEGImageReader.java | 6 +-- .../com/sun/jmx/snmp/SnmpCounter64.java | 2 +- .../classes/com/sun/jmx/snmp/SnmpInt.java | 2 +- .../com/sun/jmx/snmp/agent/SnmpMibGroup.java | 4 +- .../jmx/snmp/daemon/SnmpAdaptorServer.java | 38 +++++++++---------- .../com/sun/jndi/ldap/LdapPoolManager.java | 2 +- .../sun/jndi/ldap/NamingEventNotifier.java | 8 ++-- .../auth/SolarisNumericGroupPrincipal.java | 4 +- .../auth/SolarisNumericUserPrincipal.java | 4 +- .../auth/UnixNumericGroupPrincipal.java | 4 +- .../auth/UnixNumericUserPrincipal.java | 4 +- .../example/debug/tty/BreakpointSpec.java | 4 +- .../sun/tools/example/debug/tty/Commands.java | 6 +-- .../internal/model/JavaLazyReadObject.java | 2 +- .../tools/hat/internal/model/Snapshot.java | 2 +- .../hat/internal/parser/HprofReader.java | 12 +++--- .../hat/internal/server/RefsByTypeQuery.java | 8 ++-- .../com/sun/tools/jdi/VirtualMachineImpl.java | 10 ++--- .../awt/image/renderable/ParameterBlock.java | 4 +- .../classes/java/text/DecimalFormat.java | 2 +- .../javax/management/loading/MLet.java | 2 +- .../modelmbean/RequiredModelMBean.java | 4 +- .../swing/plaf/basic/BasicLookAndFeel.java | 2 +- .../perfdata/monitor/PerfLongMonitor.java | 2 +- .../sun/management/GcInfoCompositeData.java | 8 ++-- .../classes/sun/management/HotspotThread.java | 2 +- .../MemoryNotifInfoCompositeData.java | 2 +- .../management/MemoryUsageCompositeData.java | 8 ++-- .../management/ThreadInfoCompositeData.java | 12 +++--- .../counter/perf/LongCounterSnapshot.java | 2 +- .../counter/perf/PerfLongCounter.java | 2 +- .../snmp/jvminstr/JvmClassLoadingImpl.java | 6 +-- .../snmp/jvminstr/JvmCompilationImpl.java | 2 +- .../snmp/jvminstr/JvmMemGCEntryImpl.java | 4 +- .../snmp/jvminstr/JvmMemPoolEntryImpl.java | 30 +++++++-------- .../snmp/jvminstr/JvmMemoryImpl.java | 22 +++++------ .../snmp/jvminstr/JvmRuntimeImpl.java | 4 +- .../jvminstr/JvmThreadInstanceEntryImpl.java | 12 +++--- .../snmp/jvminstr/JvmThreadingImpl.java | 10 ++--- jdk/src/share/classes/sun/nio/ch/Util.java | 4 +- .../sun/security/action/GetLongAction.java | 2 +- .../security/jgss/wrapper/GSSNameElement.java | 2 +- .../security/krb5/internal/KerberosTime.java | 7 ++-- .../sun/security/tools/keytool/Main.java | 2 +- .../sun/tools/java/BinaryConstantPool.java | 2 +- .../sun/tools/jconsole/MemoryPoolProxy.java | 4 +- .../sun/tools/tree/BitNotExpression.java | 2 +- .../sun/tools/tree/IncDecExpression.java | 2 +- .../sun/tools/tree/LongExpression.java | 4 +- .../util/prefs/FileSystemPreferences.java | 2 +- .../sun/awt/X11/XFocusProxyWindow.java | 5 ++- 53 files changed, 153 insertions(+), 153 deletions(-) diff --git a/jdk/src/macosx/classes/sun/font/CStrike.java b/jdk/src/macosx/classes/sun/font/CStrike.java index af4f8754cfb..5296f5c87f0 100644 --- a/jdk/src/macosx/classes/sun/font/CStrike.java +++ b/jdk/src/macosx/classes/sun/font/CStrike.java @@ -415,7 +415,7 @@ public final class CStrike extends FontStrike { generalCache = new HashMap(); } - generalCache.put(new Integer(index), new Long(value)); + generalCache.put(new Integer(index), Long.valueOf(value)); } public synchronized void dispose() { diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java b/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java index 961f7a0682e..82814627077 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFImageReader.java @@ -616,7 +616,7 @@ public class GIFImageReader extends ImageReader { return index; } - Long l1 = new Long(stream.getStreamPosition()); + Long l1 = stream.getStreamPosition(); imageStartPosition.add(l1); ++index; } diff --git a/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java index 8b6cdcbce13..5743cedc904 100644 --- a/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +++ b/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java @@ -367,10 +367,10 @@ public class JPEGImageReader extends ImageReader { // Now we are at the first image if there are any, so add it // to the list if (hasNextImage()) { - imagePositions.add(new Long(iis.getStreamPosition())); + imagePositions.add(iis.getStreamPosition()); } } else { // Not tables only, so add original pos to the list - imagePositions.add(new Long(savePos)); + imagePositions.add(savePos); // And set current image since we've read it now currentImage = 0; } @@ -498,7 +498,7 @@ public class JPEGImageReader extends ImageReader { if (!hasNextImage()) { throw new IndexOutOfBoundsException(); } - pos = new Long(iis.getStreamPosition()); + pos = iis.getStreamPosition(); imagePositions.add(pos); if (seekForwardOnly) { iis.flushBefore(pos.longValue()); diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java index 7d29b251127..f65d887050b 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpCounter64.java @@ -84,7 +84,7 @@ public class SnmpCounter64 extends SnmpValue { * @return The Long representation of the value. */ public Long toLong() { - return new Long(value) ; + return value; } /** diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpInt.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpInt.java index a6114d7dbc5..eb536581bb8 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpInt.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpInt.java @@ -130,7 +130,7 @@ public class SnmpInt extends SnmpValue { * @return The Long representation of the value. */ public Long toLong() { - return new Long(value) ; + return value; } /** diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java b/jdk/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java index b689ef287e7..99223ea0cb8 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibGroup.java @@ -136,7 +136,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid */ public boolean isNestedArc(long arc) { if (subgroups == null) return false; - Object obj = subgroups.get(new Long(arc)); + Object obj = subgroups.get(arc); // if the arc is registered in the hashtable, // it leads to a subgroup. return (obj != null); @@ -260,7 +260,7 @@ public abstract class SnmpMibGroup extends SnmpMibOid * */ void registerNestedArc(long arc) { - Long obj = new Long(arc); + Long obj = arc; if (subgroups == null) subgroups = new Hashtable<>(); // registers the arc in the hashtable. subgroups.put(obj,obj); diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java b/jdk/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java index 612d4c57437..b55c32ab1ea 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java @@ -858,7 +858,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutTraps() { - return new Long(snmpOutTraps); + return (long)snmpOutTraps; } /** @@ -868,7 +868,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutGetResponses() { - return new Long(snmpOutGetResponses); + return (long)snmpOutGetResponses; } /** @@ -878,7 +878,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutGenErrs() { - return new Long(snmpOutGenErrs); + return (long)snmpOutGenErrs; } /** @@ -888,7 +888,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutBadValues() { - return new Long(snmpOutBadValues); + return (long)snmpOutBadValues; } /** @@ -898,7 +898,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutNoSuchNames() { - return new Long(snmpOutNoSuchNames); + return (long)snmpOutNoSuchNames; } /** @@ -908,7 +908,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutTooBigs() { - return new Long(snmpOutTooBigs); + return (long)snmpOutTooBigs; } /** @@ -918,7 +918,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInASNParseErrs() { - return new Long(snmpInASNParseErrs); + return (long)snmpInASNParseErrs; } /** @@ -928,7 +928,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInBadCommunityUses() { - return new Long(snmpInBadCommunityUses); + return (long)snmpInBadCommunityUses; } /** @@ -939,7 +939,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInBadCommunityNames() { - return new Long(snmpInBadCommunityNames); + return (long)snmpInBadCommunityNames; } /** @@ -949,7 +949,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInBadVersions() { - return new Long(snmpInBadVersions); + return (long)snmpInBadVersions; } /** @@ -959,7 +959,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpOutPkts() { - return new Long(snmpOutPkts); + return (long)snmpOutPkts; } /** @@ -969,7 +969,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInPkts() { - return new Long(snmpInPkts); + return (long)snmpInPkts; } /** @@ -979,7 +979,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInGetRequests() { - return new Long(snmpInGetRequests); + return (long)snmpInGetRequests; } /** @@ -989,7 +989,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInGetNexts() { - return new Long(snmpInGetNexts); + return (long)snmpInGetNexts; } /** @@ -999,7 +999,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInSetRequests() { - return new Long(snmpInSetRequests); + return (long)snmpInSetRequests; } /** @@ -1009,7 +1009,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInTotalSetVars() { - return new Long(snmpInTotalSetVars); + return (long)snmpInTotalSetVars; } /** @@ -1019,7 +1019,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpInTotalReqVars() { - return new Long(snmpInTotalReqVars); + return (long)snmpInTotalReqVars; } /** @@ -1032,7 +1032,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpSilentDrops() { - return new Long(snmpSilentDrops); + return (long)snmpSilentDrops; } /** @@ -1045,7 +1045,7 @@ public class SnmpAdaptorServer extends CommunicatorServer */ @Override public Long getSnmpProxyDrops() { - return new Long(0); + return 0L; } diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java b/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java index 88b36cba315..a40b964c592 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java @@ -421,7 +421,7 @@ public final class LdapPoolManager { try { return Long.getLong(propName, defVal); } catch (SecurityException e) { - return new Long(defVal); + return defVal; } } }); diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java b/jdk/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java index d614aa943da..20794f8e502 100644 --- a/jdk/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java +++ b/jdk/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java @@ -221,7 +221,7 @@ final class NamingEventNotifier implements Runnable { return; NamingEvent e = new NamingEvent(eventSrc, NamingEvent.OBJECT_ADDED, - newBd, null, new Long(changeID)); + newBd, null, changeID); support.queueEvent(e, namingListeners); } @@ -233,7 +233,7 @@ final class NamingEventNotifier implements Runnable { return; NamingEvent e = new NamingEvent(eventSrc, NamingEvent.OBJECT_REMOVED, - null, oldBd, new Long(changeID)); + null, oldBd, changeID); support.queueEvent(e, namingListeners); } @@ -248,7 +248,7 @@ final class NamingEventNotifier implements Runnable { Binding oldBd = new Binding(newBd.getName(), null, newBd.isRelative()); NamingEvent e = new NamingEvent( - eventSrc, NamingEvent.OBJECT_CHANGED, newBd, oldBd, new Long(changeID)); + eventSrc, NamingEvent.OBJECT_CHANGED, newBd, oldBd, changeID); support.queueEvent(e, namingListeners); } @@ -273,7 +273,7 @@ final class NamingEventNotifier implements Runnable { } NamingEvent e = new NamingEvent( - eventSrc, NamingEvent.OBJECT_RENAMED, newBd, oldBd, new Long(changeID)); + eventSrc, NamingEvent.OBJECT_RENAMED, newBd, oldBd, changeID); support.queueEvent(e, namingListeners); } diff --git a/jdk/src/share/classes/com/sun/security/auth/SolarisNumericGroupPrincipal.java b/jdk/src/share/classes/com/sun/security/auth/SolarisNumericGroupPrincipal.java index 7924362f28b..04229eaab9c 100644 --- a/jdk/src/share/classes/com/sun/security/auth/SolarisNumericGroupPrincipal.java +++ b/jdk/src/share/classes/com/sun/security/auth/SolarisNumericGroupPrincipal.java @@ -110,7 +110,7 @@ public class SolarisNumericGroupPrincipal implements * */ public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) { - this.name = (new Long(name)).toString(); + this.name = Long.toString(name); this.primaryGroup = primaryGroup; } @@ -137,7 +137,7 @@ public class SolarisNumericGroupPrincipal implements * SolarisNumericGroupPrincipal as a long. */ public long longValue() { - return ((new Long(name)).longValue()); + return Long.parseLong(name); } /** diff --git a/jdk/src/share/classes/com/sun/security/auth/SolarisNumericUserPrincipal.java b/jdk/src/share/classes/com/sun/security/auth/SolarisNumericUserPrincipal.java index 86f7ed67768..d7ba9c038d7 100644 --- a/jdk/src/share/classes/com/sun/security/auth/SolarisNumericUserPrincipal.java +++ b/jdk/src/share/classes/com/sun/security/auth/SolarisNumericUserPrincipal.java @@ -96,7 +96,7 @@ public class SolarisNumericUserPrincipal implements * represented as a long. */ public SolarisNumericUserPrincipal(long name) { - this.name = (new Long(name)).toString(); + this.name = Long.toString(name); } /** @@ -122,7 +122,7 @@ public class SolarisNumericUserPrincipal implements * SolarisNumericUserPrincipal as a long. */ public long longValue() { - return ((new Long(name)).longValue()); + return Long.parseLong(name); } /** diff --git a/jdk/src/share/classes/com/sun/security/auth/UnixNumericGroupPrincipal.java b/jdk/src/share/classes/com/sun/security/auth/UnixNumericGroupPrincipal.java index db5775ab329..63c9d28c34d 100644 --- a/jdk/src/share/classes/com/sun/security/auth/UnixNumericGroupPrincipal.java +++ b/jdk/src/share/classes/com/sun/security/auth/UnixNumericGroupPrincipal.java @@ -102,7 +102,7 @@ public class UnixNumericGroupPrincipal implements * */ public UnixNumericGroupPrincipal(long name, boolean primaryGroup) { - this.name = (new Long(name)).toString(); + this.name = Long.toString(name); this.primaryGroup = primaryGroup; } @@ -129,7 +129,7 @@ public class UnixNumericGroupPrincipal implements * UnixNumericGroupPrincipal as a long. */ public long longValue() { - return ((new Long(name)).longValue()); + return Long.parseLong(name); } /** diff --git a/jdk/src/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.java b/jdk/src/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.java index c6dfd7eaf1b..e2016efe77d 100644 --- a/jdk/src/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.java +++ b/jdk/src/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.java @@ -87,7 +87,7 @@ public class UnixNumericUserPrincipal implements * represented as a long. */ public UnixNumericUserPrincipal(long name) { - this.name = (new Long(name)).toString(); + this.name = Long.toString(name); } /** @@ -113,7 +113,7 @@ public class UnixNumericUserPrincipal implements * UnixNumericUserPrincipal as a long. */ public long longValue() { - return ((new Long(name)).longValue()); + return Long.parseLong(name); } /** diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java index db0f25c1cb8..2bd04857e00 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/BreakpointSpec.java @@ -142,8 +142,8 @@ class BreakpointSpec extends EventRequestSpec { refSpec.toString())); } else if (e instanceof LineNotFoundException) { return (MessageOutput.format("No code at line", - new Object [] {new Long (lineNumber()), - refSpec.toString()})); + new Object [] {Long.valueOf(lineNumber()), + refSpec.toString()})); } else if (e instanceof InvalidTypeException) { return (MessageOutput.format("Breakpoints can be located only in classes.", refSpec.toString())); diff --git a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java index 65a0a800e09..2ea7d487a02 100644 --- a/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java +++ b/jdk/src/share/classes/com/sun/tools/example/debug/tty/Commands.java @@ -935,7 +935,7 @@ class Commands { try { methodInfo = loc.sourceName() + MessageOutput.format("line number", - new Object [] {new Long(lineNumber)}); + new Object [] {Long.valueOf(lineNumber)}); } catch (AbsentInformationException e) { methodInfo = MessageOutput.format("unknown"); } @@ -946,7 +946,7 @@ class Commands { meth.declaringType().name(), meth.name(), methodInfo, - new Long(pc)}); + Long.valueOf(pc)}); } else { MessageOutput.println("stack frame dump", new Object [] {new Integer(frameNumber + 1), @@ -1015,7 +1015,7 @@ class Commands { new Object [] {loc.declaringType().name(), loc.method().name(), new Integer (loc.lineNumber()), - new Long (loc.codeIndex())}); + Long.valueOf(loc.codeIndex())}); } void listBreakpoints() { diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/model/JavaLazyReadObject.java b/jdk/src/share/classes/com/sun/tools/hat/internal/model/JavaLazyReadObject.java index 0727d519ca6..7b80466f488 100644 --- a/jdk/src/share/classes/com/sun/tools/hat/internal/model/JavaLazyReadObject.java +++ b/jdk/src/share/classes/com/sun/tools/hat/internal/model/JavaLazyReadObject.java @@ -102,7 +102,7 @@ public abstract class JavaLazyReadObject extends JavaHeapObject { if ((id & ~Snapshot.SMALL_ID_MASK) == 0) { return new Integer((int)id); } else { - return new Long(id); + return id; } } diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java b/jdk/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java index 4d881fd0d72..51f922c8044 100644 --- a/jdk/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java +++ b/jdk/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java @@ -583,7 +583,7 @@ public class Snapshot { if (identifierSize == 4) { return new Integer((int)id); } else { - return new Long(id); + return id; } } diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java b/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java index 33cdb3aa3e1..8a5afa88854 100644 --- a/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java +++ b/jdk/src/share/classes/com/sun/tools/hat/internal/parser/HprofReader.java @@ -215,7 +215,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes long id = readID(); byte[] chars = new byte[(int)length - identifierSize]; in.readFully(chars); - names.put(new Long(id), new String(chars)); + names.put(id, new String(chars)); break; } case HPROF_LOAD_CLASS: { @@ -223,7 +223,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes long classID = readID(); int stackTraceSerialNo = in.readInt(); long classNameID = readID(); - Long classIdI = new Long(classID); + Long classIdI = classID; String nm = getNameFromID(classNameID).replace('/', '.'); classNameFromObjectID.put(classIdI, nm); if (classNameFromSerialNo != null) { @@ -303,7 +303,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes warn("Weird stack frame line number: " + lineNumber); lineNumber = StackFrame.LINE_NUMBER_UNKNOWN; } - stackFrames.put(new Long(id), + stackFrames.put(id, new StackFrame(methodName, methodSig, className, sourceFile, lineNumber)); @@ -319,7 +319,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes StackFrame[] frames = new StackFrame[in.readInt()]; for (int i = 0; i < frames.length; i++) { long fid = readID(); - frames[i] = stackFrames.get(new Long(fid)); + frames[i] = stackFrames.get(fid); if (frames[i] == null) { throw new IOException("Stack frame " + toHex(fid) + " not found"); } @@ -619,7 +619,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes } private String getNameFromID(long id) throws IOException { - return getNameFromID(new Long(id)); + return getNameFromID(Long.valueOf(id)); } private String getNameFromID(Long id) throws IOException { @@ -703,7 +703,7 @@ public class HprofReader extends Reader /* imports */ implements ArrayTypeCodes String signature = "" + ((char) type); fields[i] = new JavaField(fieldName, signature); } - String name = classNameFromObjectID.get(new Long(id)); + String name = classNameFromObjectID.get(id); if (name == null) { warn("Class name not found for " + toHex(id)); name = "unknown-name@" + toHex(id); diff --git a/jdk/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java b/jdk/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java index ccffc6d5602..73755c2e523 100644 --- a/jdk/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java +++ b/jdk/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java @@ -63,9 +63,9 @@ public class RefsByTypeQuery extends QueryHandler { } Long count = referrersStat.get(cl); if (count == null) { - count = new Long(1); + count = 1L; } else { - count = new Long(count.longValue() + 1); + count = count + 1L; } referrersStat.put(cl, count); } @@ -75,9 +75,9 @@ public class RefsByTypeQuery extends QueryHandler { JavaClass cl = obj.getClazz(); Long count = refereesStat.get(cl); if (count == null) { - count = new Long(1); + count = 1L; } else { - count = new Long(count.longValue() + 1); + count = count + 1L; } refereesStat.put(cl, count); } diff --git a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java index ca1c6e21408..c03ed4de31b 100644 --- a/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java +++ b/jdk/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java @@ -781,7 +781,7 @@ class VirtualMachineImpl extends MirrorImpl type.setSignature(signature); } - typesByID.put(new Long(id), type); + typesByID.put(id, type); typesBySignature.add(type); if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) { @@ -809,7 +809,7 @@ class VirtualMachineImpl extends MirrorImpl if (comp == 0) { matches++; iter.remove(); - typesByID.remove(new Long(type.ref())); + typesByID.remove(type.ref()); if ((vm.traceFlags & VirtualMachine.TRACE_REFTYPES) != 0) { vm.printTrace("Uncaching ReferenceType, sig=" + signature + ", id=" + type.ref()); @@ -895,7 +895,7 @@ class VirtualMachineImpl extends MirrorImpl ReferenceTypeImpl retType = null; synchronized (this) { if (typesByID != null) { - retType = (ReferenceTypeImpl)typesByID.get(new Long(id)); + retType = (ReferenceTypeImpl)typesByID.get(id); } if (retType == null) { retType = addReferenceType(id, tag, signature); @@ -1247,7 +1247,7 @@ class VirtualMachineImpl extends MirrorImpl return null; } ObjectReferenceImpl object = null; - Long key = new Long(id); + Long key = id; /* * Attempt to retrieve an existing object object reference @@ -1313,7 +1313,7 @@ class VirtualMachineImpl extends MirrorImpl // Handle any queue elements that are not strongly reachable processQueue(); - SoftObjectReference ref = objectsByID.remove(new Long(object.ref())); + SoftObjectReference ref = objectsByID.remove(object.ref()); if (ref != null) { batchForDispose(ref); } else { diff --git a/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java b/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java index bf14e8ce2d3..63e510d9c83 100644 --- a/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java +++ b/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java @@ -381,7 +381,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock add(long l) { - return add(new Long(l)); + return add(Long.valueOf(l)); } /** @@ -505,7 +505,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock set(long l, int index) { - return set(new Long(l), index); + return set(Long.valueOf(l), index); } /** diff --git a/jdk/src/share/classes/java/text/DecimalFormat.java b/jdk/src/share/classes/java/text/DecimalFormat.java index f89fd151749..a82011fd7d5 100644 --- a/jdk/src/share/classes/java/text/DecimalFormat.java +++ b/jdk/src/share/classes/java/text/DecimalFormat.java @@ -2094,7 +2094,7 @@ public class DecimalFormat extends NumberFormat { } return gotDouble ? - (Number)new Double(doubleResult) : (Number)new Long(longResult); + (Number)new Double(doubleResult) : (Number)Long.valueOf(longResult); } } diff --git a/jdk/src/share/classes/javax/management/loading/MLet.java b/jdk/src/share/classes/javax/management/loading/MLet.java index ac80c38b93c..b3f507839ad 100644 --- a/jdk/src/share/classes/javax/management/loading/MLet.java +++ b/jdk/src/share/classes/javax/management/loading/MLet.java @@ -1311,7 +1311,7 @@ public class MLet extends java.net.URLClassLoader if (type.compareTo("java.lang.Short") == 0) return new Short(param); if (type.compareTo("java.lang.Long") == 0) - return new Long(param); + return Long.valueOf(param); if (type.compareTo("java.lang.Integer") == 0) return new Integer(param); if (type.compareTo("java.lang.Float") == 0) diff --git a/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java b/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java index 869a2c8cdc8..d9323203a03 100644 --- a/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java +++ b/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java @@ -544,7 +544,7 @@ public class RequiredModelMBean } // convert seconds to milliseconds for time comparison - currencyPeriod = ((new Long(expTime)).longValue()) * 1000; + currencyPeriod = Long.parseLong(expTime) * 1000; if (currencyPeriod < 0) { /* if currencyTimeLimit is -1 then value is never cached */ returnCachedValue = false; @@ -580,7 +580,7 @@ public class RequiredModelMBean if (tStamp == null) tStamp = "0"; - long lastTime = (new Long(tStamp)).longValue(); + long lastTime = Long.parseLong(tStamp); if (tracing) { MODELMBEAN_LOGGER.logp(Level.FINER, diff --git a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java index 6ed2265087e..8c1622a4f2a 100644 --- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -458,7 +458,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab Integer fiveHundred = new Integer(500); // *** Shared Longs - Long oneThousand = new Long(1000); + Long oneThousand = 1000L; LazyValue dialogPlain12 = t -> new FontUIResource(Font.DIALOG, Font.PLAIN, 12); diff --git a/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java index faa79c22c8a..27d5431b1bf 100644 --- a/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java +++ b/jdk/src/share/classes/sun/jvmstat/perfdata/monitor/PerfLongMonitor.java @@ -66,7 +66,7 @@ public class PerfLongMonitor extends AbstractMonitor implements LongMonitor { * return type is guaranteed to be of type Long. */ public Object getValue() { - return new Long(lb.get(0)); + return Long.valueOf(lb.get(0)); } /** diff --git a/jdk/src/share/classes/sun/management/GcInfoCompositeData.java b/jdk/src/share/classes/sun/management/GcInfoCompositeData.java index b5797c947a4..a7730300e76 100644 --- a/jdk/src/share/classes/sun/management/GcInfoCompositeData.java +++ b/jdk/src/share/classes/sun/management/GcInfoCompositeData.java @@ -105,10 +105,10 @@ public class GcInfoCompositeData extends LazyCompositeData { try { baseGcInfoItemValues = new Object[] { - new Long(info.getId()), - new Long(info.getStartTime()), - new Long(info.getEndTime()), - new Long(info.getDuration()), + info.getId(), + info.getStartTime(), + info.getEndTime(), + info.getDuration(), memoryUsageMapType.toOpenTypeData(info.getMemoryUsageBeforeGc()), memoryUsageMapType.toOpenTypeData(info.getMemoryUsageAfterGc()), }; diff --git a/jdk/src/share/classes/sun/management/HotspotThread.java b/jdk/src/share/classes/sun/management/HotspotThread.java index 17319ba1526..03e403a8983 100644 --- a/jdk/src/share/classes/sun/management/HotspotThread.java +++ b/jdk/src/share/classes/sun/management/HotspotThread.java @@ -60,7 +60,7 @@ class HotspotThread int numThreads = getInternalThreadTimes0(names, times); Map result = new HashMap<>(numThreads); for (int i = 0; i < numThreads; i++) { - result.put(names[i], new Long(times[i])); + result.put(names[i], times[i]); } return result; } diff --git a/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java b/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java index b99ccdaed19..219b2d9fbc1 100644 --- a/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java +++ b/jdk/src/share/classes/sun/management/MemoryNotifInfoCompositeData.java @@ -60,7 +60,7 @@ public class MemoryNotifInfoCompositeData extends LazyCompositeData { final Object[] memoryNotifInfoItemValues = { memoryNotifInfo.getPoolName(), MemoryUsageCompositeData.toCompositeData(memoryNotifInfo.getUsage()), - new Long(memoryNotifInfo.getCount()), + memoryNotifInfo.getCount(), }; try { diff --git a/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java b/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java index a30795201ce..0b3a6e0656f 100644 --- a/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java +++ b/jdk/src/share/classes/sun/management/MemoryUsageCompositeData.java @@ -56,10 +56,10 @@ public class MemoryUsageCompositeData extends LazyCompositeData { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // memoryUsageItemNames! final Object[] memoryUsageItemValues = { - new Long(usage.getInit()), - new Long(usage.getUsed()), - new Long(usage.getCommitted()), - new Long(usage.getMax()), + usage.getInit(), + usage.getUsed(), + usage.getCommitted(), + usage.getMax(), }; try { diff --git a/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java b/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java index cef28271e7e..1067c175939 100644 --- a/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java +++ b/jdk/src/share/classes/sun/management/ThreadInfoCompositeData.java @@ -108,16 +108,16 @@ public class ThreadInfoCompositeData extends LazyCompositeData { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // threadInfoItemNames! final Object[] threadInfoItemValues = { - new Long(threadInfo.getThreadId()), + threadInfo.getThreadId(), threadInfo.getThreadName(), threadInfo.getThreadState().name(), - new Long(threadInfo.getBlockedTime()), - new Long(threadInfo.getBlockedCount()), - new Long(threadInfo.getWaitedTime()), - new Long(threadInfo.getWaitedCount()), + threadInfo.getBlockedTime(), + threadInfo.getBlockedCount(), + threadInfo.getWaitedTime(), + threadInfo.getWaitedCount(), lockInfoData, threadInfo.getLockName(), - new Long(threadInfo.getLockOwnerId()), + threadInfo.getLockOwnerId(), threadInfo.getLockOwnerName(), stackTraceData, threadInfo.isSuspended(), diff --git a/jdk/src/share/classes/sun/management/counter/perf/LongCounterSnapshot.java b/jdk/src/share/classes/sun/management/counter/perf/LongCounterSnapshot.java index 5935f7f7920..1281a688eb2 100644 --- a/jdk/src/share/classes/sun/management/counter/perf/LongCounterSnapshot.java +++ b/jdk/src/share/classes/sun/management/counter/perf/LongCounterSnapshot.java @@ -43,7 +43,7 @@ class LongCounterSnapshot extends AbstractCounter } public Object getValue() { - return new Long(value); + return Long.valueOf(value); } /** diff --git a/jdk/src/share/classes/sun/management/counter/perf/PerfLongCounter.java b/jdk/src/share/classes/sun/management/counter/perf/PerfLongCounter.java index e50ccd54153..b0246ed717a 100644 --- a/jdk/src/share/classes/sun/management/counter/perf/PerfLongCounter.java +++ b/jdk/src/share/classes/sun/management/counter/perf/PerfLongCounter.java @@ -42,7 +42,7 @@ public class PerfLongCounter extends AbstractCounter } public Object getValue() { - return new Long(lb.get(0)); + return Long.valueOf(lb.get(0)); } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmClassLoadingImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmClassLoadingImpl.java index af8900b433d..e4a9953ea81 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmClassLoadingImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmClassLoadingImpl.java @@ -129,21 +129,21 @@ public class JvmClassLoadingImpl implements JvmClassLoadingMBean { * Getter for the "JvmClassesUnloadedCount" variable. */ public Long getJvmClassesUnloadedCount() throws SnmpStatusException { - return new Long(getClassLoadingMXBean().getUnloadedClassCount()); + return getClassLoadingMXBean().getUnloadedClassCount(); } /** * Getter for the "JvmClassesTotalLoadedCount" variable. */ public Long getJvmClassesTotalLoadedCount() throws SnmpStatusException { - return new Long(getClassLoadingMXBean().getTotalLoadedClassCount()); + return getClassLoadingMXBean().getTotalLoadedClassCount(); } /** * Getter for the "JvmClassesLoadedCount" variable. */ public Long getJvmClassesLoadedCount() throws SnmpStatusException { - return new Long(getClassLoadingMXBean().getLoadedClassCount()); + return (long)getClassLoadingMXBean().getLoadedClassCount(); } } diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmCompilationImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmCompilationImpl.java index ef699c7033d..7e3ce4bd4d4 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmCompilationImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmCompilationImpl.java @@ -115,7 +115,7 @@ public class JvmCompilationImpl implements JvmCompilationMBean { t = getCompilationMXBean().getTotalCompilationTime(); else t = 0; - return new Long(t); + return t; } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemGCEntryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemGCEntryImpl.java index f6f125bc2cc..7c23d772fc2 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemGCEntryImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemGCEntryImpl.java @@ -70,7 +70,7 @@ public class JvmMemGCEntryImpl implements JvmMemGCEntryMBean { */ // Don't bother to uses the request contextual cache for this. public Long getJvmMemGCTimeMs() throws SnmpStatusException { - return new Long(gcm.getCollectionTime()); + return gcm.getCollectionTime(); } /** @@ -78,7 +78,7 @@ public class JvmMemGCEntryImpl implements JvmMemGCEntryMBean { */ // Don't bother to uses the request contextual cache for this. public Long getJvmMemGCCount() throws SnmpStatusException { - return new Long(gcm.getCollectionCount()); + return gcm.getCollectionCount(); } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java index f86ef931805..f1b14602224 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemPoolEntryImpl.java @@ -191,7 +191,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolMaxSize() throws SnmpStatusException { final long val = getMemoryUsage().getMax(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -200,7 +200,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolUsed() throws SnmpStatusException { final long val = getMemoryUsage().getUsed(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -209,7 +209,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolInitSize() throws SnmpStatusException { final long val = getMemoryUsage().getInit(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -218,7 +218,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolCommitted() throws SnmpStatusException { final long val = getMemoryUsage().getCommitted(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -227,7 +227,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolPeakMaxSize() throws SnmpStatusException { final long val = getPeakMemoryUsage().getMax(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -236,7 +236,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolPeakUsed() throws SnmpStatusException { final long val = getPeakMemoryUsage().getUsed(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -245,7 +245,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolPeakCommitted() throws SnmpStatusException { final long val = getPeakMemoryUsage().getCommitted(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -254,7 +254,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolCollectMaxSize() throws SnmpStatusException { final long val = getCollectMemoryUsage().getMax(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -263,7 +263,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolCollectUsed() throws SnmpStatusException { final long val = getCollectMemoryUsage().getUsed(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -272,7 +272,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public Long getJvmMemPoolCollectCommitted() throws SnmpStatusException { final long val = getCollectMemoryUsage().getCommitted(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -283,7 +283,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { if (!pool.isUsageThresholdSupported()) return JvmMemoryImpl.Long0; final long val = pool.getUsageThreshold(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -334,7 +334,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { if (!pool.isUsageThresholdSupported()) return JvmMemoryImpl.Long0; final long val = pool.getUsageThresholdCount(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -345,7 +345,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { if (!pool.isCollectionUsageThresholdSupported()) return JvmMemoryImpl.Long0; final long val = pool.getCollectionUsageThreshold(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -399,7 +399,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { if (!pool.isCollectionUsageThresholdSupported()) return JvmMemoryImpl.Long0; final long val = pool.getCollectionUsageThresholdCount(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return JvmMemoryImpl.Long0; } @@ -450,7 +450,7 @@ public class JvmMemPoolEntryImpl implements JvmMemPoolEntryMBean { */ public synchronized Long getJvmMemPoolPeakReset() throws SnmpStatusException { - return new Long(jvmMemPoolPeakReset); + return jvmMemPoolPeakReset; } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java index a40267d0799..c24866e4d2f 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java @@ -222,7 +222,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { } } - static final Long Long0 = new Long(0); + static final Long Long0 = 0L; /** * Getter for the "JvmMemoryNonHeapMaxSize" variable. @@ -230,7 +230,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { public Long getJvmMemoryNonHeapMaxSize() throws SnmpStatusException { final long val = getNonHeapMemoryUsage().getMax(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -239,7 +239,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryNonHeapCommitted() throws SnmpStatusException { final long val = getNonHeapMemoryUsage().getCommitted(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -248,7 +248,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryNonHeapUsed() throws SnmpStatusException { final long val = getNonHeapMemoryUsage().getUsed(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -257,7 +257,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryNonHeapInitSize() throws SnmpStatusException { final long val = getNonHeapMemoryUsage().getInit(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -266,7 +266,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryHeapMaxSize() throws SnmpStatusException { final long val = getHeapMemoryUsage().getMax(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -320,7 +320,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryHeapCommitted() throws SnmpStatusException { final long val = getHeapMemoryUsage().getCommitted(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -359,7 +359,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryHeapUsed() throws SnmpStatusException { final long val = getHeapMemoryUsage().getUsed(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -368,7 +368,7 @@ public class JvmMemoryImpl implements JvmMemoryMBean { */ public Long getJvmMemoryHeapInitSize() throws SnmpStatusException { final long val = getHeapMemoryUsage().getInit(); - if (val > -1) return new Long(val); + if (val > -1) return val; else return Long0; } @@ -380,11 +380,11 @@ public class JvmMemoryImpl implements JvmMemoryMBean { final long val = ManagementFactory.getMemoryMXBean(). getObjectPendingFinalizationCount(); - if (val > -1) return new Long((int)val); + if (val > -1) return Long.valueOf((int) val); // Should never happen... but stay safe all the same. // - else return new Long(0); + else return 0L; } static final MibLogger log = new MibLogger(JvmMemoryImpl.class); diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmRuntimeImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmRuntimeImpl.java index fea0240b365..cf62699872f 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmRuntimeImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmRuntimeImpl.java @@ -259,14 +259,14 @@ public class JvmRuntimeImpl implements JvmRuntimeMBean { * Getter for the "JvmRTUptimeMs" variable. */ public Long getJvmRTUptimeMs() throws SnmpStatusException { - return new Long(getRuntimeMXBean().getUptime()); + return getRuntimeMXBean().getUptime(); } /** * Getter for the "JvmRTStartTimeMs" variable. */ public Long getJvmRTStartTimeMs() throws SnmpStatusException { - return new Long(getRuntimeMXBean().getStartTime()); + return getRuntimeMXBean().getStartTime(); } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java index b4344def620..d419e57e899 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java @@ -231,7 +231,7 @@ public class JvmThreadInstanceEntryImpl log.debug("getJvmThreadInstCpuTimeNs", "Operation not supported: " + e); } - return new Long(l); + return l; } /** @@ -248,14 +248,14 @@ public class JvmThreadInstanceEntryImpl //Monitoring is disabled if(l == -1) l = 0; } - return new Long(l); + return l; } /** * Getter for the "JvmThreadInstBlockCount" variable. */ public Long getJvmThreadInstBlockCount() throws SnmpStatusException { - return new Long(info.getBlockedCount()); + return info.getBlockedCount(); } /** @@ -272,14 +272,14 @@ public class JvmThreadInstanceEntryImpl //Monitoring is disabled if(l == -1) l = 0; } - return new Long(l); + return l; } /** * Getter for the "JvmThreadInstWaitCount" variable. */ public Long getJvmThreadInstWaitCount() throws SnmpStatusException { - return new Long(info.getWaitedCount()); + return info.getWaitedCount(); } /** @@ -294,7 +294,7 @@ public class JvmThreadInstanceEntryImpl * Getter for the "JvmThreadInstId" variable. */ public Long getJvmThreadInstId() throws SnmpStatusException { - return new Long(info.getThreadId()); + return info.getThreadId(); } /** diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadingImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadingImpl.java index 480642c3253..e4a1f01d024 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadingImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadingImpl.java @@ -303,28 +303,28 @@ public class JvmThreadingImpl implements JvmThreadingMBean { * Getter for the "JvmThreadTotalStartedCount" variable. */ public Long getJvmThreadTotalStartedCount() throws SnmpStatusException { - return new Long(getThreadMXBean().getTotalStartedThreadCount()); + return getThreadMXBean().getTotalStartedThreadCount(); } /** * Getter for the "JvmThreadPeakCount" variable. */ public Long getJvmThreadPeakCount() throws SnmpStatusException { - return new Long(getThreadMXBean().getPeakThreadCount()); + return (long)getThreadMXBean().getPeakThreadCount(); } /** * Getter for the "JvmThreadDaemonCount" variable. */ public Long getJvmThreadDaemonCount() throws SnmpStatusException { - return new Long(getThreadMXBean().getDaemonThreadCount()); + return (long)getThreadMXBean().getDaemonThreadCount(); } /** * Getter for the "JvmThreadCount" variable. */ public Long getJvmThreadCount() throws SnmpStatusException { - return new Long(getThreadMXBean().getThreadCount()); + return (long)getThreadMXBean().getThreadCount(); } /** @@ -332,7 +332,7 @@ public class JvmThreadingImpl implements JvmThreadingMBean { */ public synchronized Long getJvmThreadPeakCountReset() throws SnmpStatusException { - return new Long(jvmThreadPeakCountReset); + return jvmThreadPeakCountReset; } /** diff --git a/jdk/src/share/classes/sun/nio/ch/Util.java b/jdk/src/share/classes/sun/nio/ch/Util.java index dca91d6e8b2..5a30b51721b 100644 --- a/jdk/src/share/classes/sun/nio/ch/Util.java +++ b/jdk/src/share/classes/sun/nio/ch/Util.java @@ -329,7 +329,7 @@ public class Util { try { dbb = (MappedByteBuffer)directByteBufferConstructor.newInstance( new Object[] { new Integer(size), - new Long(addr), + addr, fd, unmapper }); } catch (InstantiationException | @@ -374,7 +374,7 @@ public class Util { try { dbb = (MappedByteBuffer)directByteBufferRConstructor.newInstance( new Object[] { new Integer(size), - new Long(addr), + addr, fd, unmapper }); } catch (InstantiationException | diff --git a/jdk/src/share/classes/sun/security/action/GetLongAction.java b/jdk/src/share/classes/sun/security/action/GetLongAction.java index 4b99f02ae03..fdadc191b72 100644 --- a/jdk/src/share/classes/sun/security/action/GetLongAction.java +++ b/jdk/src/share/classes/sun/security/action/GetLongAction.java @@ -106,7 +106,7 @@ public class GetLongAction implements java.security.PrivilegedAction { public Long run() { Long value = Long.getLong(theProp); if ((value == null) && defaultSet) - return new Long(defaultVal); + return defaultVal; return value; } } diff --git a/jdk/src/share/classes/sun/security/jgss/wrapper/GSSNameElement.java b/jdk/src/share/classes/sun/security/jgss/wrapper/GSSNameElement.java index b98dcea6fce..1f216ec32bd 100644 --- a/jdk/src/share/classes/sun/security/jgss/wrapper/GSSNameElement.java +++ b/jdk/src/share/classes/sun/security/jgss/wrapper/GSSNameElement.java @@ -203,7 +203,7 @@ public class GSSNameElement implements GSSNameSpi { } public int hashCode() { - return new Long(pName).hashCode(); + return Long.hashCode(pName); } public byte[] export() throws GSSException { diff --git a/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java b/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java index 3beaac873ce..264f2e06192 100644 --- a/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java +++ b/jdk/src/share/classes/sun/security/krb5/internal/KerberosTime.java @@ -188,8 +188,8 @@ public class KerberosTime { } public int getMicroSeconds() { - Long temp_long = new Long((kerberosTime % 1000L) * 1000L); - return temp_long.intValue() + microSeconds; + int temp_int = (int) ((kerberosTime % 1000L) * 1000L); + return temp_int + microSeconds; } /** @@ -250,8 +250,7 @@ public class KerberosTime { } public int getSeconds() { - Long temp_long = new Long(kerberosTime / 1000L); - return temp_long.intValue(); + return (int) (kerberosTime / 1000L); } /** diff --git a/jdk/src/share/classes/sun/security/tools/keytool/Main.java b/jdk/src/share/classes/sun/security/tools/keytool/Main.java index 1618fe19f89..2947a3081a1 100644 --- a/jdk/src/share/classes/sun/security/tools/keytool/Main.java +++ b/jdk/src/share/classes/sun/security/tools/keytool/Main.java @@ -1675,7 +1675,7 @@ public final class Main { Object[] source = {new Integer(keysize), privKey.getAlgorithm(), chain[0].getSigAlgName(), - new Long(validity), + validity, x500Name}; System.err.println(form.format(source)); } diff --git a/jdk/src/share/classes/sun/tools/java/BinaryConstantPool.java b/jdk/src/share/classes/sun/tools/java/BinaryConstantPool.java index 2bcc7e1b32d..18d0087efb2 100644 --- a/jdk/src/share/classes/sun/tools/java/BinaryConstantPool.java +++ b/jdk/src/share/classes/sun/tools/java/BinaryConstantPool.java @@ -66,7 +66,7 @@ class BinaryConstantPool implements Constants { cpool[i] = new Float(in.readFloat()); break; case CONSTANT_LONG: - cpool[i++] = new Long(in.readLong()); + cpool[i++] = in.readLong(); break; case CONSTANT_DOUBLE: cpool[i++] = new Double(in.readDouble()); diff --git a/jdk/src/share/classes/sun/tools/jconsole/MemoryPoolProxy.java b/jdk/src/share/classes/sun/tools/jconsole/MemoryPoolProxy.java index 8bd37ce9a49..33fa55d73f7 100644 --- a/jdk/src/share/classes/sun/tools/jconsole/MemoryPoolProxy.java +++ b/jdk/src/share/classes/sun/tools/jconsole/MemoryPoolProxy.java @@ -56,7 +56,7 @@ public class MemoryPoolProxy { ObjectName mbeanName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + name); if (client.isRegistered(mbeanName)) { - gcMBeans.put(mbeanName, new Long(0)); + gcMBeans.put(mbeanName, 0L); } } catch (Exception e) { assert false; @@ -97,7 +97,7 @@ public class MemoryPoolProxy { Long gcCount = e.getValue(); Long newCount = gc.getCollectionCount(); if (newCount > gcCount) { - gcMBeans.put(e.getKey(), new Long(newCount)); + gcMBeans.put(e.getKey(), newCount); lastGcInfo = gc.getLastGcInfo(); if (lastGcInfo.getEndTime() > lastGcEndTime) { gcId = lastGcInfo.getId(); diff --git a/jdk/src/share/classes/sun/tools/tree/BitNotExpression.java b/jdk/src/share/classes/sun/tools/tree/BitNotExpression.java index b729c7de51b..ac1cf526d29 100644 --- a/jdk/src/share/classes/sun/tools/tree/BitNotExpression.java +++ b/jdk/src/share/classes/sun/tools/tree/BitNotExpression.java @@ -83,7 +83,7 @@ class BitNotExpression extends UnaryExpression { asm.add(where, opc_ldc, new Integer(-1)); asm.add(where, opc_ixor); } else { - asm.add(where, opc_ldc2_w, new Long(-1)); + asm.add(where, opc_ldc2_w, -1L); asm.add(where, opc_lxor); } } diff --git a/jdk/src/share/classes/sun/tools/tree/IncDecExpression.java b/jdk/src/share/classes/sun/tools/tree/IncDecExpression.java index 5a4021b8c3e..c9ec1ad3d2f 100644 --- a/jdk/src/share/classes/sun/tools/tree/IncDecExpression.java +++ b/jdk/src/share/classes/sun/tools/tree/IncDecExpression.java @@ -131,7 +131,7 @@ class IncDecExpression extends UnaryExpression { asm.add(where, inc ? opc_iadd : opc_isub); break; case TC_LONG: - asm.add(where, opc_ldc2_w, new Long(1)); + asm.add(where, opc_ldc2_w, 1L); asm.add(where, inc ? opc_ladd : opc_lsub); break; case TC_FLOAT: diff --git a/jdk/src/share/classes/sun/tools/tree/LongExpression.java b/jdk/src/share/classes/sun/tools/tree/LongExpression.java index 82f084ddbd4..d1900161ca8 100644 --- a/jdk/src/share/classes/sun/tools/tree/LongExpression.java +++ b/jdk/src/share/classes/sun/tools/tree/LongExpression.java @@ -50,7 +50,7 @@ class LongExpression extends ConstantExpression { * Get the value */ public Object getValue() { - return new Long(value); + return value; } /** @@ -71,7 +71,7 @@ class LongExpression extends ConstantExpression { * Code */ public void codeValue(Environment env, Context ctx, Assembler asm) { - asm.add(where, opc_ldc2_w, new Long(value)); + asm.add(where, opc_ldc2_w, value); } /** diff --git a/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java b/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java index 18af8c7830d..37c4458f6e4 100644 --- a/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java +++ b/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java @@ -747,7 +747,7 @@ class FileSystemPreferences extends AbstractPreferences { nmt = systemRootModFile.lastModified(); isSystemRootModified = systemRootModTime == nmt; } - return new Long(nmt); + return nmt; } }); try { diff --git a/jdk/src/solaris/classes/sun/awt/X11/XFocusProxyWindow.java b/jdk/src/solaris/classes/sun/awt/X11/XFocusProxyWindow.java index 293b9e05341..1365a7d8a07 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XFocusProxyWindow.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XFocusProxyWindow.java @@ -38,8 +38,9 @@ public class XFocusProxyWindow extends XBaseWindow { public XFocusProxyWindow(XWindowPeer owner) { super(new XCreateWindowParams(new Object[] { BOUNDS, new Rectangle(-1, -1, 1, 1), - PARENT_WINDOW, new Long(owner.getWindow()), - EVENT_MASK, new Long(XConstants.FocusChangeMask | XConstants.KeyPressMask | XConstants.KeyReleaseMask) + PARENT_WINDOW, Long.valueOf(owner.getWindow()), + EVENT_MASK, Long.valueOf(XConstants.FocusChangeMask | XConstants + .KeyPressMask | XConstants.KeyReleaseMask) })); this.owner = owner; } From 5a0450feea95340545d30d58bcb5714f3e595d21 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 1 Jul 2014 14:44:37 +0100 Subject: [PATCH 29/30] 8048874: Replace uses of 'new Byte', 'new Short' and 'new Character' with appropriate alternative across core classes Reviewed-by: chegar, psandoz, prappo --- .../plaf/windows/WindowsLookAndFeel.java | 3 +- .../classes/com/sun/jmx/snmp/SnmpString.java | 2 +- .../sun/jndi/toolkit/dir/SearchFilter.java | 2 +- .../security/sasl/digest/DigestMD5Base.java | 2 +- .../security/sasl/gsskerb/GssKrb5Client.java | 4 +-- .../security/sasl/gsskerb/GssKrb5Server.java | 4 +-- .../security/sasl/util/AbstractSaslImpl.java | 2 +- jdk/src/share/classes/java/awt/Component.java | 2 +- .../awt/image/renderable/ParameterBlock.java | 12 +++---- .../share/classes/java/beans/Statement.java | 2 +- .../javax/management/loading/MLet.java | 4 +-- .../jvminstr/JvmThreadInstanceEntryImpl.java | 2 +- .../classes/sun/misc/ProxyGenerator.java | 4 +-- .../sun/security/pkcs/PKCS9Attribute.java | 36 +++++++++---------- .../share/classes/sun/security/x509/AVA.java | 2 +- .../sun/tools/jconsole/inspector/Utils.java | 4 +-- 16 files changed, 43 insertions(+), 44 deletions(-) diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java index a6c1c895757..5998f85483c 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java @@ -1102,8 +1102,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel "PasswordField.selectionBackground", SelectionBackgroundColor, "PasswordField.selectionForeground", SelectionTextColor, "PasswordField.caretForeground",WindowTextColor, - "PasswordField.echoChar", new XPValue(new Character((char)0x25CF), - new Character('*')), + "PasswordField.echoChar", new XPValue((char)0x25CF, '*'), // *** ProgressBar "ProgressBar.font", ControlFont, diff --git a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpString.java b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpString.java index 169b67bcad3..675386ab1be 100644 --- a/jdk/src/share/classes/com/sun/jmx/snmp/SnmpString.java +++ b/jdk/src/share/classes/com/sun/jmx/snmp/SnmpString.java @@ -140,7 +140,7 @@ public class SnmpString extends SnmpValue { public Byte[] toByte() { Byte[] result = new Byte[value.length] ; for (int i = 0 ; i < value.length ; i++) { - result[i] = new Byte(value[i]) ; + result[i] = value[i]; } return result ; } diff --git a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java index bdbf578cc24..cf23c3dd2e4 100644 --- a/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java +++ b/jdk/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java @@ -379,7 +379,7 @@ public class SearchFilter implements AttrFilter { // used for substring comparisons (where proto has "*" wildcards private boolean substringMatch(String proto, String value) { // simple case 1: "*" means attribute presence is being tested - if(proto.equals(new Character(WILDCARD_TOKEN).toString())) { + if(proto.equals(Character.toString(WILDCARD_TOKEN))) { if(debug) {System.out.println("simple presence assertion");} return true; } diff --git a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java index 37a261a6a2f..3469e708233 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java +++ b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java @@ -1460,7 +1460,7 @@ abstract class DigestMD5Base extends AbstractSaslImpl { if (logger.isLoggable(Level.INFO)) { logger.log(Level.INFO, "DIGEST39:Incorrect padding: {0}", - new Byte(msgWithPadding[msgWithPadding.length - 1])); + msgWithPadding[msgWithPadding.length - 1]); } return EMPTY_BYTE_ARRAY; } diff --git a/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java b/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java index e8d9a4cc866..aca462929f7 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java +++ b/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java @@ -241,7 +241,7 @@ final class GssKrb5Client extends GssKrb5Base implements SaslClient { "KRB5CLNT05:Challenge [unwrapped]:", gssOutToken); } logger.log(Level.FINE, "KRB5CLNT06:Server protections: {0}", - new Byte(gssOutToken[0])); + gssOutToken[0]); } // Client selects preferred protection @@ -293,7 +293,7 @@ final class GssKrb5Client extends GssKrb5Base implements SaslClient { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "KRB5CLNT08:Selected protection: {0}; privacy: {1}; integrity: {2}", - new Object[]{new Byte(selectedQop), + new Object[]{selectedQop, Boolean.valueOf(privacy), Boolean.valueOf(integrity)}); } diff --git a/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java b/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java index 94ce39c0ad1..c15dfc9aae7 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java +++ b/jdk/src/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Server.java @@ -221,7 +221,7 @@ final class GssKrb5Server extends GssKrb5Base implements SaslServer { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "KRB5SRV06:Supported protections: {0}; recv max buf size: {1}", - new Object[]{new Byte(allQop), + new Object[]{allQop, new Integer(recvMaxBufSize)}); } @@ -288,7 +288,7 @@ final class GssKrb5Server extends GssKrb5Base implements SaslServer { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "KRB5SRV10:Selected protection: {0}; privacy: {1}; integrity: {2}", - new Object[]{new Byte(selectedQop), + new Object[]{selectedQop, Boolean.valueOf(privacy), Boolean.valueOf(integrity)}); logger.log(Level.FINE, diff --git a/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java b/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java index eb122e3bbb4..1136d8db723 100644 --- a/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java +++ b/jdk/src/share/classes/com/sun/security/sasl/util/AbstractSaslImpl.java @@ -77,7 +77,7 @@ public abstract class AbstractSaslImpl { if (logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, myClassName, "constructor", - "SASLIMPL02:Preferred qop mask: {0}", new Byte(allQop)); + "SASLIMPL02:Preferred qop mask: {0}", allQop); if (qop.length > 0) { StringBuilder str = new StringBuilder(); diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index b062cc718b7..24cc58733e7 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -8640,7 +8640,7 @@ public abstract class Component implements ImageObserver, MenuContainer, if (changeSupport == null || oldValue == newValue) { return; } - firePropertyChange(propertyName, new Character(oldValue), new Character(newValue)); + firePropertyChange(propertyName, Character.valueOf(oldValue), Character.valueOf(newValue)); } /** diff --git a/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java b/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java index 63e510d9c83..e6b923dda0e 100644 --- a/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java +++ b/jdk/src/share/classes/java/awt/image/renderable/ParameterBlock.java @@ -337,7 +337,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock add(byte b) { - return add(new Byte(b)); + return add(Byte.valueOf(b)); } /** @@ -348,7 +348,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock add(char c) { - return add(new Character(c)); + return add(Character.valueOf(c)); } /** @@ -359,7 +359,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock add(short s) { - return add(new Short(s)); + return add(Short.valueOf(s)); } /** @@ -441,7 +441,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock set(byte b, int index) { - return set(new Byte(b), index); + return set(Byte.valueOf(b), index); } /** @@ -457,7 +457,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock set(char c, int index) { - return set(new Character(c), index); + return set(Character.valueOf(c), index); } /** @@ -473,7 +473,7 @@ public class ParameterBlock implements Cloneable, Serializable { * the specified parameter. */ public ParameterBlock set(short s, int index) { - return set(new Short(s), index); + return set(Short.valueOf(s), index); } /** diff --git a/jdk/src/share/classes/java/beans/Statement.java b/jdk/src/share/classes/java/beans/Statement.java index d1e6717817f..fc11a42be12 100644 --- a/jdk/src/share/classes/java/beans/Statement.java +++ b/jdk/src/share/classes/java/beans/Statement.java @@ -248,7 +248,7 @@ public class Statement { // ignored elsewhere. if (target == Character.class && arguments.length == 1 && argClasses[0] == String.class) { - return new Character(((String)arguments[0]).charAt(0)); + return ((String)arguments[0]).charAt(0); } try { m = ConstructorFinder.findConstructor((Class)target, argClasses); diff --git a/jdk/src/share/classes/javax/management/loading/MLet.java b/jdk/src/share/classes/javax/management/loading/MLet.java index b3f507839ad..54f2a872512 100644 --- a/jdk/src/share/classes/javax/management/loading/MLet.java +++ b/jdk/src/share/classes/javax/management/loading/MLet.java @@ -1307,9 +1307,9 @@ public class MLet extends java.net.URLClassLoader if (type.compareTo("java.lang.Boolean") == 0) return Boolean.valueOf(param); if (type.compareTo("java.lang.Byte") == 0) - return new Byte(param); + return Byte.valueOf(param); if (type.compareTo("java.lang.Short") == 0) - return new Short(param); + return Short.valueOf(param); if (type.compareTo("java.lang.Long") == 0) return Long.valueOf(param); if (type.compareTo("java.lang.Integer") == 0) diff --git a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java index d419e57e899..455bd677fc6 100644 --- a/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java +++ b/jdk/src/share/classes/sun/management/snmp/jvminstr/JvmThreadInstanceEntryImpl.java @@ -139,7 +139,7 @@ public class JvmThreadInstanceEntryImpl "Unexpected exception: " + r); log.debug("getJvmThreadInstState",r); } - Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) }; + Byte[] result = {bitmap[0], bitmap[1]}; return result; } } diff --git a/jdk/src/share/classes/sun/misc/ProxyGenerator.java b/jdk/src/share/classes/sun/misc/ProxyGenerator.java index d561df61d27..844987823a7 100644 --- a/jdk/src/share/classes/sun/misc/ProxyGenerator.java +++ b/jdk/src/share/classes/sun/misc/ProxyGenerator.java @@ -1885,7 +1885,7 @@ public class ProxyGenerator { "late constant pool addition: " + key); } short i = addEntry(new ValueEntry(key)); - map.put(key, new Short(i)); + map.put(key, i); return i; } } @@ -1903,7 +1903,7 @@ public class ProxyGenerator { throw new InternalError("late constant pool addition"); } short i = addEntry(e); - map.put(e, new Short(i)); + map.put(e, i); return i; } } diff --git a/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java b/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java index ab103d5963e..943ba93cc28 100644 --- a/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java +++ b/jdk/src/share/classes/sun/security/pkcs/PKCS9Attribute.java @@ -309,26 +309,26 @@ public class PKCS9Attribute implements DerEncoder { */ private static final Byte[][] PKCS9_VALUE_TAGS = { null, - {new Byte(DerValue.tag_IA5String)}, // EMailAddress - {new Byte(DerValue.tag_IA5String), // UnstructuredName - new Byte(DerValue.tag_PrintableString)}, - {new Byte(DerValue.tag_ObjectId)}, // ContentType - {new Byte(DerValue.tag_OctetString)}, // MessageDigest - {new Byte(DerValue.tag_UtcTime)}, // SigningTime - {new Byte(DerValue.tag_Sequence)}, // Countersignature - {new Byte(DerValue.tag_PrintableString), - new Byte(DerValue.tag_T61String)}, // ChallengePassword - {new Byte(DerValue.tag_PrintableString), - new Byte(DerValue.tag_T61String)}, // UnstructuredAddress - {new Byte(DerValue.tag_SetOf)}, // ExtendedCertificateAttributes - {new Byte(DerValue.tag_Sequence)}, // issuerAndSerialNumber + {DerValue.tag_IA5String}, // EMailAddress + {DerValue.tag_IA5String, // UnstructuredName + DerValue.tag_PrintableString}, + {DerValue.tag_ObjectId}, // ContentType + {DerValue.tag_OctetString}, // MessageDigest + {DerValue.tag_UtcTime}, // SigningTime + {DerValue.tag_Sequence}, // Countersignature + {DerValue.tag_PrintableString, + DerValue.tag_T61String}, // ChallengePassword + {DerValue.tag_PrintableString, + DerValue.tag_T61String}, // UnstructuredAddress + {DerValue.tag_SetOf}, // ExtendedCertificateAttributes + {DerValue.tag_Sequence}, // issuerAndSerialNumber null, null, null, - {new Byte(DerValue.tag_Sequence)}, // extensionRequest - {new Byte(DerValue.tag_Sequence)}, // SMIMECapability - {new Byte(DerValue.tag_Sequence)}, // SigningCertificate - {new Byte(DerValue.tag_Sequence)} // SignatureTimestampToken + {DerValue.tag_Sequence}, // extensionRequest + {DerValue.tag_Sequence}, // SMIMECapability + {DerValue.tag_Sequence}, // SigningCertificate + {DerValue.tag_Sequence} // SignatureTimestampToken }; private static final Class[] VALUE_CLASSES = new Class[18]; @@ -511,7 +511,7 @@ public class PKCS9Attribute implements DerEncoder { // check for illegal element tags Byte tag; for (int i=0; i < elems.length; i++) { - tag = new Byte(elems[i].tag); + tag = elems[i].tag; if (indexOf(tag, PKCS9_VALUE_TAGS[index], 0) == -1) throwTagException(tag); diff --git a/jdk/src/share/classes/sun/security/x509/AVA.java b/jdk/src/share/classes/sun/security/x509/AVA.java index b07e565cfbd..fd3a3544592 100644 --- a/jdk/src/share/classes/sun/security/x509/AVA.java +++ b/jdk/src/share/classes/sun/security/x509/AVA.java @@ -517,7 +517,7 @@ public class AVA implements DerEncoder { if (hexDigits.indexOf(Character.toUpperCase((char)c2)) >= 0) { int hi = Character.digit((char)c1, 16); int lo = Character.digit((char)c2, 16); - return new Byte((byte)((hi<<4) + lo)); + return (byte)((hi<<4) + lo); } else { throw new IOException ("escaped hex value must include two valid digits"); diff --git a/jdk/src/share/classes/sun/tools/jconsole/inspector/Utils.java b/jdk/src/share/classes/sun/tools/jconsole/inspector/Utils.java index eb1f6b1be80..e706715fb0f 100644 --- a/jdk/src/share/classes/sun/tools/jconsole/inspector/Utils.java +++ b/jdk/src/share/classes/sun/tools/jconsole/inspector/Utils.java @@ -342,14 +342,14 @@ public class Utils { Object result; if (primitiveToWrapper.containsKey(type)) { if (type.equals(Character.TYPE.getName())) { - result = new Character(value.charAt(0)); + result = value.charAt(0); } else { result = newStringConstructor( ((Class) primitiveToWrapper.get(type)).getName(), value); } } else if (type.equals(Character.class.getName())) { - result = new Character(value.charAt(0)); + result = value.charAt(0); } else if (Number.class.isAssignableFrom(Utils.getClass(type))) { result = createNumberFromStringValue(value); } else if (value == null || value.equals("null")) { From 2edd214440a4d4186506ce8ffdffd12ebce7be25 Mon Sep 17 00:00:00 2001 From: Jamil Nimeh Date: Tue, 1 Jul 2014 09:46:20 -0700 Subject: [PATCH 30/30] 8015081: javax.security.auth.Subject.toString() throws NPE Reviewed-by: xuelei, weijun --- .../classes/javax/security/auth/Subject.java | 276 ++++-- .../javax/security/auth/Subject/Generic.java | 4 +- .../javax/security/auth/Subject/Serial.java | 4 +- .../javax/security/auth/Subject/Subject.java | 126 +++ .../auth/Subject/SubjectNullTests.java | 852 ++++++++++++++++++ 5 files changed, 1172 insertions(+), 90 deletions(-) create mode 100644 jdk/test/javax/security/auth/Subject/Subject.java create mode 100644 jdk/test/javax/security/auth/Subject/SubjectNullTests.java diff --git a/jdk/src/share/classes/javax/security/auth/Subject.java b/jdk/src/share/classes/javax/security/auth/Subject.java index 2c9e8b8083f..e8ce12c9eee 100644 --- a/jdk/src/share/classes/javax/security/auth/Subject.java +++ b/jdk/src/share/classes/javax/security/auth/Subject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -142,7 +142,9 @@ public final class Subject implements java.io.Serializable { *

    The newly constructed Sets check whether this {@code Subject} * has been set read-only before permitting subsequent modifications. * The newly created Sets also prevent illegal modifications - * by ensuring that callers have sufficient permissions. + * by ensuring that callers have sufficient permissions. These Sets + * also prohibit null elements, and attempts to add or query a null + * element will result in a {@code NullPointerException}. * *

    To modify the Principals Set, the caller must have * {@code AuthPermission("modifyPrincipals")}. @@ -170,7 +172,9 @@ public final class Subject implements java.io.Serializable { * These newly created Sets check whether this {@code Subject} * has been set read-only before permitting subsequent modifications. * The newly created Sets also prevent illegal modifications - * by ensuring that callers have sufficient permissions. + * by ensuring that callers have sufficient permissions. These Sets + * also prohibit null elements, and attempts to add or query a null + * element will result in a {@code NullPointerException}. * *

    To modify the Principals Set, the caller must have * {@code AuthPermission("modifyPrincipals")}. @@ -194,17 +198,16 @@ public final class Subject implements java.io.Serializable { * * @exception NullPointerException if the specified * {@code principals}, {@code pubCredentials}, - * or {@code privCredentials} are {@code null}. + * or {@code privCredentials} are {@code null}, + * or a null value exists within any of these three + * Sets. */ public Subject(boolean readOnly, Set principals, Set pubCredentials, Set privCredentials) { - - if (principals == null || - pubCredentials == null || - privCredentials == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.input.s.")); + collectionNullClean(principals); + collectionNullClean(pubCredentials); + collectionNullClean(privCredentials); this.principals = Collections.synchronizedSet(new SecureSet (this, PRINCIPAL_SET, principals)); @@ -287,18 +290,17 @@ public final class Subject implements java.io.Serializable { sm.checkPermission(AuthPermissionHolder.GET_SUBJECT_PERMISSION); } - if (acc == null) { - throw new NullPointerException(ResourcesMgr.getString + Objects.requireNonNull(acc, ResourcesMgr.getString ("invalid.null.AccessControlContext.provided")); - } // return the Subject from the DomainCombiner of the provided context return AccessController.doPrivileged (new java.security.PrivilegedAction() { public Subject run() { DomainCombiner dc = acc.getDomainCombiner(); - if (!(dc instanceof SubjectDomainCombiner)) + if (!(dc instanceof SubjectDomainCombiner)) { return null; + } SubjectDomainCombiner sdc = (SubjectDomainCombiner)dc; return sdc.getSubject(); } @@ -347,9 +349,9 @@ public final class Subject implements java.io.Serializable { if (sm != null) { sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION); } - if (action == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.action.provided")); + + Objects.requireNonNull(action, + ResourcesMgr.getString("invalid.null.action.provided")); // set up the new Subject-based AccessControlContext // for doPrivileged @@ -410,9 +412,8 @@ public final class Subject implements java.io.Serializable { sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION); } - if (action == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.action.provided")); + Objects.requireNonNull(action, + ResourcesMgr.getString("invalid.null.action.provided")); // set up the new Subject-based AccessControlContext for doPrivileged final AccessControlContext currentAcc = AccessController.getContext(); @@ -467,9 +468,8 @@ public final class Subject implements java.io.Serializable { sm.checkPermission(AuthPermissionHolder.DO_AS_PRIVILEGED_PERMISSION); } - if (action == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.action.provided")); + Objects.requireNonNull(action, + ResourcesMgr.getString("invalid.null.action.provided")); // set up the new Subject-based AccessControlContext // for doPrivileged @@ -534,9 +534,8 @@ public final class Subject implements java.io.Serializable { sm.checkPermission(AuthPermissionHolder.DO_AS_PRIVILEGED_PERMISSION); } - if (action == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.action.provided")); + Objects.requireNonNull(action, + ResourcesMgr.getString("invalid.null.action.provided")); // set up the new Subject-based AccessControlContext for doPrivileged final AccessControlContext callerAcc = @@ -557,13 +556,14 @@ public final class Subject implements java.io.Serializable { return java.security.AccessController.doPrivileged (new java.security.PrivilegedAction() { public AccessControlContext run() { - if (subject == null) + if (subject == null) { return new AccessControlContext(acc, null); - else + } else { return new AccessControlContext (acc, new SubjectDomainCombiner(subject)); } + } }); } @@ -615,9 +615,8 @@ public final class Subject implements java.io.Serializable { */ public Set getPrincipals(Class c) { - if (c == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.Class.provided")); + Objects.requireNonNull(c, + ResourcesMgr.getString("invalid.null.Class.provided")); // always return an empty Set instead of null // so LoginModules can add to the Set if necessary @@ -711,9 +710,8 @@ public final class Subject implements java.io.Serializable { */ public Set getPublicCredentials(Class c) { - if (c == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.Class.provided")); + Objects.requireNonNull(c, + ResourcesMgr.getString("invalid.null.Class.provided")); // always return an empty Set instead of null // so LoginModules can add to the Set if necessary @@ -758,9 +756,8 @@ public final class Subject implements java.io.Serializable { // would do is protect the set operations themselves // (like size()), which don't seem security-sensitive. - if (c == null) - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.Class.provided")); + Objects.requireNonNull(c, + ResourcesMgr.getString("invalid.null.Class.provided")); // always return an empty Set instead of null // so LoginModules can add to the Set if necessary @@ -790,11 +787,13 @@ public final class Subject implements java.io.Serializable { */ public boolean equals(Object o) { - if (o == null) + if (o == null) { return false; + } - if (this == o) + if (this == o) { return true; + } if (o instanceof Subject) { @@ -969,11 +968,10 @@ public final class Subject implements java.io.Serializable { Set inputPrincs = (Set)gf.get("principals", null); + Objects.requireNonNull(inputPrincs, + ResourcesMgr.getString("invalid.null.input.s.")); + // Rewrap the principals into a SecureSet - if (inputPrincs == null) { - throw new NullPointerException - (ResourcesMgr.getString("invalid.null.input.s.")); - } try { principals = Collections.synchronizedSet(new SecureSet (this, PRINCIPAL_SET, inputPrincs)); @@ -992,14 +990,44 @@ public final class Subject implements java.io.Serializable { (new SecureSet(this, PRIV_CREDENTIAL_SET)); } + /** + * Tests for null-clean collections (both non-null reference and + * no null elements) + * + * @param coll A {@code Collection} to be tested for null references + * + * @exception NullPointerException if the specified collection is either + * {@code null} or contains a {@code null} element + */ + private static void collectionNullClean(Collection coll) { + boolean hasNullElements = false; + + Objects.requireNonNull(coll, + ResourcesMgr.getString("invalid.null.input.s.")); + + try { + hasNullElements = coll.contains(null); + } catch (NullPointerException npe) { + // A null-hostile collection may choose to throw + // NullPointerException if contains(null) is called on it + // rather than returning false. + // If this happens we know the collection is null-clean. + hasNullElements = false; + } finally { + if (hasNullElements) { + throw new NullPointerException + (ResourcesMgr.getString("invalid.null.input.s.")); + } + } + } + /** * Prevent modifications unless caller has permission. * * @serial include */ private static class SecureSet - extends AbstractSet - implements java.io.Serializable { + implements Set, java.io.Serializable { private static final long serialVersionUID = 7911754171111800359L; @@ -1098,6 +1126,9 @@ public final class Subject implements java.io.Serializable { public boolean add(E o) { + Objects.requireNonNull(o, + ResourcesMgr.getString("invalid.null.input.s.")); + if (subject.isReadOnly()) { throw new IllegalStateException (ResourcesMgr.getString("Subject.is.read.only")); @@ -1133,12 +1164,16 @@ public final class Subject implements java.io.Serializable { // check for duplicates if (!elements.contains(o)) return elements.add(o); - else + else { return false; } + } public boolean remove(Object o) { + Objects.requireNonNull(o, + ResourcesMgr.getString("invalid.null.input.s.")); + final Iterator e = iterator(); while (e.hasNext()) { E next; @@ -1153,12 +1188,7 @@ public final class Subject implements java.io.Serializable { }); } - if (next == null) { - if (o == null) { - e.remove(); - return true; - } - } else if (next.equals(o)) { + if (next.equals(o)) { e.remove(); return true; } @@ -1167,6 +1197,10 @@ public final class Subject implements java.io.Serializable { } public boolean contains(Object o) { + + Objects.requireNonNull(o, + ResourcesMgr.getString("invalid.null.input.s.")); + final Iterator e = iterator(); while (e.hasNext()) { E next; @@ -1194,19 +1228,28 @@ public final class Subject implements java.io.Serializable { }); } - if (next == null) { - if (o == null) { - return true; - } - } else if (next.equals(o)) { + if (next.equals(o)) { return true; } } return false; } + public boolean addAll(Collection c) { + boolean result = false; + + collectionNullClean(c); + + for (E item : c) { + result |= this.add(item); + } + + return result; + } + public boolean removeAll(Collection c) { - Objects.requireNonNull(c); + collectionNullClean(c); + boolean modified = false; final Iterator e = iterator(); while (e.hasNext()) { @@ -1224,30 +1267,34 @@ public final class Subject implements java.io.Serializable { Iterator ce = c.iterator(); while (ce.hasNext()) { - Object o = ce.next(); - if (next == null) { - if (o == null) { + if (next.equals(ce.next())) { e.remove(); modified = true; break; } - } else if (next.equals(o)) { - e.remove(); - modified = true; - break; - } } } return modified; } + public boolean containsAll(Collection c) { + collectionNullClean(c); + + for (Object item : c) { + if (this.contains(item) == false) { + return false; + } + } + + return true; + } + public boolean retainAll(Collection c) { - Objects.requireNonNull(c); + collectionNullClean(c); + boolean modified = false; - boolean retain = false; final Iterator e = iterator(); while (e.hasNext()) { - retain = false; E next; if (which != Subject.PRIV_CREDENTIAL_SET) { next = e.next(); @@ -1260,26 +1307,12 @@ public final class Subject implements java.io.Serializable { }); } - Iterator ce = c.iterator(); - while (ce.hasNext()) { - Object o = ce.next(); - if (next == null) { - if (o == null) { - retain = true; - break; - } - } else if (next.equals(o)) { - retain = true; - break; + if (c.contains(next) == false) { + e.remove(); + modified = true; } } - if (!retain) { - e.remove(); - retain = false; - modified = true; - } - } return modified; } @@ -1301,6 +1334,73 @@ public final class Subject implements java.io.Serializable { } } + public boolean isEmpty() { + return elements.isEmpty(); + } + + public Object[] toArray() { + final Iterator e = iterator(); + while (e.hasNext()) { + // The next() method performs a security manager check + // on each element in the SecureSet. If we make it all + // the way through we should be able to simply return + // element's toArray results. Otherwise we'll let + // the SecurityException pass up the call stack. + e.next(); + } + + return elements.toArray(); + } + + public T[] toArray(T[] a) { + final Iterator e = iterator(); + while (e.hasNext()) { + // The next() method performs a security manager check + // on each element in the SecureSet. If we make it all + // the way through we should be able to simply return + // element's toArray results. Otherwise we'll let + // the SecurityException pass up the call stack. + e.next(); + } + + return elements.toArray(a); + } + + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (!(o instanceof Set)) { + return false; + } + + Collection c = (Collection) o; + if (c.size() != size()) { + return false; + } + + try { + return containsAll(c); + } catch (ClassCastException unused) { + return false; + } catch (NullPointerException unused) { + return false; + } + } + + public int hashCode() { + int h = 0; + Iterator i = iterator(); + while (i.hasNext()) { + E obj = i.next(); + if (obj != null) { + h += obj.hashCode(); + } + } + return h; + } + /** * Writes this object out to a stream (i.e., serializes it). * @@ -1338,12 +1438,16 @@ public final class Subject implements java.io.Serializable { which = fields.get("which", 0); LinkedList tmp = (LinkedList) fields.get("elements", null); + + Subject.collectionNullClean(tmp); + if (tmp.getClass() != LinkedList.class) { elements = new LinkedList(tmp); } else { elements = tmp; } } + } /** diff --git a/jdk/test/javax/security/auth/Subject/Generic.java b/jdk/test/javax/security/auth/Subject/Generic.java index 66bf5605649..1afba28f1fb 100644 --- a/jdk/test/javax/security/auth/Subject/Generic.java +++ b/jdk/test/javax/security/auth/Subject/Generic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -28,7 +28,7 @@ */ import java.security.*; -import javax.security.auth.*; +import javax.security.auth.Subject; public class Generic { public static void main(String[] args) throws Exception { diff --git a/jdk/test/javax/security/auth/Subject/Serial.java b/jdk/test/javax/security/auth/Subject/Serial.java index 3bdee14071f..f4fc860d37e 100644 --- a/jdk/test/javax/security/auth/Subject/Serial.java +++ b/jdk/test/javax/security/auth/Subject/Serial.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -29,7 +29,7 @@ * @run main/othervm/policy=Serial.policy Serial */ -import javax.security.auth.*; +import javax.security.auth.Subject; import java.io.*; import java.util.*; diff --git a/jdk/test/javax/security/auth/Subject/Subject.java b/jdk/test/javax/security/auth/Subject/Subject.java new file mode 100644 index 00000000000..422e94ae5ec --- /dev/null +++ b/jdk/test/javax/security/auth/Subject/Subject.java @@ -0,0 +1,126 @@ +/* + * 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. + */ + +/* + * An implementation of the Subject class that provides basic functionality + * for the construction of Subject objects with null Principal elements. + * This is a helper class for serialization tests tied to bug 8015081 + * (see SubjectNullTests.java). + */ +package jjjjj.security.auth; + +import sun.misc.HexDumpEncoder; +import javax.management.remote.JMXPrincipal; +import javax.security.auth.kerberos.KerberosPrincipal; +import javax.security.auth.x500.X500Principal; +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamField; +import java.lang.Exception; +import java.lang.RuntimeException; +import java.security.Principal; +import java.util.AbstractSet; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; + +import java.io.FileOutputStream; + +public class Subject implements java.io.Serializable { + + private static final long serialVersionUID = -8308522755600156056L; + + Set principals; + private volatile boolean readOnly = false; + private static final int PRINCIPAL_SET = 1; + + public Subject(Set principals) { + this.principals = Collections.synchronizedSet(new SecureSet + (this, PRINCIPAL_SET, principals)); + } + + public Set getPrincipals() { + return principals; + } + + private static class SecureSet + extends AbstractSet + implements java.io.Serializable { + + private static final long serialVersionUID = 7911754171111800359L; + private static final ObjectStreamField[] serialPersistentFields = { + new ObjectStreamField("this$0", Subject.class), + new ObjectStreamField("elements", LinkedList.class), + new ObjectStreamField("which", int.class) + }; + + Subject subject; + LinkedList elements; + private int which; + + SecureSet(Subject subject, int which, Set set) { + this.subject = subject; + this.which = which; + this.elements = new LinkedList(set); + } + + public Iterator iterator() { + return elements.iterator(); + } + + public int size() { + return elements.size(); + } + + private void writeObject(java.io.ObjectOutputStream oos) + throws java.io.IOException { + + ObjectOutputStream.PutField fields = oos.putFields(); + fields.put("this$0", subject); + fields.put("elements", elements); + fields.put("which", which); + oos.writeFields(); + } + } + + public static byte[] enc(Object obj) { + try { + HexDumpEncoder hex = new HexDumpEncoder(); + ByteArrayOutputStream bout; + bout = new ByteArrayOutputStream(); + new ObjectOutputStream(bout).writeObject(obj); + byte[] data = bout.toByteArray(); + for (int i = 0; i < data.length - 5; i++) { + if (data[i] == 'j' && data[i + 1] == 'j' && data[i + 2] == 'j' + && data[i + 3] == 'j' && data[i + 4] == 'j') { + System.arraycopy("javax".getBytes(), 0, data, i, 5); + } + } + return data; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/jdk/test/javax/security/auth/Subject/SubjectNullTests.java b/jdk/test/javax/security/auth/Subject/SubjectNullTests.java new file mode 100644 index 00000000000..c473ea8f30b --- /dev/null +++ b/jdk/test/javax/security/auth/Subject/SubjectNullTests.java @@ -0,0 +1,852 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8015081 + * @compile Subject.java + * @compile SubjectNullTests.java + * @build SubjectNullTests + * @run main SubjectNullTests + * @summary javax.security.auth.Subject.toString() throws NPE + */ + +import java.io.File; +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.ObjectInputStream; +import java.io.IOException; +import java.security.Principal; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import javax.management.remote.JMXPrincipal; +import javax.security.auth.Subject; +import javax.security.auth.x500.X500Principal; +import javax.security.auth.kerberos.KerberosPrincipal; + +public class SubjectNullTests { + + // Value templates for the constructor + private static Principal[] princVals = { + new X500Principal("CN=Tom Sawyer, ST=Missouri, C=US"), + new JMXPrincipal("Huckleberry Finn"), + new KerberosPrincipal("mtwain/author@LITERATURE.US") + }; + private static String[] pubVals = {"tsawyer", "hfinn", "mtwain"}; + private static String[] privVals = {"th3R!v3r", "oNth3R4ft", "5Cl3M3nz"}; + + // Templates for collection-based modifiers for the Subject + private static Principal[] tmplAddPrincs = { + new X500Principal("CN=John Doe, O=Bogus Corp."), + new KerberosPrincipal("jdoe/admin@BOGUSCORP.COM") + }; + private static String[] tmplAddPubVals = {"jdoe", "djoe"}; + private static String[] tmplAddPrvVals = {"b4dpa55w0rd", "pass123"}; + + /** + * Byte arrays used for deserialization: + * These byte arrays contain serialized Subjects and SecureSets, + * either with or without nulls. These use + * jjjjj.security.auth.Subject, which is a modified Subject + * implementation that allows the addition of null elements + */ + private static final byte[] SUBJ_NO_NULL = + jjjjj.security.auth.Subject.enc(makeSubjWithNull(false)); + private static final byte[] SUBJ_WITH_NULL = + jjjjj.security.auth.Subject.enc(makeSubjWithNull(true)); + private static final byte[] PRIN_NO_NULL = + jjjjj.security.auth.Subject.enc(makeSecSetWithNull(false)); + private static final byte[] PRIN_WITH_NULL = + jjjjj.security.auth.Subject.enc(makeSecSetWithNull(true)); + + /** + * Method to allow creation of a subject that can optionally + * insert a null reference into the principals Set. + */ + private static jjjjj.security.auth.Subject makeSubjWithNull( + boolean nullPrinc) { + Set setPrinc = new HashSet<>(Arrays.asList(princVals)); + if (nullPrinc) { + setPrinc.add(null); + } + + return (new jjjjj.security.auth.Subject(setPrinc)); + } + + /** + * Method to allow creation of a SecureSet that can optionally + * insert a null reference. + */ + private static Set makeSecSetWithNull(boolean nullPrinc) { + Set setPrinc = new HashSet<>(Arrays.asList(princVals)); + if (nullPrinc) { + setPrinc.add(null); + } + + jjjjj.security.auth.Subject subj = + new jjjjj.security.auth.Subject(setPrinc); + + return subj.getPrincipals(); + } + + /** + * Construct a subject, and optionally place a null in any one + * of the three Sets used to initialize a Subject's values + */ + private static Subject makeSubj(boolean nullPrinc, boolean nullPub, + boolean nullPriv) { + Set setPrinc = new HashSet<>(Arrays.asList(princVals)); + Set setPubCreds = new HashSet<>(Arrays.asList(pubVals)); + Set setPrvCreds = new HashSet<>(Arrays.asList(privVals)); + + if (nullPrinc) { + setPrinc.add(null); + } + + if (nullPub) { + setPubCreds.add(null); + } + + if (nullPriv) { + setPrvCreds.add(null); + } + + return (new Subject(false, setPrinc, setPubCreds, setPrvCreds)); + } + + /** + * Provide a simple interface for abstracting collection-on-collection + * functions + */ + public interface Function { + boolean execCollection(Set subjSet, Collection actorData); + } + + public static final Function methAdd = new Function() { + @SuppressWarnings("unchecked") + @Override + public boolean execCollection(Set subjSet, Collection actorData) { + return subjSet.addAll((Collection)actorData); + } + }; + + public static final Function methContains = new Function() { + @Override + public boolean execCollection(Set subjSet, Collection actorData) { + return subjSet.containsAll(actorData); + } + }; + + public static final Function methRemove = new Function() { + @Override + public boolean execCollection(Set subjSet, Collection actorData) { + return subjSet.removeAll(actorData); + } + }; + + public static final Function methRetain = new Function() { + @Override + public boolean execCollection(Set subjSet, Collection actorData) { + return subjSet.retainAll(actorData); + } + }; + + /** + * Run a test using a specified Collection method upon a Subject's + * SecureSet fields. This method expects NullPointerExceptions + * to be thrown, and throws RuntimeException when the operation + * succeeds + */ + private static void nullTestCollection(Function meth, Set subjSet, + Collection actorData) { + try { + meth.execCollection(subjSet, actorData); + throw new RuntimeException("Failed to throw NullPointerException"); + } catch (NullPointerException npe) { + System.out.println("Caught expected NullPointerException [PASS]"); + } + } + + /** + * Run a test using a specified Collection method upon a Subject's + * SecureSet fields. This method expects the function and arguments + * passed in to complete without exception. It returns false + * if either an exception occurs or the result of the operation is + * false. + */ + private static boolean validTestCollection(Function meth, Set subjSet, + Collection actorData) { + boolean result = false; + + try { + result = meth.execCollection(subjSet, actorData); + } catch (Exception exc) { + System.out.println("Caught exception " + exc); + } + + return result; + } + + /** + * Deserialize an object from a byte array. + * + * @param type The {@code Class} that the serialized file is supposed + * to contain. + * @param serBuffer The byte array containing the serialized object data + * + * @return An object of the type specified in the {@code type} parameter + */ + private static T deserializeBuffer(Class type, byte[] serBuffer) + throws IOException, ClassNotFoundException { + + ByteArrayInputStream bis = new ByteArrayInputStream(serBuffer); + ObjectInputStream ois = new ObjectInputStream(bis); + + T newObj = type.cast(ois.readObject()); + ois.close(); + bis.close(); + + return newObj; + } + + private static void testCTOR() { + System.out.println("------ constructor ------"); + + try { + // Case 1: Create a subject with a null principal + // Expected result: NullPointerException + Subject mtSubj = makeSubj(true, false, false); + throw new RuntimeException( + "constructor [principal w/ null]: Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println("constructor [principal w/ null]: " + + "NullPointerException [PASS]"); + } + + try { + // Case 2: Create a subject with a null public credential element + // Expected result: NullPointerException + Subject mtSubj = makeSubj(false, true, false); + throw new RuntimeException( + "constructor [pub cred w/ null]: Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println("constructor [pub cred w/ null]: " + + "NullPointerException [PASS]"); + } + + try { + // Case 3: Create a subject with a null private credential element + // Expected result: NullPointerException + Subject mtSubj = makeSubj(false, false, true); + throw new RuntimeException( + "constructor [priv cred w/ null]: Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println("constructor [priv cred w/ null]: " + + "NullPointerException [PASS]"); + } + + // Case 4: Create a new subject using the principals, public + // and private credentials from another well-formed subject + // Expected result: Successful construction + Subject srcSubj = makeSubj(false, false, false); + Subject mtSubj = new Subject(false, srcSubj.getPrincipals(), + srcSubj.getPublicCredentials(), + srcSubj.getPrivateCredentials()); + System.out.println("Construction from another well-formed Subject's " + + "principals/creds [PASS]"); + } + + @SuppressWarnings("unchecked") + private static void testDeserialize() throws Exception { + System.out.println("------ deserialize -----"); + + Subject subj = null; + Set prin = null; + + // Case 1: positive deserialization test of a Subject + // Expected result: well-formed Subject + subj = deserializeBuffer(Subject.class, SUBJ_NO_NULL); + System.out.println("Positive deserialization test (Subject) passed"); + + // Case 2: positive deserialization test of a SecureSet + // Expected result: well-formed Set + prin = deserializeBuffer(Set.class, PRIN_NO_NULL); + System.out.println("Positive deserialization test (SecureSet) passed"); + + System.out.println( + "* Testing deserialization with null-poisoned objects"); + // Case 3: deserialization test of a null-poisoned Subject + // Expected result: NullPointerException + try { + subj = deserializeBuffer(Subject.class, SUBJ_WITH_NULL); + throw new RuntimeException("Failed to throw NullPointerException"); + } catch (NullPointerException npe) { + System.out.println("Caught expected NullPointerException [PASS]"); + } + + // Case 4: deserialization test of a null-poisoned SecureSet + // Expected result: NullPointerException + try { + prin = deserializeBuffer(Set.class, PRIN_WITH_NULL); + throw new RuntimeException("Failed to throw NullPointerException"); + } catch (NullPointerException npe) { + System.out.println("Caught expected NullPointerException [PASS]"); + } + } + + private static void testAdd() { + System.out.println("------ add() ------"); + // Create a well formed subject + Subject mtSubj = makeSubj(false, false, false); + + try { + // Case 1: Attempt to add null values to principal + // Expected result: NullPointerException + mtSubj.getPrincipals().add(null); + throw new RuntimeException( + "PRINCIPAL add(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRINCIPAL add(null): NullPointerException [PASS]"); + } + + try { + // Case 2: Attempt to add null into the public creds + // Expected result: NullPointerException + mtSubj.getPublicCredentials().add(null); + throw new RuntimeException( + "PUB CRED add(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PUB CRED add(null): NullPointerException [PASS]"); + } + + try { + // Case 3: Attempt to add null into the private creds + // Expected result: NullPointerException + mtSubj.getPrivateCredentials().add(null); + throw new RuntimeException( + "PRIV CRED add(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRIV CRED add(null): NullPointerException [PASS]"); + } + } + + private static void testRemove() { + System.out.println("------ remove() ------"); + // Create a well formed subject + Subject mtSubj = makeSubj(false, false, false); + + try { + // Case 1: Attempt to remove null values from principal + // Expected result: NullPointerException + mtSubj.getPrincipals().remove(null); + throw new RuntimeException( + "PRINCIPAL remove(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRINCIPAL remove(null): NullPointerException [PASS]"); + } + + try { + // Case 2: Attempt to remove null from the public creds + // Expected result: NullPointerException + mtSubj.getPublicCredentials().remove(null); + throw new RuntimeException( + "PUB CRED remove(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PUB CRED remove(null): NullPointerException [PASS]"); + } + + try { + // Case 3: Attempt to remove null from the private creds + // Expected result: NullPointerException + mtSubj.getPrivateCredentials().remove(null); + throw new RuntimeException( + "PRIV CRED remove(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRIV CRED remove(null): NullPointerException [PASS]"); + } + } + + private static void testContains() { + System.out.println("------ contains() ------"); + // Create a well formed subject + Subject mtSubj = makeSubj(false, false, false); + + try { + // Case 1: Attempt to check for null values in principals + // Expected result: NullPointerException + mtSubj.getPrincipals().contains(null); + throw new RuntimeException( + "PRINCIPAL contains(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRINCIPAL contains(null): NullPointerException [PASS]"); + } + + try { + // Case 2: Attempt to check for null in public creds + // Expected result: NullPointerException + mtSubj.getPublicCredentials().contains(null); + throw new RuntimeException( + "PUB CRED contains(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PUB CRED contains(null): NullPointerException [PASS]"); + } + + try { + // Case 3: Attempt to check for null in private creds + // Expected result: NullPointerException + mtSubj.getPrivateCredentials().contains(null); + throw new RuntimeException( + "PRIV CRED contains(null): Failed to throw NPE"); + } catch (NullPointerException npe) { + System.out.println( + "PRIV CRED contains(null): NullPointerException [PASS]"); + } + } + + private static void testAddAll() { + // Create a well formed subject and additional collections + Subject mtSubj = makeSubj(false, false, false); + Set morePrincs = new HashSet<>(Arrays.asList(tmplAddPrincs)); + Set morePubVals = new HashSet<>(Arrays.asList(tmplAddPubVals)); + Set morePrvVals = new HashSet<>(Arrays.asList(tmplAddPrvVals)); + + // Run one success test for each Subject family to verify the + // overloaded method works as intended. + Set setPrin = mtSubj.getPrincipals(); + Set setPubCreds = mtSubj.getPublicCredentials(); + Set setPrvCreds = mtSubj.getPrivateCredentials(); + int prinOrigSize = setPrin.size(); + int pubOrigSize = setPubCreds.size(); + int prvOrigSize = setPrvCreds.size(); + + System.out.println("------ addAll() -----"); + + // Add the new members, then check the resulting size of the + // Subject attributes to verify they've increased by the proper + // amounts. + if ((validTestCollection(methAdd, setPrin, morePrincs) != true) || + (setPrin.size() != prinOrigSize + morePrincs.size())) + { + throw new RuntimeException("Failed addAll() on principals"); + } + if ((validTestCollection(methAdd, setPubCreds, + morePubVals) != true) || + (setPubCreds.size() != pubOrigSize + morePubVals.size())) + { + throw new RuntimeException("Failed addAll() on public creds"); + } + if ((validTestCollection(methAdd, setPrvCreds, + morePrvVals) != true) || + (setPrvCreds.size() != prvOrigSize + morePrvVals.size())) + { + throw new RuntimeException("Failed addAll() on private creds"); + } + System.out.println("Positive addAll() test passed"); + + // Now add null elements into each container, then retest + morePrincs.add(null); + morePubVals.add(null); + morePrvVals.add(null); + + System.out.println("* Testing addAll w/ null values on Principals"); + nullTestCollection(methAdd, mtSubj.getPrincipals(), null); + nullTestCollection(methAdd, mtSubj.getPrincipals(), morePrincs); + + System.out.println("* Testing addAll w/ null values on Public Creds"); + nullTestCollection(methAdd, mtSubj.getPublicCredentials(), null); + nullTestCollection(methAdd, mtSubj.getPublicCredentials(), + morePubVals); + + System.out.println("* Testing addAll w/ null values on Private Creds"); + nullTestCollection(methAdd, mtSubj.getPrivateCredentials(), null); + nullTestCollection(methAdd, mtSubj.getPrivateCredentials(), + morePrvVals); + } + + private static void testRemoveAll() { + // Create a well formed subject and additional collections + Subject mtSubj = makeSubj(false, false, false); + Set remPrincs = new HashSet<>(); + Set remPubVals = new HashSet<>(); + Set remPrvVals = new HashSet<>(); + + remPrincs.add(new KerberosPrincipal("mtwain/author@LITERATURE.US")); + remPubVals.add("mtwain"); + remPrvVals.add("5Cl3M3nz"); + + // Run one success test for each Subject family to verify the + // overloaded method works as intended. + Set setPrin = mtSubj.getPrincipals(); + Set setPubCreds = mtSubj.getPublicCredentials(); + Set setPrvCreds = mtSubj.getPrivateCredentials(); + int prinOrigSize = setPrin.size(); + int pubOrigSize = setPubCreds.size(); + int prvOrigSize = setPrvCreds.size(); + + System.out.println("------ removeAll() -----"); + + // Remove the specified members, then check the resulting size of the + // Subject attributes to verify they've decreased by the proper + // amounts. + if ((validTestCollection(methRemove, setPrin, remPrincs) != true) || + (setPrin.size() != prinOrigSize - remPrincs.size())) + { + throw new RuntimeException("Failed removeAll() on principals"); + } + if ((validTestCollection(methRemove, setPubCreds, + remPubVals) != true) || + (setPubCreds.size() != pubOrigSize - remPubVals.size())) + { + throw new RuntimeException("Failed removeAll() on public creds"); + } + if ((validTestCollection(methRemove, setPrvCreds, + remPrvVals) != true) || + (setPrvCreds.size() != prvOrigSize - remPrvVals.size())) + { + throw new RuntimeException("Failed removeAll() on private creds"); + } + System.out.println("Positive removeAll() test passed"); + + // Now add null elements into each container, then retest + remPrincs.add(null); + remPubVals.add(null); + remPrvVals.add(null); + + System.out.println("* Testing removeAll w/ null values on Principals"); + nullTestCollection(methRemove, mtSubj.getPrincipals(), null); + nullTestCollection(methRemove, mtSubj.getPrincipals(), remPrincs); + + System.out.println( + "* Testing removeAll w/ null values on Public Creds"); + nullTestCollection(methRemove, mtSubj.getPublicCredentials(), null); + nullTestCollection(methRemove, mtSubj.getPublicCredentials(), + remPubVals); + + System.out.println( + "* Testing removeAll w/ null values on Private Creds"); + nullTestCollection(methRemove, mtSubj.getPrivateCredentials(), null); + nullTestCollection(methRemove, mtSubj.getPrivateCredentials(), + remPrvVals); + } + + private static void testContainsAll() { + // Create a well formed subject and additional collections + Subject mtSubj = makeSubj(false, false, false); + Set testPrincs = new HashSet<>(Arrays.asList(princVals)); + Set testPubVals = new HashSet<>(Arrays.asList(pubVals)); + Set testPrvVals = new HashSet<>(Arrays.asList(privVals)); + + System.out.println("------ containsAll() -----"); + + // Run one success test for each Subject family to verify the + // overloaded method works as intended. + if ((validTestCollection(methContains, mtSubj.getPrincipals(), + testPrincs) == false) && + (validTestCollection(methContains, mtSubj.getPublicCredentials(), + testPubVals) == false) && + (validTestCollection(methContains, + mtSubj.getPrivateCredentials(), testPrvVals) == false)) { + throw new RuntimeException("Valid containsAll() check failed"); + } + System.out.println("Positive containsAll() test passed"); + + // Now let's add a null into each collection and watch the fireworks. + testPrincs.add(null); + testPubVals.add(null); + testPrvVals.add(null); + + System.out.println( + "* Testing containsAll w/ null values on Principals"); + nullTestCollection(methContains, mtSubj.getPrincipals(), null); + nullTestCollection(methContains, mtSubj.getPrincipals(), testPrincs); + + System.out.println( + "* Testing containsAll w/ null values on Public Creds"); + nullTestCollection(methContains, mtSubj.getPublicCredentials(), + null); + nullTestCollection(methContains, mtSubj.getPublicCredentials(), + testPubVals); + + System.out.println( + "* Testing containsAll w/ null values on Private Creds"); + nullTestCollection(methContains, mtSubj.getPrivateCredentials(), + null); + nullTestCollection(methContains, mtSubj.getPrivateCredentials(), + testPrvVals); + } + + private static void testRetainAll() { + // Create a well formed subject and additional collections + Subject mtSubj = makeSubj(false, false, false); + Set remPrincs = new HashSet<>(Arrays.asList(tmplAddPrincs)); + Set remPubVals = new HashSet<>(Arrays.asList(tmplAddPubVals)); + Set remPrvVals = new HashSet<>(Arrays.asList(tmplAddPrvVals)); + + // Add in values that exist within the Subject + remPrincs.add(princVals[2]); + remPubVals.add(pubVals[2]); + remPrvVals.add(privVals[2]); + + // Run one success test for each Subject family to verify the + // overloaded method works as intended. + Set setPrin = mtSubj.getPrincipals(); + Set setPubCreds = mtSubj.getPublicCredentials(); + Set setPrvCreds = mtSubj.getPrivateCredentials(); + int prinOrigSize = setPrin.size(); + int pubOrigSize = setPubCreds.size(); + int prvOrigSize = setPrvCreds.size(); + + System.out.println("------ retainAll() -----"); + + // Retain the specified members (those that exist in the Subject) + // and validate the results. + if (validTestCollection(methRetain, setPrin, remPrincs) == false || + setPrin.size() != 1 || setPrin.contains(princVals[2]) == false) + { + throw new RuntimeException("Failed retainAll() on principals"); + } + + if (validTestCollection(methRetain, setPubCreds, + remPubVals) == false || + setPubCreds.size() != 1 || + setPubCreds.contains(pubVals[2]) == false) + { + throw new RuntimeException("Failed retainAll() on public creds"); + } + if (validTestCollection(methRetain, setPrvCreds, + remPrvVals) == false || + setPrvCreds.size() != 1 || + setPrvCreds.contains(privVals[2]) == false) + { + throw new RuntimeException("Failed retainAll() on private creds"); + } + System.out.println("Positive retainAll() test passed"); + + // Now add null elements into each container, then retest + remPrincs.add(null); + remPubVals.add(null); + remPrvVals.add(null); + + System.out.println("* Testing retainAll w/ null values on Principals"); + nullTestCollection(methRetain, mtSubj.getPrincipals(), null); + nullTestCollection(methRetain, mtSubj.getPrincipals(), remPrincs); + + System.out.println( + "* Testing retainAll w/ null values on Public Creds"); + nullTestCollection(methRetain, mtSubj.getPublicCredentials(), null); + nullTestCollection(methRetain, mtSubj.getPublicCredentials(), + remPubVals); + + System.out.println( + "* Testing retainAll w/ null values on Private Creds"); + nullTestCollection(methRetain, mtSubj.getPrivateCredentials(), null); + nullTestCollection(methRetain, mtSubj.getPrivateCredentials(), + remPrvVals); + } + + private static void testIsEmpty() { + Subject populatedSubj = makeSubj(false, false, false); + Subject emptySubj = new Subject(); + + System.out.println("------ isEmpty() -----"); + + if (populatedSubj.getPrincipals().isEmpty()) { + throw new RuntimeException( + "Populated Subject Principals incorrectly returned empty"); + } + if (emptySubj.getPrincipals().isEmpty() == false) { + throw new RuntimeException( + "Empty Subject Principals incorrectly returned non-empty"); + } + System.out.println("isEmpty() test passed"); + } + + private static void testSecureSetEquals() { + System.out.println("------ SecureSet.equals() -----"); + + Subject subj = makeSubj(false, false, false); + Subject subjComp = makeSubj(false, false, false); + + // Case 1: null comparison [expect false] + if (subj.getPublicCredentials().equals(null) != false) { + throw new RuntimeException( + "equals(null) incorrectly returned true"); + } + + // Case 2: Self-comparison [expect true] + Set princs = subj.getPrincipals(); + princs.equals(subj.getPrincipals()); + + // Case 3: Comparison with non-Set type [expect false] + List listPrinc = new LinkedList<>(Arrays.asList(princVals)); + if (subj.getPublicCredentials().equals(listPrinc) != false) { + throw new RuntimeException( + "equals([Non-Set]) incorrectly returned true"); + } + + // Case 4: SecureSets of differing sizes [expect false] + Subject subj1princ = new Subject(); + Subject subj2princ = new Subject(); + subj1princ.getPrincipals().add( + new X500Principal("CN=Tom Sawyer, ST=Missouri, C=US")); + subj1princ.getPrincipals().add( + new X500Principal("CN=John Doe, O=Bogus Corp.")); + subj2princ.getPrincipals().add( + new X500Principal("CN=Tom Sawyer, ST=Missouri, C=US")); + if (subj1princ.getPrincipals().equals( + subj2princ.getPrincipals()) != false) { + throw new RuntimeException( + "equals([differing sizes]) incorrectly returned true"); + } + + // Case 5: Content equality test [expect true] + Set equalSet = new HashSet<>(Arrays.asList(princVals)); + if (subj.getPrincipals().equals(equalSet) != true) { + throw new RuntimeException( + "equals([equivalent set]) incorrectly returned false"); + } + + // Case 5: Content inequality test [expect false] + // Note: to not fall into the size inequality check the two + // sets need to have the same number of elements. + Set inequalSet = + new HashSet(Arrays.asList(tmplAddPrincs)); + inequalSet.add(new JMXPrincipal("Samuel Clemens")); + + if (subj.getPrincipals().equals(inequalSet) != false) { + throw new RuntimeException( + "equals([equivalent set]) incorrectly returned false"); + } + System.out.println("SecureSet.equals() tests passed"); + } + + private static void testSecureSetHashCode() { + System.out.println("------ SecureSet.hashCode() -----"); + + Subject subj = makeSubj(false, false, false); + + // Make sure two other Set types that we know are equal per + // SecureSet.equals() and verify their hashCodes are also the same + Set equalHashSet = new HashSet<>(Arrays.asList(princVals)); + + if (subj.getPrincipals().hashCode() != equalHashSet.hashCode()) { + throw new RuntimeException( + "SecureSet and HashSet hashCodes() differ"); + } + System.out.println("SecureSet.hashCode() tests passed"); + } + + private static void testToArray() { + System.out.println("------ toArray() -----"); + + Subject subj = makeSubj(false, false, false); + + // Case 1: no-parameter toArray with equality comparison + // Expected result: true + List alSubj = Arrays.asList(subj.getPrincipals().toArray()); + List alPrincs = Arrays.asList(princVals); + + if (alSubj.size() != alPrincs.size() || + alSubj.containsAll(alPrincs) != true) { + throw new RuntimeException( + "Unexpected inequality on returned toArray()"); + } + + // Case 2: generic-type toArray where passed array is of sufficient + // size. + // Expected result: returned Array is reference-equal to input param + // and content equal to data used to construct the originating Subject. + Principal[] pBlock = new Principal[3]; + Principal[] pBlockRef = subj.getPrincipals().toArray(pBlock); + alSubj = Arrays.asList((Object[])pBlockRef); + + if (pBlockRef != pBlock) { + throw new RuntimeException( + "Unexpected reference-inequality on returned toArray(T[])"); + } else if (alSubj.size() != alPrincs.size() || + alSubj.containsAll(alPrincs) != true) { + throw new RuntimeException( + "Unexpected content-inequality on returned toArray(T[])"); + } + + // Case 3: generic-type toArray where passed array is of + // insufficient size. + // Expected result: returned Array is not reference-equal to + // input param but is content equal to data used to construct the + // originating Subject. + pBlock = new Principal[1]; + pBlockRef = subj.getPrincipals().toArray(pBlock); + alSubj = Arrays.asList((Object[])pBlockRef); + + if (pBlockRef == pBlock) { + throw new RuntimeException( + "Unexpected reference-equality on returned toArray(T[])"); + } else if (alSubj.size() != alPrincs.size() || + alSubj.containsAll(alPrincs) != true) { + throw new RuntimeException( + "Unexpected content-inequality on returned toArray(T[])"); + } + System.out.println("toArray() tests passed"); + } + + public static void main(String[] args) throws Exception { + + testCTOR(); + + testDeserialize(); + + testAdd(); + + testRemove(); + + testContains(); + + testAddAll(); + + testRemoveAll(); + + testContainsAll(); + + testRetainAll(); + + testIsEmpty(); + + testSecureSetEquals(); + + testSecureSetHashCode(); + + testToArray(); + } +}