diff --git a/.hgtags b/.hgtags index 4d0ba62cd995bce1f23d40e979cdae7f628554a4..7b1dd87bd4e2c765287fa10840cd7bfe846b3e9e 100644 --- a/.hgtags +++ b/.hgtags @@ -175,3 +175,4 @@ e4bae5c53fca8fcb9393d47fd36a34b9e2e8d4ec jdk8-b50 e865efbc71059a414b3b2dd2e0adfcb3d2ab6ff9 jdk8-b51 e8569a473cee7f4955bd9e76a9bdf6c6a07ced27 jdk8-b52 2c6933c5106b81a8578b70996fe5b735fb3adb60 jdk8-b53 +70ad0ed1d6cef0e7712690d1bab21e4769708aad jdk8-b54 diff --git a/make/common/Program.gmk b/make/common/Program.gmk index 0ad45e5331ebce74170cf0348f94dcc0dfac624a..5a2e7464c73fbf15c181b2a5a231d1ed0f282f44 100644 --- a/make/common/Program.gmk +++ b/make/common/Program.gmk @@ -125,6 +125,26 @@ ifeq ($(PLATFORM), windows) OTHER_LDLIBS += jli.lib endif +# +# Applications expect to be able to link against libjawt without invoking +# System.loadLibrary("jawt") first. This was the behaviour described in the +# devloper documentation of JAWT and what worked with OpenJDK6. +# +ifeq ($(PLATFORM), solaris) + ifeq ($(ARCH_DATA_MODEL), 32) + LDFLAGS += -R \$$ORIGIN/../lib/$(LIBARCH) + LDFLAGS += -R \$$ORIGIN/../jre/lib/$(LIBARCH) + else # ! ARCH_DATA_MODEL 64-bit + LDFLAGS += -R \$$ORIGIN/../../lib/$(LIBARCH) + LDFLAGS += -R \$$ORIGIN/../../jre/lib/$(LIBARCH) + endif # ARCH_DATA_MODEL +endif # PLATFORM SOLARIS +ifeq ($(PLATFORM), linux) + LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../lib/$(LIBARCH) + LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/../jre/lib/$(LIBARCH) +endif # PLATFORM LINUX + + # # Launcher specific files. # diff --git a/make/docs/Makefile b/make/docs/Makefile index fcb461ae8c0a6958a0d898868bfbe22e72cbb7dc..e181b66a4ed1f5a56c8f2c1084943e10c9a21ea6 100644 --- a/make/docs/Makefile +++ b/make/docs/Makefile @@ -73,7 +73,7 @@ ifeq ($(ARCH_DATA_MODEL),64) else ifeq ($(ARCH),universal) MAX_VM_MEMORY = 1024 else - MAX_VM_MEMORY = 612 + MAX_VM_MEMORY = 768 endif # List of all possible directories for javadoc to look for sources diff --git a/make/sun/Makefile b/make/sun/Makefile index 7f53c2a19428713a6da93964558ca0db575a1a9c..56b484fc19f4c1010c5fe8b96561bbaedbe01f85 100644 --- a/make/sun/Makefile +++ b/make/sun/Makefile @@ -87,7 +87,7 @@ else endif SUBDIRS_desktop = audio $(RENDER_SUBDIR) image \ $(LWAWT_PRE_SUBDIR) $(DISPLAY_LIBS) $(DGA_SUBDIR) $(LWAWT_SUBDIR) \ - jawt font jpeg cmm $(DISPLAY_TOOLS) beans + jawt font jpeg cmm $(DISPLAY_TOOLS) SUBDIRS_management = management SUBDIRS_misc = $(ORG_SUBDIR) rmi $(JDBC_SUBDIR) tracing SUBDIRS_tools = native2ascii serialver tools jconsole diff --git a/make/sun/beans/Makefile b/make/sun/beans/Makefile deleted file mode 100644 index b525eb4fa2448c6fdf31a53eaa5b019656d9ac79..0000000000000000000000000000000000000000 --- a/make/sun/beans/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (c) 1997, 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. 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. -# - -# -# Makefile for building sun.beans.* -# - -BUILDDIR = ../.. -PACKAGE = sun.beans -PRODUCT = sun -include $(BUILDDIR)/common/Defs.gmk - -# -# Files -# -AUTO_FILES_JAVA_DIRS = sun/beans - -# -# Rules -# -include $(BUILDDIR)/common/Classes.gmk diff --git a/make/sun/jawt/Makefile b/make/sun/jawt/Makefile index 28cb54ea08306f453f947c7efff6c155aedf86c9..a9d712b2dbfcd87ab2bb6713c886f46f70afe2cf 100644 --- a/make/sun/jawt/Makefile +++ b/make/sun/jawt/Makefile @@ -30,6 +30,13 @@ PRODUCT = sun include $(BUILDDIR)/common/Defs.gmk +# +# libjawt links to other programs, but nothing links to it directly. An RPATH +# entry has been added to the launcher so third-party programs linked against +# it will be able to find it no matter where the JDK or the third-party program +# is located. +# + # # Files # diff --git a/src/macosx/classes/com/apple/laf/ScreenMenuItem.java b/src/macosx/classes/com/apple/laf/ScreenMenuItem.java index 49e4997865de379c108cb3ad22c03fb2a3ad9ef2..6852ea00a801d3a188409500e285eaaac7faaeb2 100644 --- a/src/macosx/classes/com/apple/laf/ScreenMenuItem.java +++ b/src/macosx/classes/com/apple/laf/ScreenMenuItem.java @@ -34,7 +34,7 @@ import javax.swing.plaf.ComponentUI; import sun.lwawt.macosx.CMenuItem; -class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler { +final class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler { ScreenMenuPropertyListener fListener; JMenuItem fMenuItem; @@ -96,21 +96,31 @@ class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListen fMenuItem.removeComponentListener(this); } - public void setAccelerator(final KeyStroke ks) { - if (ks == null) { - setShortcut(null); + static void syncLabelAndKS(MenuItem menuItem, String label, KeyStroke ks) { + final MenuComponentPeer peer = menuItem.getPeer(); + if (!(peer instanceof CMenuItem)) { + //Is it possible? return; } - - final MenuComponentPeer peer = getPeer(); - if (peer instanceof CMenuItem) { - final CMenuItem ourPeer = (CMenuItem)peer; - ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers()); + final CMenuItem cmi = (CMenuItem) peer; + if (ks == null) { + cmi.setLabel(label); } else { - setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0)); + cmi.setLabel(label, ks.getKeyChar(), ks.getKeyCode(), + ks.getModifiers()); } } + @Override + public synchronized void setLabel(final String label) { + syncLabelAndKS(this, label, fMenuItem.getAccelerator()); + } + + @Override + public void setAccelerator(final KeyStroke ks) { + syncLabelAndKS(this, fMenuItem.getText(), ks); + } + public void actionPerformed(final ActionEvent e) { fMenuItem.doClick(0); // This takes care of all the different events } diff --git a/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java b/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java index 15f314e14b2561c2c424dfc83cdffbb91498cf5c..644eaccc79da5a83459ee5dd471c44e9fc4eb3de 100644 --- a/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java +++ b/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java @@ -36,7 +36,7 @@ import com.apple.laf.AquaMenuItemUI.IndeterminateListener; import sun.lwawt.macosx.*; -class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener { +final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener { JMenuItem fMenuItem; MenuContainer fParent; @@ -110,19 +110,14 @@ class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, super.removeNotify(); } - public void setAccelerator(final KeyStroke ks) { - if (ks == null) { - setShortcut(null); - return; - } + @Override + public synchronized void setLabel(final String label) { + ScreenMenuItem.syncLabelAndKS(this, label, fMenuItem.getAccelerator()); + } - final MenuComponentPeer peer = getPeer(); - if (peer instanceof CMenuItem) { - final CMenuItem ourPeer = (CMenuItem)peer; - ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers()); - } else { - setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0)); - } + @Override + public void setAccelerator(final KeyStroke ks) { + ScreenMenuItem.syncLabelAndKS(this, fMenuItem.getText(), ks); } public void actionPerformed(final ActionEvent e) { diff --git a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java index b03527de9c1091060899cbacfafc6237e014e6bb..8c36ddc6614c16acfa9be8acb5786c1ef4526b09 100644 --- a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java +++ b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java @@ -31,8 +31,12 @@ import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.ImageCapabilities; +import java.awt.Rectangle; import java.awt.Transparency; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; @@ -44,6 +48,7 @@ import java.awt.image.WritableRaster; import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsDevice; +import sun.awt.TextureSizeConstraining; import sun.awt.image.OffScreenImage; import sun.awt.image.SunVolatileImage; import sun.awt.image.SurfaceManager; @@ -65,7 +70,7 @@ import sun.java2d.pipe.hw.AccelDeviceEventNotifier; import sun.lwawt.macosx.CPlatformView; public class CGLGraphicsConfig extends CGraphicsConfig - implements OGLGraphicsConfig + implements OGLGraphicsConfig, TextureSizeConstraining { //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; private static final int kOpenGLSwapInterval = 0; // TODO @@ -242,6 +247,8 @@ public class CGLGraphicsConfig extends CGraphicsConfig } finally { rq.unlock(); } + + updateTotalDisplayBounds(); } @Override @@ -478,4 +485,50 @@ public class CGLGraphicsConfig extends CGraphicsConfig public void removeDeviceEventListener(AccelDeviceEventListener l) { AccelDeviceEventNotifier.removeListener(l); } + + private static final Rectangle totalDisplayBounds = new Rectangle(); + + private static void updateTotalDisplayBounds() { + synchronized (totalDisplayBounds) { + Rectangle virtualBounds = new Rectangle(); + for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { + for (GraphicsConfiguration gc : gd.getConfigurations()) { + virtualBounds = virtualBounds.union(gc.getBounds()); + } + } + totalDisplayBounds.setBounds(virtualBounds); + } + } + + // 7160609: GL still fails to create a square texture of this size, + // so we use this value to cap the total display bounds. + native private static int getMaxTextureSize(); + + @Override + public int getMaxTextureWidth() { + int width; + + synchronized (totalDisplayBounds) { + if (totalDisplayBounds.width == 0) { + updateTotalDisplayBounds(); + } + width = totalDisplayBounds.width; + } + + return Math.min(width, getMaxTextureSize()); + } + + @Override + public int getMaxTextureHeight() { + int height; + + synchronized (totalDisplayBounds) { + if (totalDisplayBounds.height == 0) { + updateTotalDisplayBounds(); + } + height = totalDisplayBounds.height; + } + + return Math.min(height, getMaxTextureSize()); + } } diff --git a/src/macosx/classes/sun/lwawt/LWComponentPeer.java b/src/macosx/classes/sun/lwawt/LWComponentPeer.java index f6ad8838051c3324b7ac0a1ecfe542511b47ce7a..76d8161c749c1464eeed510d01c7beee8bc9860c 100644 --- a/src/macosx/classes/sun/lwawt/LWComponentPeer.java +++ b/src/macosx/classes/sun/lwawt/LWComponentPeer.java @@ -282,7 +282,7 @@ public abstract class LWComponentPeer * Note that we call setVisible() at the end of initialization. */ public final void initialize() { - platformComponent.initialize(target, this, getPlatformWindow()); + platformComponent.initialize(getPlatformWindow()); initializeImpl(); setVisible(target.isVisible()); } diff --git a/src/macosx/classes/sun/lwawt/LWWindowPeer.java b/src/macosx/classes/sun/lwawt/LWWindowPeer.java index dd20e87139a4b729afdf60fd8d79a35fc86b1188..3b7cb79728c47e1383d39945e689258e2212c7c8 100644 --- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java +++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java @@ -338,6 +338,18 @@ public class LWWindowPeer h = MINIMUM_HEIGHT; } + if (graphicsConfig instanceof TextureSizeConstraining) { + final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth(); + final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight(); + + if (w > maxW) { + w = maxW; + } + if (h > maxH) { + h = maxH; + } + } + // Don't post ComponentMoved/Resized and Paint events // until we've got a notification from the delegate setBounds(x, y, w, h, op, false, false); @@ -405,14 +417,33 @@ public class LWWindowPeer @Override public void updateMinimumSize() { - Dimension d = null; + final Dimension min; if (getTarget().isMinimumSizeSet()) { - d = getTarget().getMinimumSize(); + min = getTarget().getMinimumSize(); + min.width = Math.max(min.width, MINIMUM_WIDTH); + min.height = Math.max(min.height, MINIMUM_HEIGHT); + } else { + min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT); } - if (d == null) { - d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT); + + final int maxW, maxH; + if (graphicsConfig instanceof TextureSizeConstraining) { + maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth(); + maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight(); + } else { + maxW = maxH = Integer.MAX_VALUE; + } + + final Dimension max; + if (getTarget().isMaximumSizeSet()) { + max = getTarget().getMaximumSize(); + max.width = Math.min(max.width, maxW); + max.height = Math.min(max.height, maxH); + } else { + max = new Dimension(maxW, maxH); } - platformWindow.setMinimumSize(d.width, d.height); + + platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height); } @Override diff --git a/src/macosx/classes/sun/lwawt/PlatformComponent.java b/src/macosx/classes/sun/lwawt/PlatformComponent.java index e791e0d57b06903255421212c9dde7d0ed987d49..836a19cd3f0b22a7d66745bd749ab9e208f2bf0a 100644 --- a/src/macosx/classes/sun/lwawt/PlatformComponent.java +++ b/src/macosx/classes/sun/lwawt/PlatformComponent.java @@ -23,15 +23,38 @@ * questions. */ -package sun.lwawt; -import java.awt.Component; +package sun.lwawt; +/** + * Can be used to store information about native resource related to the + * lightweight component. + */ public interface PlatformComponent { - public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow); + /** + * Initializes platform component. + * + * @param platformWindow already initialized {@code PlatformWindow}. + */ + void initialize(PlatformWindow platformWindow); - public void setBounds(int x, int y, int w, int h); + /** + * Moves and resizes this component. The new location of the top-left corner + * is specified by {@code x} and {@code y}, and the new size is specified by + * {@code w} and {@code h}. The location is specified relative to the {@code + * platformWindow}. + * + * @param x the X location of the component + * @param y the Y location of the component + * @param w the width of the component + * @param h the height of the component + */ + void setBounds(int x, int y, int w, int h); - public void dispose(); + /** + * Releases all of the native resources used by this {@code + * PlatformComponent}. + */ + void dispose(); } diff --git a/src/macosx/classes/sun/lwawt/PlatformWindow.java b/src/macosx/classes/sun/lwawt/PlatformWindow.java index 92608b8b2c0a6ea9fcc48c426ffccc5a35f4bc0e..2c7df7c3308cd5333ede115dda1b6db82a094ba1 100644 --- a/src/macosx/classes/sun/lwawt/PlatformWindow.java +++ b/src/macosx/classes/sun/lwawt/PlatformWindow.java @@ -131,7 +131,10 @@ public interface PlatformWindow { public void setResizable(boolean resizable); - public void setMinimumSize(int width, int height); + /** + * Applies the minimum and maximum size to the platform window. + */ + public void setSizeConstraints(int minW, int minH, int maxW, int maxH); /** * Transforms the given Graphics object according to the native diff --git a/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java b/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java index 5ff47d63cd2d4817bfab76fd8ca14ef0ea00b23b..a92545e213b9852acb158c8dd1a51c44f81075b7 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java +++ b/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java @@ -33,8 +33,8 @@ package sun.lwawt.macosx; public class CFRetainedResource { private static native void nativeCFRelease(final long ptr, final boolean disposeOnAppKitThread); - final boolean disposeOnAppKitThread; - protected long ptr; + private final boolean disposeOnAppKitThread; + protected volatile long ptr; /** * @param ptr CFRetained native object pointer diff --git a/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java b/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java index b905f0bcc932d53a9a192c505666b05c7fd2f29b..359f606636409720b563612b4a81b73afdf21317 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java +++ b/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java @@ -30,12 +30,14 @@ import java.awt.peer.*; import java.awt.BufferCapabilities.FlipContents; import java.awt.event.*; import java.awt.image.*; +import java.security.AccessController; import java.util.List; import java.io.*; import sun.awt.CausedFocusEvent.Cause; import sun.awt.AWTAccessor; import sun.java2d.pipe.Region; +import sun.security.action.GetBooleanAction; class CFileDialog implements FileDialogPeer { @@ -53,11 +55,14 @@ class CFileDialog implements FileDialogPeer { if (title == null) { title = " "; } + Boolean chooseDirectories = AccessController.doPrivileged( + new GetBooleanAction("apple.awt.fileDialogForDirectories")); String[] userFileNames = nativeRunFileDialog(title, dialogMode, target.isMultipleMode(), navigateApps, + chooseDirectories, target.getFilenameFilter() != null, target.getDirectory(), target.getFile()); @@ -142,7 +147,8 @@ class CFileDialog implements FileDialogPeer { } private native String[] nativeRunFileDialog(String title, int mode, - boolean multipleMode, boolean shouldNavigateApps, boolean hasFilenameFilter, + boolean multipleMode, boolean shouldNavigateApps, + boolean canChooseDirectories, boolean hasFilenameFilter, String directory, String file); @Override diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java index dec254786b26c7ed6dd27c6bfbb7596704a934c3..370b930ea985a81e15ba44b7f36750b004a0857b 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java @@ -23,27 +23,24 @@ * questions. */ + package sun.lwawt.macosx; -import java.awt.Component; import java.awt.Insets; import sun.lwawt.PlatformComponent; import sun.lwawt.PlatformWindow; -import sun.lwawt.LWComponentPeer; - -import sun.lwawt.macosx.CFRetainedResource; - -public class CPlatformComponent extends CFRetainedResource implements PlatformComponent { - Component target; - LWComponentPeer peer; - PlatformWindow platformWindow; +/** + * On OSX {@code CPlatformComponent} stores pointer to the native CAlayer which + * can be used from JAWT. + */ +final class CPlatformComponent extends CFRetainedResource + implements PlatformComponent { - private native long nativeCreateComponent(long windowLayer); - private native long nativeSetBounds(long ptr, int x, int y, int width, int height); + private volatile PlatformWindow platformWindow; - public CPlatformComponent() { + CPlatformComponent() { super(0, true); } @@ -51,27 +48,28 @@ public class CPlatformComponent extends CFRetainedResource implements PlatformCo return ptr; } - public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow) { - this.target = target; - this.peer = peer; + @Override + public void initialize(final PlatformWindow platformWindow) { this.platformWindow = platformWindow; - - long windowLayerPtr = platformWindow.getLayerPtr(); - setPtr(nativeCreateComponent(windowLayerPtr)); + setPtr(nativeCreateComponent(platformWindow.getLayerPtr())); } // TODO: visibility, z-order @Override - public void setBounds(int x, int y, int width, int height) { + public void setBounds(final int x, final int y, final int w, final int h) { // translates values from the coordinate system of the top-level window // to the coordinate system of the content view - Insets insets = platformWindow.getPeer().getInsets(); - nativeSetBounds(getPointer(), x - insets.left, y - insets.top, width, height); + final Insets insets = platformWindow.getPeer().getInsets(); + nativeSetBounds(getPointer(), x - insets.left, y - insets.top, w, h); } @Override public void dispose() { super.dispose(); } + + private native long nativeCreateComponent(long windowLayer); + + private native void nativeSetBounds(long ptr, int x, int y, int w, int h); } diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java index aeff2833d9ab4ae97e301e85a72b0021d9ab727f..c21247f10572b561a6c4eb6f034b3142c936c7cb 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java @@ -180,7 +180,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { public void setResizable(boolean resizable) {} @Override - public void setMinimumSize(int width, int height) {} + public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {} @Override public Graphics transformGraphics(Graphics g) { diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java index b2f0d832999c561aad74bc957ee47e40058d1b74..b826f74dd0466e1f29bd46ab8b06d7d1f368cd7d 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java @@ -672,20 +672,15 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo // Re-apply the size constraints and the size to ensure the space // occupied by the grow box is counted properly - setMinimumSize(1, 1); // the method ignores its arguments + peer.updateMinimumSize(); Rectangle bounds = peer.getBounds(); setBounds(bounds.x, bounds.y, bounds.width, bounds.height); } @Override - public void setMinimumSize(int width, int height) { - //TODO width, height should be used - //NOTE: setResizable() calls setMinimumSize(1,1) relaying on the logic below - final long nsWindowPtr = getNSWindowPtr(); - final Dimension min = target.getMinimumSize(); - final Dimension max = target.getMaximumSize(); - nativeSetNSWindowMinMax(nsWindowPtr, min.getWidth(), min.getHeight(), max.getWidth(), max.getHeight()); + public void setSizeConstraints(int minW, int minH, int maxW, int maxH) { + nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH); } @Override diff --git a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index 774d31228d5e386ac15b07f06d530ac042c91fbc..ea44e5fe9f6e6d9d4be471157134fbe4db2b3c8a 100644 --- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -42,7 +42,7 @@ import java.util.concurrent.Callable; import sun.awt.*; import sun.lwawt.*; import sun.lwawt.LWWindowPeer.PeerType; - +import sun.security.action.GetBooleanAction; class NamedCursor extends Cursor { NamedCursor(String name) { @@ -81,14 +81,6 @@ public class LWCToolkit extends LWToolkit { } } - static String getSystemProperty(final String name, final String deflt) { - return AccessController.doPrivileged (new PrivilegedAction() { - public String run() { - return System.getProperty(name, deflt); - } - }); - } - public LWCToolkit() { SunToolkit.setDataTransfererClassName("sun.lwawt.macosx.CDataTransferer"); @@ -700,8 +692,8 @@ public class LWCToolkit extends LWToolkit { */ public synchronized static boolean getSunAwtDisableCALayers() { if (sunAwtDisableCALayers == null) { - sunAwtDisableCALayers = - getBooleanSystemProperty("sun.awt.disableCALayers"); + sunAwtDisableCALayers = AccessController.doPrivileged( + new GetBooleanAction("sun.awt.disableCALayers")); } return sunAwtDisableCALayers.booleanValue(); } diff --git a/src/macosx/native/sun/awt/AWTSurfaceLayers.m b/src/macosx/native/sun/awt/AWTSurfaceLayers.m index f3ab2d75e416c549f386399fa09c28ab3f5ca835..74b0855ffa22686f5586b83301edde4cc72667e0 100644 --- a/src/macosx/native/sun/awt/AWTSurfaceLayers.m +++ b/src/macosx/native/sun/awt/AWTSurfaceLayers.m @@ -78,11 +78,10 @@ // translates values to the coordinate system of the "root" layer CGFloat newY = windowLayer.bounds.size.height - rect.origin.y - rect.size.height; + CGRect newRect = CGRectMake(rect.origin.x, newY, rect.size.width, rect.size.height); - // REMIND: why do we need to inverse position? - CGRect newRect = CGRectMake(-rect.origin.x, -newY, rect.size.width, rect.size.height); + layer.frame = newRect; - layer.bounds = newRect; [AWTSurfaceLayers repaintLayersRecursively:layer]; } diff --git a/src/macosx/native/sun/awt/CFileDialog.h b/src/macosx/native/sun/awt/CFileDialog.h index 14ed63d24bf51d7bc8bcaddfb69202bb77b199ca..b8f6e14565856a2183dd97c9602841455a624469 100644 --- a/src/macosx/native/sun/awt/CFileDialog.h +++ b/src/macosx/native/sun/awt/CFileDialog.h @@ -52,6 +52,9 @@ // Should we navigate into apps? BOOL fNavigateApps; + // Can the dialog choose directories ? + BOOL fChooseDirectories; + // Contains the absolute paths of the selected files as URLs NSArray *fURLs; } @@ -65,6 +68,7 @@ mode:(jint)inMode multipleMode:(BOOL)inMultipleMode shouldNavigate:(BOOL)inNavigateApps + canChooseDirectories:(BOOL)inChooseDirectories withEnv:(JNIEnv*)env; // Invoked from the main thread diff --git a/src/macosx/native/sun/awt/CFileDialog.m b/src/macosx/native/sun/awt/CFileDialog.m index 283cc8cb781945bca546c320bd7d5dcb8bcfcd3a..be7cadc64fbc750ab6ff8fea0e4e14ecfa24511c 100644 --- a/src/macosx/native/sun/awt/CFileDialog.m +++ b/src/macosx/native/sun/awt/CFileDialog.m @@ -43,6 +43,7 @@ mode:(jint)inMode multipleMode:(BOOL)inMultipleMode shouldNavigate:(BOOL)inNavigateApps +canChooseDirectories:(BOOL)inChooseDirectories withEnv:(JNIEnv*)env; { if (self == [super init]) { @@ -57,6 +58,7 @@ fMode = inMode; fMultipleMode = inMultipleMode; fNavigateApps = inNavigateApps; + fChooseDirectories = inChooseDirectories; fPanelResult = NSCancelButton; } @@ -109,7 +111,7 @@ NSOpenPanel *openPanel = (NSOpenPanel *)thePanel; [openPanel setAllowsMultipleSelection:fMultipleMode]; [openPanel setCanChooseFiles:YES]; - [openPanel setCanChooseDirectories:NO]; + [openPanel setCanChooseDirectories:fChooseDirectories]; [openPanel setCanCreateDirectories:YES]; } @@ -182,7 +184,8 @@ JNIEXPORT jobjectArray JNICALL Java_sun_lwawt_macosx_CFileDialog_nativeRunFileDialog (JNIEnv *env, jobject peer, jstring title, jint mode, jboolean multipleMode, - jboolean navigateApps, jboolean hasFilter, jstring directory, jstring file) + jboolean navigateApps, jboolean chooseDirectories, jboolean hasFilter, + jstring directory, jstring file) { jobjectArray returnValue = NULL; @@ -200,6 +203,7 @@ JNF_COCOA_ENTER(env); mode:mode multipleMode:multipleMode shouldNavigate:navigateApps + canChooseDirectories:chooseDirectories withEnv:env]; [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad) diff --git a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m index bbe42519694cea24cd59f2ad8bb54f31f2fa335c..0bc58ec6ad3bae5acdeccd487de422c5dcfd8ec2 100644 --- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m +++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m @@ -447,3 +447,20 @@ Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities return cglinfo->context->caps; } } + +JNIEXPORT jint JNICALL +Java_sun_java2d_opengl_CGLGraphicsConfig_getMaxTextureSize + (JNIEnv *env, jclass cglgc) +{ + J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getMaxTextureSize"); + + __block int max = 0; + + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [sharedContext makeCurrentContext]; + j2d_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max); + }]; + + return (jint)max; +} + diff --git a/src/macosx/native/sun/osxapp/NSApplicationAWT.h b/src/macosx/native/sun/osxapp/NSApplicationAWT.h index bed85ce2f723bb8cd0ca15863b2887de50d46e00..3f4bc0ca749fc6649db86f6bd0a606635bffa17a 100644 --- a/src/macosx/native/sun/osxapp/NSApplicationAWT.h +++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.h @@ -28,7 +28,6 @@ @interface NSApplicationAWT : NSApplication { NSString *fApplicationName; - BOOL fUseDefaultIcon; NSWindow *eventTransparentWindow; } diff --git a/src/macosx/native/sun/osxapp/NSApplicationAWT.m b/src/macosx/native/sun/osxapp/NSApplicationAWT.m index 4128c870f327147d7b6f86c8347077c005d6d156..bc18e00f1fc85781406f1800d553319f88c798e9 100644 --- a/src/macosx/native/sun/osxapp/NSApplicationAWT.m +++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.m @@ -52,7 +52,6 @@ BOOL postEventDuringEventSynthesis = NO; AWT_ASSERT_APPKIT_THREAD; fApplicationName = nil; - fUseDefaultIcon = NO; // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one. // So, we need to call it ourselves to ensure the app is set up properly. @@ -147,10 +146,6 @@ AWT_ASSERT_APPKIT_THREAD; if (appName != NULL) { fApplicationName = [NSString stringWithUTF8String:appName]; unsetenv(envVar); - - // If this environment variable was set we were launched from the command line, so we - // should use a generic app icon if one wasn't set. - fUseDefaultIcon = YES; } // If it wasn't specified as an argument, see if it was specified as a system property. @@ -171,9 +166,6 @@ AWT_ASSERT_APPKIT_THREAD; if (lastPeriod.location != NSNotFound) { fApplicationName = [fApplicationName substringFromIndex:lastPeriod.location + 1]; } - // If this environment variable was set we were launched from the command line, so we - // should use a generic app icon if one wasn't set. - fUseDefaultIcon = YES; } } @@ -266,8 +258,11 @@ AWT_ASSERT_APPKIT_THREAD; // If the icon file wasn't specified as an argument and we need to get an icon // we'll use the generic java app icon. NSString *defaultIconPath = [NSString stringWithFormat:@"%@%@", SHARED_FRAMEWORK_BUNDLE, @"/Resources/GenericApp.icns"]; - if (fUseDefaultIcon && (theIconPath == nil)) { - theIconPath = defaultIconPath; + if (theIconPath == nil) { + NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"]; + if (bundleIcon == nil) { + theIconPath = defaultIconPath; + } } // Set up the dock icon if we have an icon name. diff --git a/src/share/bin/jli_util.h b/src/share/bin/jli_util.h index af1ce47e6e470cb259743670664b617d6c605975..568318c95c67e463e1b6ad4b5a58d7ae4d615ecb 100644 --- a/src/share/bin/jli_util.h +++ b/src/share/bin/jli_util.h @@ -68,12 +68,23 @@ int JLI_GetStdArgc(); #define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3)) #define JLI_Snprintf _snprintf void JLI_CmdToArgs(char *cmdline); -#else +#define JLI_Lseek _lseeki64 +#else /* NIXES */ #include #include #define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2)) #define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3)) #define JLI_Snprintf snprintf +#ifdef __solaris__ +#define JLI_Lseek llseek +#endif +#ifdef __linux__ +#define _LARGFILE64_SOURCE +#define JLI_Lseek lseek64 +#endif +#ifdef MACOSX +#define JLI_Lseek lseek +#endif #endif /* _WIN32 */ /* diff --git a/src/share/bin/manifest_info.h b/src/share/bin/manifest_info.h index 44341f42cf590b1c97b130b2c03cbf093e6202fc..cd951d5cb9f40dd6f21008b6f00bc503287005ca 100644 --- a/src/share/bin/manifest_info.h +++ b/src/share/bin/manifest_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,8 @@ #define CENSIG 0x02014b50L /* "PK\001\002" */ #define ENDSIG 0x06054b50L /* "PK\005\006" */ +#define ZIP64_ENDSIG 0x06064b50L /* "PK\006\006" */ +#define ZIP64_LOCSIG 0x07064b50L /* "PK\006\007" */ /* * Header sizes including signatures */ @@ -45,12 +47,21 @@ #define CENHDR 46 #define ENDHDR 22 +#define ZIP64_ENDHDR 56 // ZIP64 end header size +#define ZIP64_LOCHDR 20 // ZIP64 end loc header size +#define ZIP64_EXTHDR 24 // EXT header size +#define ZIP64_EXTID 1 // Extra field Zip64 header ID + +#define ZIP64_MAGICVAL 0xffffffffLL +#define ZIP64_MAGICCOUNT 0xffff + /* * Header field access macros */ #define CH(b, n) (((unsigned char *)(b))[n]) #define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8)) -#define LG(b, n) (SH(b, n) | (SH(b, n+2) << 16)) +#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL) +#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32)) #define GETSIG(b) LG(b, 0) /* @@ -101,6 +112,26 @@ #define ENDOFF(b) LG(b, 16) /* central directory offset */ #define ENDCOM(b) SH(b, 20) /* size of zip file comment */ +/* + * Macros for getting Zip64 end of central directory header fields + */ +#define ZIP64_ENDLEN(b) LL(b, 4) /* size of zip64 end of central dir */ +#define ZIP64_ENDVEM(b) SH(b, 12) /* version made by */ +#define ZIP64_ENDVER(b) SH(b, 14) /* version needed to extract */ +#define ZIP64_ENDNMD(b) LG(b, 16) /* number of this disk */ +#define ZIP64_ENDDSK(b) LG(b, 20) /* disk number of start */ +#define ZIP64_ENDTOD(b) LL(b, 24) /* total number of entries on this disk */ +#define ZIP64_ENDTOT(b) LL(b, 32) /* total number of entries */ +#define ZIP64_ENDSIZ(b) LL(b, 40) /* central directory size in bytes */ +#define ZIP64_ENDOFF(b) LL(b, 48) /* offset of first CEN header */ + +/* + * Macros for getting Zip64 end of central directory locator fields + */ +#define ZIP64_LOCDSK(b) LG(b, 4) /* disk number start */ +#define ZIP64_LOCOFF(b) LL(b, 8) /* offset of zip64 end */ +#define ZIP64_LOCTOT(b) LG(b, 16) /* total number of disks */ + /* * A comment of maximum length of 64kb can follow the END record. This * is the furthest the END record can be from the end of the file. @@ -119,7 +150,7 @@ typedef struct zentry { /* Zip file entry */ size_t isize; /* size of inflated data */ size_t csize; /* size of compressed data (zero if uncompressed) */ - off_t offset; /* position of compressed data */ + jlong offset; /* position of compressed data */ int how; /* compression method (if any) */ } zentry; diff --git a/src/share/bin/parse_manifest.c b/src/share/bin/parse_manifest.c index eb847bf690c3ef68b79ee422b63fdb572aa5989a..ec3014931f22330f3ebe89cc1664e7d28b3fc1c5 100644 --- a/src/share/bin/parse_manifest.c +++ b/src/share/bin/parse_manifest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,7 +61,7 @@ inflate_file(int fd, zentry *entry, int *size_out) if (entry->csize == (size_t) -1 || entry->isize == (size_t) -1 ) return (NULL); - if (lseek(fd, entry->offset, SEEK_SET) < (off_t)0) + if (JLI_Lseek(fd, entry->offset, SEEK_SET) < (jlong)0) return (NULL); if ((in = malloc(entry->csize + 1)) == NULL) return (NULL); @@ -110,6 +110,38 @@ inflate_file(int fd, zentry *entry, int *size_out) return (NULL); } +static jboolean zip64_present = JNI_FALSE; + +/* + * Checks to see if we have ZIP64 archive, and save + * the check for later use + */ +static int +haveZIP64(Byte *p) { + jlong cenlen, cenoff, centot; + cenlen = ENDSIZ(p); + cenoff = ENDOFF(p); + centot = ENDTOT(p); + zip64_present = (cenlen == ZIP64_MAGICVAL || + cenoff == ZIP64_MAGICVAL || + centot == ZIP64_MAGICCOUNT); + return zip64_present; +} + +static jlong +find_end64(int fd, Byte *ep, jlong pos) +{ + jlong end64pos; + jlong bytes; + if ((end64pos = JLI_Lseek(fd, pos - ZIP64_LOCHDR, SEEK_SET)) < (jlong)0) + return -1; + if ((bytes = read(fd, ep, ZIP64_LOCHDR)) < 0) + return -1; + if (GETSIG(ep) == ZIP64_LOCSIG) + return end64pos; + return -1; +} + /* * A very little used routine to handle the case that zip file has * a comment at the end. Believe it or not, the only way to find the @@ -122,12 +154,12 @@ inflate_file(int fd, zentry *entry, int *size_out) * Returns the offset of the END record in the file on success, * -1 on failure. */ -static off_t +static jlong find_end(int fd, Byte *eb) { - off_t len; - off_t pos; - off_t flen; + jlong len; + jlong pos; + jlong flen; int bytes; Byte *cp; Byte *endpos; @@ -136,14 +168,16 @@ find_end(int fd, Byte *eb) /* * 99.44% (or more) of the time, there will be no comment at the * end of the zip file. Try reading just enough to read the END - * record from the end of the file. + * record from the end of the file, at this time we should also + * check to see if we have a ZIP64 archive. */ - if ((pos = lseek(fd, -ENDHDR, SEEK_END)) < (off_t)0) + if ((pos = JLI_Lseek(fd, -ENDHDR, SEEK_END)) < (jlong)0) return (-1); if ((bytes = read(fd, eb, ENDHDR)) < 0) return (-1); - if (GETSIG(eb) == ENDSIG) - return (pos); + if (GETSIG(eb) == ENDSIG) { + return haveZIP64(eb) ? find_end64(fd, eb, pos) : pos; + } /* * Shucky-Darn,... There is a comment at the end of the zip file. @@ -151,10 +185,10 @@ find_end(int fd, Byte *eb) * Allocate and fill a buffer with enough of the zip file * to meet the specification for a maximal comment length. */ - if ((flen = lseek(fd, 0, SEEK_END)) < (off_t)0) + if ((flen = JLI_Lseek(fd, 0, SEEK_END)) < (jlong)0) return (-1); len = (flen < END_MAXLEN) ? flen : END_MAXLEN; - if (lseek(fd, -len, SEEK_END) < (off_t)0) + if (JLI_Lseek(fd, -len, SEEK_END) < (jlong)0) return (-1); if ((buffer = malloc(END_MAXLEN)) == NULL) return (-1); @@ -175,12 +209,92 @@ find_end(int fd, Byte *eb) (cp + ENDHDR + ENDCOM(cp) == endpos)) { (void) memcpy(eb, cp, ENDHDR); free(buffer); - return (flen - (endpos - cp)); + pos = flen - (endpos - cp); + return haveZIP64(eb) ? find_end64(fd, eb, pos) : pos; } free(buffer); return (-1); } +#define BUFSIZE (3 * 65536 + CENHDR + SIGSIZ) +#define MINREAD 1024 + +/* + * Computes and positions at the start of the CEN header, ie. the central + * directory, this will also return the offset if there is a zip file comment + * at the end of the archive, for most cases this would be 0. + */ +static jlong +compute_cen(int fd, Byte *bp) +{ + int bytes; + Byte *p; + jlong base_offset; + jlong offset; + char buffer[MINREAD]; + p = buffer; + /* + * Read the END Header, which is the starting point for ZIP files. + * (Clearly designed to make writing a zip file easier than reading + * one. Now isn't that precious...) + */ + if ((base_offset = find_end(fd, bp)) == -1) { + return (-1); + } + p = bp; + /* + * There is a historical, but undocumented, ability to allow for + * additional "stuff" to be prepended to the zip/jar file. It seems + * that this has been used to prepend an actual java launcher + * executable to the jar on Windows. Although this is just another + * form of statically linking a small piece of the JVM to the + * application, we choose to continue to support it. Note that no + * guarantees have been made (or should be made) to the customer that + * this will continue to work. + * + * Therefore, calculate the base offset of the zip file (within the + * expanded file) by assuming that the central directory is followed + * immediately by the end record. + */ + if (zip64_present) { + if ((offset = ZIP64_LOCOFF(p)) < (jlong)0) { + return -1; + } + if (JLI_Lseek(fd, offset, SEEK_SET) < (jlong) 0) { + return (-1); + } + if ((bytes = read(fd, buffer, MINREAD)) < 0) { + return (-1); + } + if (GETSIG(buffer) != ZIP64_ENDSIG) { + return -1; + } + if ((offset = ZIP64_ENDOFF(buffer)) < (jlong)0) { + return -1; + } + if (JLI_Lseek(fd, offset, SEEK_SET) < (jlong)0) { + return (-1); + } + p = buffer; + base_offset = base_offset - ZIP64_ENDSIZ(p) - ZIP64_ENDOFF(p) - ZIP64_ENDHDR; + } else { + base_offset = base_offset - ENDSIZ(p) - ENDOFF(p); + /* + * The END Header indicates the start of the Central Directory + * Headers. Remember that the desired Central Directory Header (CEN) + * will almost always be the second one and the first one is a small + * directory entry ("META-INF/"). Keep the code optimized for + * that case. + * + * Seek to the beginning of the Central Directory. + */ + if (JLI_Lseek(fd, base_offset + ENDOFF(p), SEEK_SET) < (jlong) 0) { + return (-1); + } + } + return base_offset; +} + /* * Locate the manifest file with the zip/jar file. * @@ -208,9 +322,6 @@ find_end(int fd, Byte *eb) * a typical jar file (META-INF and META-INF/MANIFEST.MF). Keep this factoid * in mind when optimizing this code. */ -#define BUFSIZE (3 * 65536 + CENHDR + SIGSIZ) -#define MINREAD 1024 - static int find_file(int fd, zentry *entry, const char *file_name) { @@ -218,7 +329,7 @@ find_file(int fd, zentry *entry, const char *file_name) int res; int entry_size; int read_size; - int base_offset; + jlong base_offset; Byte *p; Byte *bp; Byte *buffer; @@ -228,54 +339,18 @@ find_file(int fd, zentry *entry, const char *file_name) return(-1); } - p = buffer; bp = buffer; - - /* - * Read the END Header, which is the starting point for ZIP files. - * (Clearly designed to make writing a zip file easier than reading - * one. Now isn't that precious...) - */ - if ((base_offset = find_end(fd, bp)) == -1) { + base_offset = compute_cen(fd, bp); + if (base_offset == -1) { free(buffer); - return (-1); + return -1; } - /* - * There is a historical, but undocumented, ability to allow for - * additional "stuff" to be prepended to the zip/jar file. It seems - * that this has been used to prepend an actual java launcher - * executable to the jar on Windows. Although this is just another - * form of statically linking a small piece of the JVM to the - * application, we choose to continue to support it. Note that no - * guarantees have been made (or should be made) to the customer that - * this will continue to work. - * - * Therefore, calculate the base offset of the zip file (within the - * expanded file) by assuming that the central directory is followed - * immediately by the end record. - */ - base_offset = base_offset - ENDSIZ(p) - ENDOFF(p); - - /* - * The END Header indicates the start of the Central Directory - * Headers. Remember that the desired Central Directory Header (CEN) - * will almost always be the second one and the first one is a small - * directory entry ("META-INF/"). Keep the code optimized for - * that case. - * - * Begin by seeking to the beginning of the Central Directory and - * reading in the first buffer full of bits. - */ - if (lseek(fd, base_offset + ENDOFF(p), SEEK_SET) < (off_t)0) { - free(buffer); - return (-1); - } if ((bytes = read(fd, bp, MINREAD)) < 0) { free(buffer); return (-1); } - + p = bp; /* * Loop through the Central Directory Headers. Note that a valid zip/jar * must have an ENDHDR (with ENDSIG) after the Central Directory. @@ -319,7 +394,7 @@ find_file(int fd, zentry *entry, const char *file_name) */ if ((size_t)CENNAM(p) == JLI_StrLen(file_name) && memcmp((p + CENHDR), file_name, JLI_StrLen(file_name)) == 0) { - if (lseek(fd, base_offset + CENOFF(p), SEEK_SET) < (off_t)0) { + if (JLI_Lseek(fd, base_offset + CENOFF(p), SEEK_SET) < (jlong)0) { free(buffer); return (-1); } @@ -487,6 +562,9 @@ JLI_ParseManifest(char *jarfile, manifest_info *info) char *splashscreen_name = NULL; if ((fd = open(jarfile, O_RDONLY +#ifdef O_LARGEFILE + | O_LARGEFILE /* large file mode on solaris */ +#endif #ifdef O_BINARY | O_BINARY /* use binary mode on windows */ #endif diff --git a/src/share/classes/com/sun/beans/decoder/MethodElementHandler.java b/src/share/classes/com/sun/beans/decoder/MethodElementHandler.java index 4afd7b1556ec3988462b6f100fe41bddaa65a052..73fcb67fa4fa4b94e04caf2458f1fdf1c6286f13 100644 --- a/src/share/classes/com/sun/beans/decoder/MethodElementHandler.java +++ b/src/share/classes/com/sun/beans/decoder/MethodElementHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,8 @@ import com.sun.beans.finder.MethodFinder; import java.lang.reflect.Method; +import sun.reflect.misc.MethodUtil; + /** * This class is intended to handle <method> element. * It describes invocation of the method. @@ -101,7 +103,7 @@ final class MethodElementHandler extends NewElementHandler { if (method.isVarArgs()) { args = getArguments(args, method.getParameterTypes()); } - Object value = method.invoke(bean, args); + Object value = MethodUtil.invoke(method, bean, args); return method.getReturnType().equals(void.class) ? ValueObjectImpl.VOID : ValueObjectImpl.create(value); diff --git a/src/share/classes/sun/beans/editors/BooleanEditor.java b/src/share/classes/com/sun/beans/editors/BooleanEditor.java similarity index 96% rename from src/share/classes/sun/beans/editors/BooleanEditor.java rename to src/share/classes/com/sun/beans/editors/BooleanEditor.java index 60103f53aa99b9af84f3e4bf5b18dc275f8a946e..69aca3238c93327ce87774764d837d39246f9c90 100644 --- a/src/share/classes/sun/beans/editors/BooleanEditor.java +++ b/src/share/classes/com/sun/beans/editors/BooleanEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "boolean" type. diff --git a/src/share/classes/sun/beans/editors/ByteEditor.java b/src/share/classes/com/sun/beans/editors/ByteEditor.java similarity index 94% rename from src/share/classes/sun/beans/editors/ByteEditor.java rename to src/share/classes/com/sun/beans/editors/ByteEditor.java index fb31293e8cb83b32a41d10291b454d5dda1d105b..2f4f342774f44a4d2070fc33f78851dfb43289f1 100644 --- a/src/share/classes/sun/beans/editors/ByteEditor.java +++ b/src/share/classes/com/sun/beans/editors/ByteEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "byte" type. diff --git a/src/share/classes/sun/beans/editors/ColorEditor.java b/src/share/classes/com/sun/beans/editors/ColorEditor.java similarity index 98% rename from src/share/classes/sun/beans/editors/ColorEditor.java rename to src/share/classes/com/sun/beans/editors/ColorEditor.java index 82ff2d680eb4d809b231b95c49f87f4a88133e43..377af057bd9912a75a3aa58c8eff01e3abb56ef9 100644 --- a/src/share/classes/sun/beans/editors/ColorEditor.java +++ b/src/share/classes/com/sun/beans/editors/ColorEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; import java.awt.*; import java.beans.*; diff --git a/src/share/classes/sun/beans/editors/DoubleEditor.java b/src/share/classes/com/sun/beans/editors/DoubleEditor.java similarity index 93% rename from src/share/classes/sun/beans/editors/DoubleEditor.java rename to src/share/classes/com/sun/beans/editors/DoubleEditor.java index e99d46779aba437626f5f632281f2efc5dba7e3e..55d5a0528a445d96fc7d6e1028ae9c8570ffdfa6 100644 --- a/src/share/classes/sun/beans/editors/DoubleEditor.java +++ b/src/share/classes/com/sun/beans/editors/DoubleEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "double" type. diff --git a/src/share/classes/sun/beans/editors/EnumEditor.java b/src/share/classes/com/sun/beans/editors/EnumEditor.java similarity index 97% rename from src/share/classes/sun/beans/editors/EnumEditor.java rename to src/share/classes/com/sun/beans/editors/EnumEditor.java index 1da56fc1938d0ab66d94eecb2fc9a97b387331fc..6275977d34475247983132d6fe7c6a6164fe0130 100644 --- a/src/share/classes/sun/beans/editors/EnumEditor.java +++ b/src/share/classes/com/sun/beans/editors/EnumEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; import java.awt.Component; import java.awt.Graphics; diff --git a/src/share/classes/sun/beans/editors/FloatEditor.java b/src/share/classes/com/sun/beans/editors/FloatEditor.java similarity index 94% rename from src/share/classes/sun/beans/editors/FloatEditor.java rename to src/share/classes/com/sun/beans/editors/FloatEditor.java index 85da73d0158a5050d10ef9b8e1203941c0a3eb1f..4723c489cc0510623ffd8ab2d42e74cbe0ad6ac9 100644 --- a/src/share/classes/sun/beans/editors/FloatEditor.java +++ b/src/share/classes/com/sun/beans/editors/FloatEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "float" type. diff --git a/src/share/classes/sun/beans/editors/FontEditor.java b/src/share/classes/com/sun/beans/editors/FontEditor.java similarity index 98% rename from src/share/classes/sun/beans/editors/FontEditor.java rename to src/share/classes/com/sun/beans/editors/FontEditor.java index b6d6911bda158ab394c6396a56def512e7d0f034..108ac5e2e5b19848398c7ff6c03e363d82a19d86 100644 --- a/src/share/classes/sun/beans/editors/FontEditor.java +++ b/src/share/classes/com/sun/beans/editors/FontEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; import java.awt.*; import java.beans.*; diff --git a/src/share/classes/sun/beans/editors/IntegerEditor.java b/src/share/classes/com/sun/beans/editors/IntegerEditor.java similarity index 93% rename from src/share/classes/sun/beans/editors/IntegerEditor.java rename to src/share/classes/com/sun/beans/editors/IntegerEditor.java index 216596af452ce79f70df6f864e469327b99e0a00..066b7143ac603a307cf2c1dbd6f29b51a07caff1 100644 --- a/src/share/classes/sun/beans/editors/IntegerEditor.java +++ b/src/share/classes/com/sun/beans/editors/IntegerEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "int" type. diff --git a/src/share/classes/sun/beans/editors/LongEditor.java b/src/share/classes/com/sun/beans/editors/LongEditor.java similarity index 94% rename from src/share/classes/sun/beans/editors/LongEditor.java rename to src/share/classes/com/sun/beans/editors/LongEditor.java index 8d0ad3a795d3fd34db37942e439e821e90bf6155..3a8efbba53cfc99b8f68f0b71dd282bc5355dc88 100644 --- a/src/share/classes/sun/beans/editors/LongEditor.java +++ b/src/share/classes/com/sun/beans/editors/LongEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "long" type. diff --git a/src/share/classes/sun/beans/editors/NumberEditor.java b/src/share/classes/com/sun/beans/editors/NumberEditor.java similarity index 93% rename from src/share/classes/sun/beans/editors/NumberEditor.java rename to src/share/classes/com/sun/beans/editors/NumberEditor.java index 2325f97f2efc7f588d45b7bd3d3984b75bc33676..3941e2cf0bcb673048ae53d5b8d8fdec037be235 100644 --- a/src/share/classes/sun/beans/editors/NumberEditor.java +++ b/src/share/classes/com/sun/beans/editors/NumberEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Abstract Property editor for a java builtin number types. diff --git a/src/share/classes/sun/beans/editors/ShortEditor.java b/src/share/classes/com/sun/beans/editors/ShortEditor.java similarity index 94% rename from src/share/classes/sun/beans/editors/ShortEditor.java rename to src/share/classes/com/sun/beans/editors/ShortEditor.java index 8eee3f895040293d188f481935ad63c059c6b547..cf82eef215d6d8607adc44900c972e6c4ae14ec8 100644 --- a/src/share/classes/sun/beans/editors/ShortEditor.java +++ b/src/share/classes/com/sun/beans/editors/ShortEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,7 @@ */ -package sun.beans.editors; +package com.sun.beans.editors; /** * Property editor for a java builtin "short" type. diff --git a/src/share/classes/sun/beans/editors/StringEditor.java b/src/share/classes/com/sun/beans/editors/StringEditor.java similarity index 96% rename from src/share/classes/sun/beans/editors/StringEditor.java rename to src/share/classes/com/sun/beans/editors/StringEditor.java index 23a8a72f1dc0ba6ec02320d12de0c2a540eeb010..2f1cde46ea0b5e3ed89689b9997c6a0826468eaf 100644 --- a/src/share/classes/sun/beans/editors/StringEditor.java +++ b/src/share/classes/com/sun/beans/editors/StringEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,7 @@ */ -package sun.beans.editors; +package com.sun.beans.editors; import java.beans.*; diff --git a/src/share/classes/com/sun/beans/finder/BeanInfoFinder.java b/src/share/classes/com/sun/beans/finder/BeanInfoFinder.java index ec9d0df4df79552dc7130902c4705c4f55a0b4f7..28af1a4c1b25d0200200ffa7b6e9a6e746b07c8c 100644 --- a/src/share/classes/com/sun/beans/finder/BeanInfoFinder.java +++ b/src/share/classes/com/sun/beans/finder/BeanInfoFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ public final class BeanInfoFinder extends InstanceFinder { private static final String DEFAULT = "sun.beans.infos"; + private static final String DEFAULT_NEW = "com.sun.beans.infos"; public BeanInfoFinder() { super(BeanInfo.class, true, "BeanInfo", DEFAULT); @@ -53,10 +54,13 @@ public final class BeanInfoFinder @Override protected BeanInfo instantiate(Class type, String prefix, String name) { + if (DEFAULT.equals(prefix)) { + prefix = DEFAULT_NEW; + } // this optimization will only use the BeanInfo search path // if is has changed from the original // or trying to get the ComponentBeanInfo - BeanInfo info = !DEFAULT.equals(prefix) || "ComponentBeanInfo".equals(name) + BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name) ? super.instantiate(type, prefix, name) : null; diff --git a/src/share/classes/com/sun/beans/finder/ClassFinder.java b/src/share/classes/com/sun/beans/finder/ClassFinder.java index d5ba14839ba178256b9c2ade63ec6fea23d5c47a..9d53235a8da7853336c5ec78a395a5850df8619d 100644 --- a/src/share/classes/com/sun/beans/finder/ClassFinder.java +++ b/src/share/classes/com/sun/beans/finder/ClassFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,8 @@ */ package com.sun.beans.finder; +import static sun.reflect.misc.ReflectUtil.checkPackageAccess; + /** * This is utility class that provides {@code static} methods * to find a class with the specified name using the specified class loader. @@ -54,6 +56,7 @@ public final class ClassFinder { * @see Thread#getContextClassLoader() */ public static Class findClass(String name) throws ClassNotFoundException { + checkPackageAccess(name); try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { @@ -94,6 +97,7 @@ public final class ClassFinder { * @see Class#forName(String,boolean,ClassLoader) */ public static Class findClass(String name, ClassLoader loader) throws ClassNotFoundException { + checkPackageAccess(name); if (loader != null) { try { return Class.forName(name, false, loader); diff --git a/src/share/classes/com/sun/beans/finder/ConstructorFinder.java b/src/share/classes/com/sun/beans/finder/ConstructorFinder.java index cfc3a1cae739e69874c044edb42fee1b735dd7f0..f7419c7973af7aafc68e9f710730f2fabd030ebe 100644 --- a/src/share/classes/com/sun/beans/finder/ConstructorFinder.java +++ b/src/share/classes/com/sun/beans/finder/ConstructorFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,8 @@ import com.sun.beans.WeakCache; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import static sun.reflect.misc.ReflectUtil.isPackageAccessible; + /** * This utility class provides {@code static} methods * to find a public constructor with specified parameter types @@ -61,7 +63,7 @@ public final class ConstructorFinder extends AbstractFinder> { if (Modifier.isAbstract(type.getModifiers())) { throw new NoSuchMethodException("Abstract class cannot be instantiated"); } - if (!Modifier.isPublic(type.getModifiers())) { + if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) { throw new NoSuchMethodException("Class is not accessible"); } PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); diff --git a/src/share/classes/com/sun/beans/finder/FieldFinder.java b/src/share/classes/com/sun/beans/finder/FieldFinder.java index a8a6dc8ffd943563283497581ca02563226da7df..eb8b5bba616af64763c121574ae2eaceb2c41cf1 100644 --- a/src/share/classes/com/sun/beans/finder/FieldFinder.java +++ b/src/share/classes/com/sun/beans/finder/FieldFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,8 @@ package com.sun.beans.finder; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import static sun.reflect.misc.ReflectUtil.isPackageAccessible; + /** * This utility class provides {@code static} methods * to find a public field with specified name @@ -56,7 +58,8 @@ public final class FieldFinder { if (!Modifier.isPublic(field.getModifiers())) { throw new NoSuchFieldException("Field '" + name + "' is not public"); } - if (!Modifier.isPublic(field.getDeclaringClass().getModifiers())) { + type = field.getDeclaringClass(); + if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) { throw new NoSuchFieldException("Field '" + name + "' is not accessible"); } return field; diff --git a/src/share/classes/com/sun/beans/finder/MethodFinder.java b/src/share/classes/com/sun/beans/finder/MethodFinder.java index 695363b9bc0473bf37c151b74c9368bdcb245256..fa7cc5612abb762d75f5c61b18904e963e969710 100644 --- a/src/share/classes/com/sun/beans/finder/MethodFinder.java +++ b/src/share/classes/com/sun/beans/finder/MethodFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,6 +33,8 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; +import static sun.reflect.misc.ReflectUtil.isPackageAccessible; + /** * This utility class provides {@code static} methods * to find a public method with specified name and parameter types @@ -120,7 +122,7 @@ public final class MethodFinder extends AbstractFinder { */ public static Method findAccessibleMethod(Method method) throws NoSuchMethodException { Class type = method.getDeclaringClass(); - if (Modifier.isPublic(type.getModifiers())) { + if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) { return method; } if (Modifier.isStatic(method.getModifiers())) { diff --git a/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java b/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java index 45c19da1cf3abb19dc2cec8a85082a48827bc4bb..c4097cc0575fdd20c7c68b677d3a946f915d4f40 100644 --- a/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java +++ b/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,14 +28,14 @@ import com.sun.beans.WeakCache; import java.beans.PropertyEditor; -import sun.beans.editors.BooleanEditor; -import sun.beans.editors.ByteEditor; -import sun.beans.editors.DoubleEditor; -import sun.beans.editors.EnumEditor; -import sun.beans.editors.FloatEditor; -import sun.beans.editors.IntegerEditor; -import sun.beans.editors.LongEditor; -import sun.beans.editors.ShortEditor; +import com.sun.beans.editors.BooleanEditor; +import com.sun.beans.editors.ByteEditor; +import com.sun.beans.editors.DoubleEditor; +import com.sun.beans.editors.EnumEditor; +import com.sun.beans.editors.FloatEditor; +import com.sun.beans.editors.IntegerEditor; +import com.sun.beans.editors.LongEditor; +import com.sun.beans.editors.ShortEditor; /** * This is utility class that provides functionality @@ -48,10 +48,13 @@ import sun.beans.editors.ShortEditor; public final class PropertyEditorFinder extends InstanceFinder { + private static final String DEFAULT = "sun.beans.editors"; + private static final String DEFAULT_NEW = "com.sun.beans.editors"; + private final WeakCache, Class> registry; public PropertyEditorFinder() { - super(PropertyEditor.class, false, "Editor", "sun.beans.editors"); + super(PropertyEditor.class, false, "Editor", DEFAULT); this.registry = new WeakCache, Class>(); this.registry.put(Byte.TYPE, ByteEditor.class); @@ -84,4 +87,9 @@ public final class PropertyEditorFinder } return editor; } + + @Override + protected PropertyEditor instantiate(Class type, String prefix, String name) { + return super.instantiate(type, DEFAULT.equals(prefix) ? DEFAULT_NEW : prefix, name); + } } diff --git a/src/share/classes/sun/beans/infos/ComponentBeanInfo.java b/src/share/classes/com/sun/beans/infos/ComponentBeanInfo.java similarity index 96% rename from src/share/classes/sun/beans/infos/ComponentBeanInfo.java rename to src/share/classes/com/sun/beans/infos/ComponentBeanInfo.java index ae6631f1f3149670292c099da4e96413b248ed4e..1514b0050747df028ac20f967c2e7aa482d8c1ac 100644 --- a/src/share/classes/sun/beans/infos/ComponentBeanInfo.java +++ b/src/share/classes/com/sun/beans/infos/ComponentBeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ * questions. */ -package sun.beans.infos; +package com.sun.beans.infos; import java.beans.*; diff --git a/src/share/classes/com/sun/crypto/provider/AESCipher.java b/src/share/classes/com/sun/crypto/provider/AESCipher.java index 3c3ef229111debb762b7b010b15b1081ddc7ed5a..0ae68957c43b86d46ffd7822433bce2b3af71773 100644 --- a/src/share/classes/com/sun/crypto/provider/AESCipher.java +++ b/src/share/classes/com/sun/crypto/provider/AESCipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -47,18 +47,122 @@ import javax.crypto.BadPaddingException; * @see OutputFeedback */ -public final class AESCipher extends CipherSpi { +abstract class AESCipher extends CipherSpi { + public static final class General extends AESCipher { + public General() { + super(-1); + } + } + abstract static class OidImpl extends AESCipher { + protected OidImpl(int keySize, String mode, String padding) { + super(keySize); + try { + engineSetMode(mode); + engineSetPadding(padding); + } catch (GeneralSecurityException gse) { + // internal error; re-throw as provider exception + ProviderException pe =new ProviderException("Internal Error"); + pe.initCause(gse); + throw pe; + } + } + } + public static final class AES128_ECB_NoPadding extends OidImpl { + public AES128_ECB_NoPadding() { + super(16, "ECB", "NOPADDING"); + } + } + public static final class AES192_ECB_NoPadding extends OidImpl { + public AES192_ECB_NoPadding() { + super(24, "ECB", "NOPADDING"); + } + } + public static final class AES256_ECB_NoPadding extends OidImpl { + public AES256_ECB_NoPadding() { + super(32, "ECB", "NOPADDING"); + } + } + public static final class AES128_CBC_NoPadding extends OidImpl { + public AES128_CBC_NoPadding() { + super(16, "CBC", "NOPADDING"); + } + } + public static final class AES192_CBC_NoPadding extends OidImpl { + public AES192_CBC_NoPadding() { + super(24, "CBC", "NOPADDING"); + } + } + public static final class AES256_CBC_NoPadding extends OidImpl { + public AES256_CBC_NoPadding() { + super(32, "CBC", "NOPADDING"); + } + } + public static final class AES128_OFB_NoPadding extends OidImpl { + public AES128_OFB_NoPadding() { + super(16, "OFB", "NOPADDING"); + } + } + public static final class AES192_OFB_NoPadding extends OidImpl { + public AES192_OFB_NoPadding() { + super(24, "OFB", "NOPADDING"); + } + } + public static final class AES256_OFB_NoPadding extends OidImpl { + public AES256_OFB_NoPadding() { + super(32, "OFB", "NOPADDING"); + } + } + public static final class AES128_CFB_NoPadding extends OidImpl { + public AES128_CFB_NoPadding() { + super(16, "CFB", "NOPADDING"); + } + } + public static final class AES192_CFB_NoPadding extends OidImpl { + public AES192_CFB_NoPadding() { + super(24, "CFB", "NOPADDING"); + } + } + public static final class AES256_CFB_NoPadding extends OidImpl { + public AES256_CFB_NoPadding() { + super(32, "CFB", "NOPADDING"); + } + } + + // utility method used by AESCipher and AESWrapCipher + static final void checkKeySize(Key key, int fixedKeySize) + throws InvalidKeyException { + if (fixedKeySize != -1) { + if (key == null) { + throw new InvalidKeyException("The key must not be null"); + } + byte[] value = key.getEncoded(); + if (value == null) { + throw new InvalidKeyException("Key encoding must not be null"); + } else if (value.length != fixedKeySize) { + throw new InvalidKeyException("The key must be " + + fixedKeySize*8 + " bits"); + } + } + } + /* * internal CipherCore object which does the real work. */ private CipherCore core = null; + /* + * needed to support AES oids which associates a fixed key size + * to the cipher object. + */ + private final int fixedKeySize; // in bytes, -1 if no restriction + /** * Creates an instance of AES cipher with default ECB mode and * PKCS5Padding. */ - public AESCipher() { + protected AESCipher(int keySize) { core = new CipherCore(new AESCrypt(), AESConstants.AES_BLOCK_SIZE); + fixedKeySize = keySize; } /** @@ -183,6 +287,7 @@ public final class AESCipher extends CipherSpi { */ protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException { + checkKeySize(key, fixedKeySize); core.init(opmode, key, random); } @@ -214,6 +319,7 @@ public final class AESCipher extends CipherSpi { AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { + checkKeySize(key, fixedKeySize); core.init(opmode, key, params, random); } @@ -221,6 +327,7 @@ public final class AESCipher extends CipherSpi { AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { + checkKeySize(key, fixedKeySize); core.init(opmode, key, params, random); } diff --git a/src/share/classes/com/sun/crypto/provider/AESWrapCipher.java b/src/share/classes/com/sun/crypto/provider/AESWrapCipher.java index 21327dd09f7688cf0e6b270086bf7f38df0ea68d..29a22ad64b64476554cbde14a00c968c1e5f20c8 100644 --- a/src/share/classes/com/sun/crypto/provider/AESWrapCipher.java +++ b/src/share/classes/com/sun/crypto/provider/AESWrapCipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,8 +43,27 @@ import javax.crypto.spec.*; * * @see AESCipher */ -public final class AESWrapCipher extends CipherSpi { - +abstract class AESWrapCipher extends CipherSpi { + public static final class General extends AESWrapCipher { + public General() { + super(-1); + } + } + public static final class AES128 extends AESWrapCipher { + public AES128() { + super(16); + } + } + public static final class AES192 extends AESWrapCipher { + public AES192() { + super(24); + } + } + public static final class AES256 extends AESWrapCipher { + public AES256() { + super(32); + } + } private static final byte[] IV = { (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6 @@ -62,12 +81,20 @@ public final class AESWrapCipher extends CipherSpi { */ private boolean decrypting = false; + /* + * needed to support AES oids which associates a fixed key size + * to the cipher object. + */ + private final int fixedKeySize; // in bytes, -1 if no restriction + /** * Creates an instance of AES KeyWrap cipher with default * mode, i.e. "ECB" and padding scheme, i.e. "NoPadding". */ - public AESWrapCipher() { + public AESWrapCipher(int keySize) { cipher = new AESCrypt(); + fixedKeySize = keySize; + } /** @@ -170,6 +197,7 @@ public final class AESWrapCipher extends CipherSpi { throw new UnsupportedOperationException("This cipher can " + "only be used for key wrapping and unwrapping"); } + AESCipher.checkKeySize(key, fixedKeySize); cipher.init(decrypting, key.getAlgorithm(), key.getEncoded()); } diff --git a/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java b/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java index 1813bf260e9cd25dbaef8172d82d56b5001c60d5..533d80d49af2d5f08517e90cb37b6758e43aa223 100644 --- a/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java +++ b/src/share/classes/com/sun/crypto/provider/DHKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,10 +80,10 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi { * @param random the source of randomness */ public void initialize(int keysize, SecureRandom random) { - if ((keysize < 512) || (keysize > 1024) || (keysize % 64 != 0)) { + if ((keysize < 512) || (keysize > 2048) || (keysize % 64 != 0)) { throw new InvalidParameterException("Keysize must be multiple " + "of 64, and can only range " - + "from 512 to 1024 " + + "from 512 to 2048 " + "(inclusive)"); } this.pSize = keysize; @@ -115,11 +115,11 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi { params = (DHParameterSpec)algParams; pSize = params.getP().bitLength(); - if ((pSize < 512) || (pSize > 1024) || + if ((pSize < 512) || (pSize > 2048) || (pSize % 64 != 0)) { throw new InvalidAlgorithmParameterException ("Prime size must be multiple of 64, and can only range " - + "from 512 to 1024 (inclusive)"); + + "from 512 to 2048 (inclusive)"); } // exponent size is optional, could be 0 @@ -156,10 +156,11 @@ public final class DHKeyPairGenerator extends KeyPairGeneratorSpi { BigInteger g = params.getG(); if (lSize <= 0) { + lSize = pSize >> 1; // use an exponent size of (pSize / 2) but at least 384 bits - lSize = Math.max(384, pSize >> 1); - // if lSize is larger than pSize, limit by pSize - lSize = Math.min(lSize, pSize); + if (lSize < 384) { + lSize = 384; + } } BigInteger x; diff --git a/src/share/classes/com/sun/crypto/provider/DHParameterGenerator.java b/src/share/classes/com/sun/crypto/provider/DHParameterGenerator.java index 0d2eec7c776b4aee1b3caf1b7140988b40d5250d..0088729d27d47b7249bb160d3a530d1776312d2d 100644 --- a/src/share/classes/com/sun/crypto/provider/DHParameterGenerator.java +++ b/src/share/classes/com/sun/crypto/provider/DHParameterGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -67,10 +67,10 @@ extends AlgorithmParameterGeneratorSpi { * @param random the source of randomness */ protected void engineInit(int keysize, SecureRandom random) { - if ((keysize < 512) || (keysize > 1024) || (keysize % 64 != 0)) { + if ((keysize < 512) || (keysize > 2048) || (keysize % 64 != 0)) { throw new InvalidParameterException("Keysize must be multiple " + "of 64, and can only range " - + "from 512 to 1024 " + + "from 512 to 2048 " + "(inclusive)"); } this.primeSize = keysize; @@ -99,10 +99,10 @@ extends AlgorithmParameterGeneratorSpi { DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec; primeSize = dhParamSpec.getPrimeSize(); - if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) { + if ((primeSize<512) || (primeSize>2048) || (primeSize%64 != 0)) { throw new InvalidAlgorithmParameterException ("Modulus size must be multiple of 64, and can only range " - + "from 512 to 1024 (inclusive)"); + + "from 512 to 2048 (inclusive)"); } exponentSize = dhParamSpec.getExponentSize(); diff --git a/src/share/classes/com/sun/crypto/provider/SunJCE.java b/src/share/classes/com/sun/crypto/provider/SunJCE.java index e7a815283b51a2ce1b8babdec93e889234223b80..925343e51f037def42f5294e8fa585b19861b503 100644 --- a/src/share/classes/com/sun/crypto/provider/SunJCE.java +++ b/src/share/classes/com/sun/crypto/provider/SunJCE.java @@ -167,17 +167,67 @@ public final class SunJCE extends Provider { put("Cipher.Blowfish SupportedPaddings", BLOCK_PADS); put("Cipher.Blowfish SupportedKeyFormats", "RAW"); - put("Cipher.AES", "com.sun.crypto.provider.AESCipher"); + put("Cipher.AES", "com.sun.crypto.provider.AESCipher$General"); put("Alg.Alias.Cipher.Rijndael", "AES"); put("Cipher.AES SupportedModes", BLOCK_MODES128); put("Cipher.AES SupportedPaddings", BLOCK_PADS); put("Cipher.AES SupportedKeyFormats", "RAW"); - put("Cipher.AESWrap", "com.sun.crypto.provider.AESWrapCipher"); + put("Cipher.AES_128/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_ECB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.1", "AES_128/ECB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.1", "AES_128/ECB/NoPadding"); + put("Cipher.AES_128/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_CBC_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.2", "AES_128/CBC/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.2", "AES_128/CBC/NoPadding"); + put("Cipher.AES_128/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_OFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.3", "AES_128/OFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.3", "AES_128/OFB/NoPadding"); + put("Cipher.AES_128/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES128_CFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.4", "AES_128/CFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.4", "AES_128/CFB/NoPadding"); + + put("Cipher.AES_192/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_ECB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.21", "AES_192/ECB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.21", "AES_192/ECB/NoPadding"); + put("Cipher.AES_192/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_CBC_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.22", "AES_192/CBC/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.22", "AES_192/CBC/NoPadding"); + put("Cipher.AES_192/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_OFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.23", "AES_192/OFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.23", "AES_192/OFB/NoPadding"); + put("Cipher.AES_192/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES192_CFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.24", "AES_192/CFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.24", "AES_192/CFB/NoPadding"); + + + put("Cipher.AES_256/ECB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_ECB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.41", "AES_256/ECB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.41", "AES_256/ECB/NoPadding"); + put("Cipher.AES_256/CBC/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_CBC_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.42", "AES_256/CBC/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.42", "AES_256/CBC/NoPadding"); + put("Cipher.AES_256/OFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_OFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.43", "AES_256/OFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.43", "AES_256/OFB/NoPadding"); + put("Cipher.AES_256/CFB/NoPadding", "com.sun.crypto.provider.AESCipher$AES256_CFB_NoPadding"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.44", "AES_256/CFB/NoPadding"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.44", "AES_256/CFB/NoPadding"); + + put("Cipher.AESWrap", "com.sun.crypto.provider.AESWrapCipher$General"); put("Cipher.AESWrap SupportedModes", "ECB"); put("Cipher.AESWrap SupportedPaddings", "NOPADDING"); put("Cipher.AESWrap SupportedKeyFormats", "RAW"); + put("Cipher.AESWrap_128", "com.sun.crypto.provider.AESWrapCipher$AES128"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.5", "AESWrap_128"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.5", "AESWrap_128"); + put("Cipher.AESWrap_192", "com.sun.crypto.provider.AESWrapCipher$AES192"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.25", "AESWrap_192"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.25", "AESWrap_192"); + put("Cipher.AESWrap_256", "com.sun.crypto.provider.AESWrapCipher$AES256"); + put("Alg.Alias.Cipher.2.16.840.1.101.3.4.1.45", "AESWrap_256"); + put("Alg.Alias.Cipher.OID.2.16.840.1.101.3.4.1.45", "AESWrap_256"); + put("Cipher.RC2", "com.sun.crypto.provider.RC2Cipher"); put("Cipher.RC2 SupportedModes", BLOCK_MODES); @@ -192,7 +242,7 @@ public final class SunJCE extends Provider { put("Cipher.ARCFOUR SupportedKeyFormats", "RAW"); /* - * Key(pair) Generator engines + * Key(pair) Generator engines */ put("KeyGenerator.DES", "com.sun.crypto.provider.DESKeyGenerator"); @@ -221,6 +271,8 @@ public final class SunJCE extends Provider { put("KeyGenerator.HmacSHA1", "com.sun.crypto.provider.HmacSHA1KeyGenerator"); + put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.7", "HmacSHA1"); + put("Alg.Alias.KeyGenerator.1.2.840.113549.2.7", "HmacSHA1"); put("KeyGenerator.HmacSHA224", "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA224"); @@ -326,14 +378,12 @@ public final class SunJCE extends Provider { "com.sun.crypto.provider.AESParameters"); put("Alg.Alias.AlgorithmParameters.Rijndael", "AES"); - put("AlgorithmParameters.RC2", "com.sun.crypto.provider.RC2Parameters"); put("AlgorithmParameters.OAEP", "com.sun.crypto.provider.OAEPParameters"); - /* * Key factories */ @@ -403,6 +453,8 @@ public final class SunJCE extends Provider { */ put("Mac.HmacMD5", "com.sun.crypto.provider.HmacMD5"); put("Mac.HmacSHA1", "com.sun.crypto.provider.HmacSHA1"); + put("Alg.Alias.Mac.OID.1.2.840.113549.2.7", "HmacSHA1"); + put("Alg.Alias.Mac.1.2.840.113549.2.7", "HmacSHA1"); put("Mac.HmacSHA224", "com.sun.crypto.provider.HmacCore$HmacSHA224"); put("Alg.Alias.Mac.OID.1.2.840.113549.2.8", "HmacSHA224"); diff --git a/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java b/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java index a4a298261359c5592b3d3268b298be95b8cc6e25..78754b5c72b44acbf5b92ef305643ba6a73f727c 100644 --- a/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java +++ b/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java @@ -883,7 +883,7 @@ class PackageWriter extends BandStructure { avHiBits &= (1L< defMap = allLayouts.get(i); - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) Map.Entry[] layoutsAndCounts = new Map.Entry[defMap.size()]; defMap.entrySet().toArray(layoutsAndCounts); diff --git a/src/share/classes/com/sun/management/VMOption.java b/src/share/classes/com/sun/management/VMOption.java index 48ce0d956b2090b6bc048638394e8a9b5459cf7a..96530072fff4c1fe27279d90201f5da7409cc43d 100644 --- a/src/share/classes/com/sun/management/VMOption.java +++ b/src/share/classes/com/sun/management/VMOption.java @@ -178,7 +178,7 @@ public class VMOption { return "VM option: " + getName() + " value: " + value + " " + " origin: " + origin + " " + - (writeable ? "(read-only)" : "(read-write)"); + (writeable ? "(read-write)" : "(read-only)"); } /** diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java b/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java index 308d517a2c47f6f4bb5091725ca1bebab0317604..d1ebe5fc730502dd1a2cd81ea1bc03d36145f8d6 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/Init.java @@ -153,8 +153,8 @@ public final class Init { break; } } - for (Node el=config.getFirstChild();el!=null;el=el.getNextSibling()) { - if (!(el instanceof Element)) { + for (Node el=config.getFirstChild();el!=null;el=el.getNextSibling()) { + if (el.getNodeType() != Node.ELEMENT_NODE) { continue; } String tag=el.getLocalName(); diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java index 77024c23403e7703f4af64bedcee83270424be8b..2f5f28904d201966daf089e668960caa62fb5a8c 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/implementations/CanonicalizerBase.java @@ -205,7 +205,7 @@ public abstract class CanonicalizerBase extends CanonicalizerSpi { try { NameSpaceSymbTable ns=new NameSpaceSymbTable(); int nodeLevel=NODE_BEFORE_DOCUMENT_ELEMENT; - if (rootNode instanceof Element) { + if (rootNode != null && rootNode.getNodeType() == Node.ELEMENT_NODE) { //Fills the nssymbtable with the definitions of the parent of the root subnode getParentNameSpaces((Element)rootNode,ns); nodeLevel=NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT; @@ -335,7 +335,7 @@ public abstract class CanonicalizerBase extends CanonicalizerSpi { return; sibling=parentNode.getNextSibling(); parentNode=parentNode.getParentNode(); - if (!(parentNode instanceof Element)) { + if (parentNode !=null && parentNode.getNodeType() != Node.ELEMENT_NODE) { documentLevel=NODE_AFTER_DOCUMENT_ELEMENT; parentNode=null; } @@ -391,7 +391,7 @@ public abstract class CanonicalizerBase extends CanonicalizerSpi { return; boolean currentNodeIsVisible = false; NameSpaceSymbTable ns=new NameSpaceSymbTable(); - if (currentNode instanceof Element) + if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) getParentNameSpaces((Element)currentNode,ns); Node sibling=null; Node parentNode=null; @@ -512,7 +512,7 @@ public abstract class CanonicalizerBase extends CanonicalizerSpi { return; sibling=parentNode.getNextSibling(); parentNode=parentNode.getParentNode(); - if (!(parentNode instanceof Element)) { + if (parentNode != null && parentNode.getNodeType() != Node.ELEMENT_NODE) { parentNode=null; documentLevel=NODE_AFTER_DOCUMENT_ELEMENT; } @@ -594,18 +594,14 @@ public abstract class CanonicalizerBase extends CanonicalizerSpi { final void getParentNameSpaces(Element el,NameSpaceSymbTable ns) { List parents=new ArrayList(10); Node n1=el.getParentNode(); - if (!(n1 instanceof Element)) { + if (n1 == null || n1.getNodeType() != Node.ELEMENT_NODE) { return; } //Obtain all the parents of the elemnt - Element parent=(Element) n1; - while (parent!=null) { - parents.add(parent); - Node n=parent.getParentNode(); - if (!(n instanceof Element )) { - break; - } - parent=(Element)n; + Node parent = n1; + while (parent!=null && parent.getNodeType() == Node.ELEMENT_NODE) { + parents.add((Element)parent); + parent = parent.getParentNode(); } //Visit them in reverse order. ListIterator it=parents.listIterator(parents.size()); diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java b/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java index 8479835c901b80e0e287bcf432bcc5395061bb1e..b8be1a505ed35aacb458fd515352e41b6da09c11 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java @@ -1445,7 +1445,7 @@ public class XMLCipher { // The de-serialiser returns a fragment whose children we need to // take on. - if (sourceParent instanceof Document) { + if (sourceParent != null && sourceParent.getNodeType() == Node.DOCUMENT_NODE) { // If this is a content decryption, this may have problems diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java b/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java index 80674426281400324ada70ad15881315f3c5f4b2..fec12b3b1bf5422f315d54ff51507c05ea4b8adc 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/keys/keyresolver/implementations/RetrievalMethodResolver.java @@ -283,7 +283,7 @@ public class RetrievalMethodResolver extends KeyResolverSpi { Element e=null; while (it.hasNext()) { Node currentNode=it.next(); - if (currentNode instanceof Element) { + if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) { e=(Element)currentNode; break; } @@ -292,14 +292,14 @@ public class RetrievalMethodResolver extends KeyResolverSpi { List parents=new ArrayList(10); //Obtain all the parents of the elemnt - do { + while (e != null) { parents.add(e); Node n=e.getParentNode(); - if (!(n instanceof Element )) { + if (n == null || n.getNodeType() != Node.ELEMENT_NODE) { break; } e=(Element)n; - } while (e!=null); + } //Visit them in reverse order. ListIterator it2=parents.listIterator(parents.size()-1); Element ele=null; diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java b/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java index 2fba84559687d56f3a5078b1af070a95157a2378..4ee51ac92ab69456362cfb0aa5c5ed7abf49c62c 100644 --- a/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java @@ -225,7 +225,7 @@ public class IdResolver { } while (sibling==null && parentNode!=null) { sibling=parentNode.getNextSibling(); parentNode=parentNode.getParentNode(); - if (!(parentNode instanceof Element)) { + if (parentNode != null && parentNode.getNodeType() != Node.ELEMENT_NODE) { parentNode=null; } } diff --git a/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java b/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java index f2a72f6a4adb5bbb5ad9e29ad2697009d8dde9b7..36612ad80804503f1947ac969a496457d4aad9a4 100644 --- a/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java +++ b/src/share/classes/com/sun/rowset/JdbcRowSetImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,6 @@ import javax.naming.*; import java.io.*; import java.math.*; import java.util.*; -import java.beans.*; import javax.sql.rowset.*; @@ -83,12 +82,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { */ private ResultSetMetaData resMD; - /** - * The property that helps to fire the property changed event when certain - * properties are changed in the JdbcRowSet object. This property - * is being added to satisfy Rave requirements. - */ - private PropertyChangeSupport propertyChangeSupport; /** * The Vector holding the Match Columns @@ -145,7 +138,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { throw new RuntimeException(ioe); } - propertyChangeSupport = new PropertyChangeSupport(this); initParams(); @@ -268,7 +260,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { throw new RuntimeException(ioe); } - propertyChangeSupport = new PropertyChangeSupport(this); initParams(); // set the defaults @@ -343,7 +334,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { throw new RuntimeException(ioe); } - propertyChangeSupport = new PropertyChangeSupport(this); initParams(); @@ -360,10 +350,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { setMaxRows(0); setMaxFieldSize(0); - // to ensure connection to a db call connect now - // and associate a conn with "this" object - // in this case. - conn = connect(); setParams(); setReadOnly(true); @@ -435,7 +421,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { throw new RuntimeException(ioe); } - propertyChangeSupport = new PropertyChangeSupport(this); initParams(); @@ -620,12 +605,7 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { } - // An alternate solution is required instead of having the - // connect method as protected. - // This is a work around to assist Rave Team - // :ah - - protected Connection connect() throws SQLException { + private Connection connect() throws SQLException { // Get a JDBC connection. @@ -4056,9 +4036,7 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { // Added as per Rave requirements if( conn.getHoldability() != HOLD_CURSORS_OVER_COMMIT) { - ResultSet oldVal = rs; rs = null; - // propertyChangeSupport.firePropertyChange("ResultSet",oldVal,rs); } } @@ -4119,9 +4097,7 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { // Makes the result ste handle null after rollback // Added as per Rave requirements - ResultSet oldVal = rs; rs = null; - // propertyChangeSupport.firePropertyChange("ResultSet", oldVal,rs); } @@ -4247,12 +4223,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { rs = resultSet; } - - // Over riding the setCommand from BaseRowSet for - // firing the propertyChangeSupport Event for - // Rave requirements when this property's value - // changes. - /** * Sets this JdbcRowSet object's command property to * the given String object and clears the parameters, if any, @@ -4277,28 +4247,19 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { * @see #getCommand */ public void setCommand(String command) throws SQLException { - String oldVal; if (getCommand() != null) { if(!getCommand().equals(command)) { - oldVal = getCommand(); super.setCommand(command); ps = null; rs = null; - propertyChangeSupport.firePropertyChange("command", oldVal,command); } } else { super.setCommand(command); - propertyChangeSupport.firePropertyChange("command", null,command); } } - // Over riding the setDataSourceName from BaseRowSet for - // firing the propertyChangeSupport Event for - // Rave requirements when this property's values - // changes. - /** * Sets the dataSourceName property for this JdbcRowSet * object to the given logical name and sets this JdbcRowSet object's @@ -4329,28 +4290,20 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { * @see #getDataSourceName */ public void setDataSourceName(String dsName) throws SQLException{ - String oldVal; if(getDataSourceName() != null) { if(!getDataSourceName().equals(dsName)) { - oldVal = getDataSourceName(); super.setDataSourceName(dsName); conn = null; ps = null; rs = null; - propertyChangeSupport.firePropertyChange("dataSourceName",oldVal,dsName); } } else { super.setDataSourceName(dsName); - propertyChangeSupport.firePropertyChange("dataSourceName",null,dsName); } } - // Over riding the setUrl from BaseRowSet for - // firing the propertyChangeSupport Event for - // Rave requirements when this property's values - // changes. /** * Sets the Url property for this JdbcRowSet object @@ -4394,29 +4347,20 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { */ public void setUrl(String url) throws SQLException { - String oldVal; if(getUrl() != null) { if(!getUrl().equals(url)) { - oldVal = getUrl(); super.setUrl(url); conn = null; ps = null; rs = null; - propertyChangeSupport.firePropertyChange("url", oldVal, url); } } else { super.setUrl(url); - propertyChangeSupport.firePropertyChange("url", null, url); } } - // Over riding the setUsername from BaseRowSet for - // firing the propertyChangeSupport Event for - // Rave requirements when this property's values - // changes. - /** * Sets the username property for this JdbcRowSet object * to the given user name. Because it @@ -4438,29 +4382,20 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { * @see #getUsername */ public void setUsername(String uname) { - String oldVal; if( getUsername() != null) { if(!getUsername().equals(uname)) { - oldVal = getUsername(); super.setUsername(uname); conn = null; ps = null; rs = null; - propertyChangeSupport.firePropertyChange("username",oldVal,uname); } } else{ super.setUsername(uname); - propertyChangeSupport.firePropertyChange("username",null,uname); } } - // Over riding the setPassword from BaseRowSet for - // firing the propertyChangeSupport Event for - // Rave requirements when this property's values - // changes. - /** * Sets the password property for this JdbcRowSet object * to the given String object. Because it @@ -4481,21 +4416,17 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { * that must be supplied to the database to create a connection */ public void setPassword(String password) { - String oldVal; if ( getPassword() != null) { if(!getPassword().equals(password)) { - oldVal = getPassword(); super.setPassword(password); conn = null; ps = null; rs = null; - propertyChangeSupport.firePropertyChange("password",oldVal,password); } } else{ super.setPassword(password); - propertyChangeSupport.firePropertyChange("password",null,password); } } @@ -4528,7 +4459,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { if(oldVal != type) { super.setType(type); - propertyChangeSupport.firePropertyChange("type",oldVal,type); } } @@ -4561,78 +4491,6 @@ public class JdbcRowSetImpl extends BaseRowSet implements JdbcRowSet, Joinable { if(oldVal != concur) { super.setConcurrency(concur); - propertyChangeSupport.firePropertyChange("concurrency",oldVal,concur); - } - - } - - /** - * Sets the transaction isolation property for this JDBC RowSet object to the given - * constant. The DBMS will use this transaction isolation level for - * transactions if it can. - *

- * For RowSet implementations such as - * the CachedRowSet that operate in a disconnected environment, - * the SyncProvider object being used - * offers complementary locking and data integrity options. The - * options described below are pertinent only to connected RowSet - * objects (JdbcRowSet objects). - * - * @param transIso one of the following constants, listed in ascending order: - * Connection.TRANSACTION_NONE, - * Connection.TRANSACTION_READ_UNCOMMITTED, - * Connection.TRANSACTION_READ_COMMITTED, - * Connection.TRANSACTION_REPEATABLE_READ, or - * Connection.TRANSACTION_SERIALIZABLE - * @throws SQLException if the given parameter is not one of the Connection - * constants - * @see javax.sql.rowset.spi.SyncFactory - * @see javax.sql.rowset.spi.SyncProvider - * @see #getTransactionIsolation - */ - public void setTransactionIsolation(int transIso) throws SQLException { - - int oldVal; - - try { - oldVal = getTransactionIsolation(); - }catch(NullPointerException ex) { - oldVal = 0; - } - - if(oldVal != transIso) { - super.setTransactionIsolation(transIso); - propertyChangeSupport.firePropertyChange("transactionIsolation",oldVal,transIso); - } - - } - - /** - * Sets the maximum number of rows that this RowSet object may contain to - * the given number. If this limit is exceeded, the excess rows are - * silently dropped. - * - * @param mRows an int indicating the current maximum number - * of rows; zero means that there is no limit - * @throws SQLException if an error occurs internally setting the - * maximum limit on the number of rows that a JDBC RowSet object - * can contain; or if max is less than 0; or - * if max is less than the fetchSize of the - * RowSet - */ - public void setMaxRows(int mRows) throws SQLException { - - int oldVal; - - try { - oldVal = getMaxRows(); - }catch(NullPointerException ex) { - oldVal = 0; - } - - if(oldVal != mRows) { - super.setMaxRows(mRows); - propertyChangeSupport.firePropertyChange("maxRows",oldVal,mRows); } } diff --git a/src/share/classes/java/awt/AWTEvent.java b/src/share/classes/java/awt/AWTEvent.java index 87469980e6d44c9190ef1e33ff822fb501e41578..65ebcd3aad263120310dd67c5cd2f20275f75404 100644 --- a/src/share/classes/java/awt/AWTEvent.java +++ b/src/share/classes/java/awt/AWTEvent.java @@ -35,8 +35,6 @@ import sun.util.logging.PlatformLogger; import java.security.AccessControlContext; import java.security.AccessController; -import java.io.ObjectInputStream; -import java.io.IOException; /** * The root event class for all AWT events. @@ -262,9 +260,11 @@ public abstract class AWTEvent extends EventObject { public void setPosted(AWTEvent ev) { ev.isPosted = true; } + public void setSystemGenerated(AWTEvent ev) { ev.isSystemGenerated = true; } + public boolean isSystemGenerated(AWTEvent ev) { return ev.isSystemGenerated; } @@ -272,6 +272,15 @@ public abstract class AWTEvent extends EventObject { public AccessControlContext getAccessControlContext(AWTEvent ev) { return ev.getAccessControlContext(); } + + public byte[] getBData(AWTEvent ev) { + return ev.bdata; + } + + public void setBData(AWTEvent ev, byte[] bdata) { + ev.bdata = bdata; + } + }); } diff --git a/src/share/classes/java/awt/CheckboxMenuItem.java b/src/share/classes/java/awt/CheckboxMenuItem.java index 27fd3d6e21de76a88affb35b3abbcd618492e215..635e9b55b89607eaf47c96c60d3902d124eeb842 100644 --- a/src/share/classes/java/awt/CheckboxMenuItem.java +++ b/src/share/classes/java/awt/CheckboxMenuItem.java @@ -31,6 +31,7 @@ import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; import javax.accessibility.*; +import sun.awt.AWTAccessor; /** @@ -68,6 +69,13 @@ public class CheckboxMenuItem extends MenuItem implements ItemSelectable, Access if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setCheckboxMenuItemAccessor( + new AWTAccessor.CheckboxMenuItemAccessor() { + public boolean getState(CheckboxMenuItem cmi) { + return cmi.state; + } + }); } /** diff --git a/src/share/classes/java/awt/Component.java b/src/share/classes/java/awt/Component.java index df80032a1a983c31ef51a740672d79c2228db722..6fc78b15487f34b8fccc33aab6c585b7eac612b2 100644 --- a/src/share/classes/java/awt/Component.java +++ b/src/share/classes/java/awt/Component.java @@ -150,7 +150,7 @@ import sun.util.logging.PlatformLogger; * import java.awt.event.*; * import java.io.Serializable; * - * class MyApp java.io.Serializable + * class MyApp implements java.io.Serializable * { * BigObjectThatShouldNotBeSerializedWithAButton bigOne; * Button aButton = new Button(); diff --git a/src/share/classes/java/awt/Cursor.java b/src/share/classes/java/awt/Cursor.java index a84f769360665d9d028be880ddc0a9d80ee20f54..c340532b20da1f49d052b921a99f90c796f86b82 100644 --- a/src/share/classes/java/awt/Cursor.java +++ b/src/share/classes/java/awt/Cursor.java @@ -24,10 +24,6 @@ */ package java.awt; -import java.awt.AWTException; -import java.awt.Point; -import java.awt.Toolkit; - import java.io.File; import java.io.FileInputStream; @@ -39,6 +35,7 @@ import java.util.StringTokenizer; import java.security.AccessController; import sun.util.logging.PlatformLogger; +import sun.awt.AWTAccessor; /** * A class to encapsulate the bitmap representation of the mouse cursor. @@ -199,6 +196,21 @@ public class Cursor implements java.io.Serializable { if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setCursorAccessor( + new AWTAccessor.CursorAccessor() { + public long getPData(Cursor cursor) { + return cursor.pData; + } + + public void setPData(Cursor cursor, long pData) { + cursor.pData = pData; + } + + public int getType(Cursor cursor) { + return cursor.type; + } + }); } /** diff --git a/src/share/classes/java/awt/DefaultKeyboardFocusManager.java b/src/share/classes/java/awt/DefaultKeyboardFocusManager.java index 109e70d9d8a69eea661f02f06e60ee0ef6c6c6c1..a5132464ceb1ae28a7abdfc468d948ba9e265a46 100644 --- a/src/share/classes/java/awt/DefaultKeyboardFocusManager.java +++ b/src/share/classes/java/awt/DefaultKeyboardFocusManager.java @@ -39,6 +39,7 @@ import sun.util.logging.PlatformLogger; import sun.awt.AppContext; import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; import sun.awt.CausedFocusEvent; /** @@ -75,6 +76,15 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager { typeAheadMarkers = new LinkedList(); private boolean consumeNextKeyTyped; + static { + AWTAccessor.setDefaultKeyboardFocusManagerAccessor( + new AWTAccessor.DefaultKeyboardFocusManagerAccessor() { + public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e) { + dkfm.consumeNextKeyTyped(e); + } + }); + } + private static class TypeAheadMarker { long after; Component untilFocused; diff --git a/src/share/classes/java/awt/EventQueue.java b/src/share/classes/java/awt/EventQueue.java index 86ea84af8304d26a1c9dfa84e73df1c840614b2f..747cbc8600bd4dc9d55609f445c5fc5841183de2 100644 --- a/src/share/classes/java/awt/EventQueue.java +++ b/src/share/classes/java/awt/EventQueue.java @@ -36,6 +36,8 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.EmptyStackException; + +import sun.awt.dnd.SunDropTargetEvent; import sun.util.logging.PlatformLogger; import sun.awt.AppContext; @@ -50,7 +52,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.atomic.AtomicInteger; import java.security.AccessControlContext; -import java.security.ProtectionDomain; import sun.misc.SharedSecrets; import sun.misc.JavaSecurityAccess; @@ -186,6 +187,17 @@ public class EventQueue { public boolean isDispatchThreadImpl(EventQueue eventQueue) { return eventQueue.isDispatchThreadImpl(); } + public void removeSourceEvents(EventQueue eventQueue, + Object source, + boolean removeAllEvents) { + eventQueue.removeSourceEvents(source, removeAllEvents); + } + public boolean noEvents(EventQueue eventQueue) { + return eventQueue.noEvents(); + } + public void wakeup(EventQueue eventQueue, boolean isShutdown) { + eventQueue.wakeup(isShutdown); + } }); } @@ -464,7 +476,9 @@ public class EventQueue { case MouseEvent.MOUSE_MOVED: return MOVE; case MouseEvent.MOUSE_DRAGGED: - return DRAG; + // Return -1 for SunDropTargetEvent since they are usually synchronous + // and we don't want to skip them by coalescing with MouseEvent or other drag events + return e instanceof SunDropTargetEvent ? -1 : DRAG; default: return e instanceof PeerEvent ? PEER : -1; } diff --git a/src/share/classes/java/awt/KeyboardFocusManager.java b/src/share/classes/java/awt/KeyboardFocusManager.java index 15fe15356c200cc77623c089ab7ee0cb82006010..8c0cc884779c1fe722d7ebd460ccd69fe00de9aa 100644 --- a/src/share/classes/java/awt/KeyboardFocusManager.java +++ b/src/share/classes/java/awt/KeyboardFocusManager.java @@ -56,7 +56,6 @@ import java.util.WeakHashMap; import sun.util.logging.PlatformLogger; import sun.awt.AppContext; -import sun.awt.HeadlessToolkit; import sun.awt.SunToolkit; import sun.awt.CausedFocusEvent; import sun.awt.KeyboardFocusManagerPeerProvider; @@ -148,6 +147,9 @@ public abstract class KeyboardFocusManager public KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx) { return KeyboardFocusManager.getCurrentKeyboardFocusManager(ctx); } + public Container getCurrentFocusCycleRoot() { + return KeyboardFocusManager.currentFocusCycleRoot; + } } ); } diff --git a/src/share/classes/java/awt/Menu.java b/src/share/classes/java/awt/Menu.java index 1eb9fe050f1fb7c8cc1e13f15a4f49def40d258a..e702a9cb8fde0971efa4f37692f93f14de9104c1 100644 --- a/src/share/classes/java/awt/Menu.java +++ b/src/share/classes/java/awt/Menu.java @@ -31,6 +31,7 @@ import java.util.Enumeration; import java.awt.peer.MenuPeer; import java.awt.event.KeyEvent; import javax.accessibility.*; +import sun.awt.AWTAccessor; /** * A Menu object is a pull-down menu component @@ -62,6 +63,13 @@ public class Menu extends MenuItem implements MenuContainer, Accessible { if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setMenuAccessor( + new AWTAccessor.MenuAccessor() { + public Vector getItems(Menu menu) { + return menu.items; + } + }); } /** diff --git a/src/share/classes/java/awt/MenuBar.java b/src/share/classes/java/awt/MenuBar.java index 021c4b361220c913b066274a99a68d8a44579525..1fd442e1583dbd6cd7437481e6c98c268f45e380 100644 --- a/src/share/classes/java/awt/MenuBar.java +++ b/src/share/classes/java/awt/MenuBar.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.util.Vector; import java.util.Enumeration; +import sun.awt.AWTAccessor; import java.awt.peer.MenuBarPeer; import java.awt.event.KeyEvent; import javax.accessibility.*; @@ -74,6 +75,16 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + AWTAccessor.setMenuBarAccessor( + new AWTAccessor.MenuBarAccessor() { + public Menu getHelpMenu(MenuBar menuBar) { + return menuBar.helpMenu; + } + + public Vector getMenus(MenuBar menuBar) { + return menuBar.menus; + } + }); } /** diff --git a/src/share/classes/java/awt/MenuComponent.java b/src/share/classes/java/awt/MenuComponent.java index ab3fe0eba57c64216fae2ad63136cb157cd8ba2c..ebd9c0576baf5b20937b8994bc6f194563cd7be1 100644 --- a/src/share/classes/java/awt/MenuComponent.java +++ b/src/share/classes/java/awt/MenuComponent.java @@ -29,7 +29,6 @@ import java.awt.event.ActionEvent; import java.io.IOException; import java.io.ObjectInputStream; import sun.awt.AppContext; -import sun.awt.SunToolkit; import sun.awt.AWTAccessor; import javax.accessibility.*; @@ -143,6 +142,9 @@ public abstract class MenuComponent implements java.io.Serializable { public MenuContainer getParent(MenuComponent menuComp) { return menuComp.parent; } + public Font getFont_NoClientCode(MenuComponent menuComp) { + return menuComp.getFont_NoClientCode(); + } }); } diff --git a/src/share/classes/java/awt/MenuItem.java b/src/share/classes/java/awt/MenuItem.java index b9700e17d0fb6cd1bd4086c87ba6463b70fbefd0..3b8b2cffa0ee64fea7cefef638c1f6e19b87d8fb 100644 --- a/src/share/classes/java/awt/MenuItem.java +++ b/src/share/classes/java/awt/MenuItem.java @@ -31,7 +31,7 @@ import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; import javax.accessibility.*; - +import sun.awt.AWTAccessor; /** * All items in a menu must belong to the class @@ -76,6 +76,29 @@ public class MenuItem extends MenuComponent implements Accessible { if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setMenuItemAccessor( + new AWTAccessor.MenuItemAccessor() { + public boolean isEnabled(MenuItem item) { + return item.enabled; + } + + public String getLabel(MenuItem item) { + return item.label; + } + + public MenuShortcut getShortcut(MenuItem item) { + return item.shortcut; + } + + public String getActionCommandImpl(MenuItem item) { + return item.getActionCommandImpl(); + } + + public boolean isItemEnabled(MenuItem item) { + return item.isItemEnabled(); + } + }); } /** diff --git a/src/share/classes/java/awt/SystemTray.java b/src/share/classes/java/awt/SystemTray.java index ff629f90b9a1b88ca12b08283122d4196fbbaba9..444f85fa320a5b18fb786ef22850e9ee966ba24c 100644 --- a/src/share/classes/java/awt/SystemTray.java +++ b/src/share/classes/java/awt/SystemTray.java @@ -33,6 +33,7 @@ import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.awt.HeadlessToolkit; import sun.security.util.SecurityConstants; +import sun.awt.AWTAccessor; /** * The SystemTray class represents the system tray for a @@ -127,6 +128,18 @@ public class SystemTray { private static final TrayIcon[] EMPTY_TRAY_ARRAY = new TrayIcon[0]; + static { + AWTAccessor.setSystemTrayAccessor( + new AWTAccessor.SystemTrayAccessor() { + public void firePropertyChange(SystemTray tray, + String propertyName, + Object oldValue, + Object newValue) { + tray.firePropertyChange(propertyName, oldValue, newValue); + } + }); + } + /** * Private SystemTray constructor. * diff --git a/src/share/classes/java/awt/TrayIcon.java b/src/share/classes/java/awt/TrayIcon.java index c6e40af9dbb932ccc7a8c7f0246429bfbe255999..9835216198e79fff9a1c6d318dadafddf0050593 100644 --- a/src/share/classes/java/awt/TrayIcon.java +++ b/src/share/classes/java/awt/TrayIcon.java @@ -25,19 +25,11 @@ package java.awt; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.GraphicsEnvironment; import java.awt.event.*; -import java.awt.AWTEvent; -import java.awt.AWTEventMulticaster; -import java.awt.EventQueue; -import java.awt.PopupMenu; -import java.awt.Image; -import java.util.EventListener; import java.awt.peer.TrayIconPeer; import sun.awt.AppContext; import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; import sun.awt.HeadlessToolkit; import java.util.EventObject; import java.security.AccessControlContext; @@ -129,6 +121,16 @@ public class TrayIcon { if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setTrayIconAccessor( + new AWTAccessor.TrayIconAccessor() { + public void addNotify(TrayIcon trayIcon) throws AWTException { + trayIcon.addNotify(); + } + public void removeNotify(TrayIcon trayIcon) { + trayIcon.removeNotify(); + } + }); } private TrayIcon() diff --git a/src/share/classes/java/awt/event/KeyEvent.java b/src/share/classes/java/awt/event/KeyEvent.java index ac6f745d5eea4b0cc2639061c497e38b2448d658..ac7c7e57a122aea15934da91e00bab137dd1757c 100644 --- a/src/share/classes/java/awt/event/KeyEvent.java +++ b/src/share/classes/java/awt/event/KeyEvent.java @@ -25,12 +25,12 @@ package java.awt.event; -import java.awt.Event; import java.awt.Component; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.io.IOException; import java.io.ObjectInputStream; +import sun.awt.AWTAccessor; /** * An event which indicates that a keystroke occurred in a component. @@ -914,6 +914,23 @@ public class KeyEvent extends InputEvent { if (!GraphicsEnvironment.isHeadless()) { initIDs(); } + + AWTAccessor.setKeyEventAccessor( + new AWTAccessor.KeyEventAccessor() { + public void setRawCode(KeyEvent ev, long rawCode) { + ev.rawCode = rawCode; + } + + public void setPrimaryLevelUnicode(KeyEvent ev, + long primaryLevelUnicode) { + ev.primaryLevelUnicode = primaryLevelUnicode; + } + + public void setExtendedKeyCode(KeyEvent ev, + long extendedKeyCode) { + ev.extendedKeyCode = extendedKeyCode; + } + }); } /** diff --git a/src/share/classes/java/beans/PropertyDescriptor.java b/src/share/classes/java/beans/PropertyDescriptor.java index cccbf1c5839c5ca5372fbf9bc82677cfab2106cf..91e17e38aa7b532a1388f302677594b091a8e75a 100644 --- a/src/share/classes/java/beans/PropertyDescriptor.java +++ b/src/share/classes/java/beans/PropertyDescriptor.java @@ -657,7 +657,7 @@ public class PropertyDescriptor extends FeatureDescriptor { throw new IntrospectionException("bad write method arg count: " + writeMethod); } - if (propertyType != null && propertyType != params[0]) { + if (propertyType != null && !params[0].isAssignableFrom(propertyType)) { throw new IntrospectionException("type mismatch between read and write methods"); } propertyType = params[0]; diff --git a/src/share/classes/java/io/FilePermission.java b/src/share/classes/java/io/FilePermission.java index a5781f3fb00a82a956f621660219452ed95893a2..b2ba8bdf7523dd0036be3e84798689313a5c6099 100644 --- a/src/share/classes/java/io/FilePermission.java +++ b/src/share/classes/java/io/FilePermission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,10 +31,6 @@ import java.util.List; import java.util.ArrayList; import java.util.Vector; import java.util.Collections; -import java.io.ObjectStreamField; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.IOException; import sun.security.util.SecurityConstants; /** @@ -424,7 +420,7 @@ public final class FilePermission extends Permission implements Serializable { /** * Converts an actions String to an actions mask. * - * @param action the action string. + * @param actions the action string. * @return the actions mask. */ private static int getMask(String actions) { @@ -435,7 +431,9 @@ public final class FilePermission extends Permission implements Serializable { if (actions == null) { return mask; } - // Check against use of constants (used heavily within the JDK) + + // Use object identity comparison against known-interned strings for + // performance benefit (these values are used heavily within the JDK). if (actions == SecurityConstants.FILE_READ_ACTION) { return READ; } else if (actions == SecurityConstants.FILE_WRITE_ACTION) { @@ -531,7 +529,7 @@ public final class FilePermission extends Permission implements Serializable { switch(a[i-matchlen]) { case ',': seencomma = true; - /*FALLTHROUGH*/ + break; case ' ': case '\r': case '\n': case '\f': case '\t': break; @@ -798,7 +796,7 @@ implements Serializable { * @return an enumeration of all the FilePermission objects. */ - public Enumeration elements() { + public Enumeration elements() { // Convert Iterator into Enumeration synchronized (this) { return Collections.enumeration(perms); @@ -843,7 +841,6 @@ implements Serializable { /* * Reads in a Vector of FilePermissions and saves them in the perms field. */ - @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // Don't call defaultReadObject() @@ -852,6 +849,7 @@ implements Serializable { ObjectInputStream.GetField gfields = in.readFields(); // Get the one we want + @SuppressWarnings("unchecked") Vector permissions = (Vector)gfields.get("permissions", null); perms = new ArrayList<>(permissions.size()); perms.addAll(permissions); diff --git a/src/share/classes/java/lang/reflect/Constructor.java b/src/share/classes/java/lang/reflect/Constructor.java index fbf300b7fac34dfb57051cab3dc67d0c4adb3870..d84e373a7b50d7ee7c2836e38f22f858940a3a35 100644 --- a/src/share/classes/java/lang/reflect/Constructor.java +++ b/src/share/classes/java/lang/reflect/Constructor.java @@ -182,7 +182,7 @@ public final class Constructor extends Executable { * @since 1.5 */ @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public TypeVariable>[] getTypeParameters() { if (getSignature() != null) { return (TypeVariable>[])getGenericInfo().getTypeParameters(); diff --git a/src/share/classes/java/lang/reflect/Method.java b/src/share/classes/java/lang/reflect/Method.java index b940e23de42bd2b7bd98c309a2c36f8c27b2e7b6..068d864e96e861c0ab6f59c1d71c5ab7363a900b 100644 --- a/src/share/classes/java/lang/reflect/Method.java +++ b/src/share/classes/java/lang/reflect/Method.java @@ -194,7 +194,7 @@ public final class Method extends Executable { * @since 1.5 */ @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public TypeVariable[] getTypeParameters() { if (getGenericSignature() != null) return (TypeVariable[])getGenericInfo().getTypeParameters(); diff --git a/src/share/classes/java/net/SocketPermission.java b/src/share/classes/java/net/SocketPermission.java index b20563bc9dc63f87b01b1e12e88e4ce821c7ff03..da9abee01f644c47dee9e1c3cbd6da88c0adaa94 100644 --- a/src/share/classes/java/net/SocketPermission.java +++ b/src/share/classes/java/net/SocketPermission.java @@ -467,7 +467,6 @@ implements java.io.Serializable * @param action the action string * @return the action mask */ - @SuppressWarnings("fallthrough") private static int getMask(String action) { if (action == null) { @@ -480,7 +479,8 @@ implements java.io.Serializable int mask = NONE; - // Check against use of constants (used heavily within the JDK) + // Use object identity comparison against known-interned strings for + // performance benefit (these values are used heavily within the JDK). if (action == SecurityConstants.SOCKET_RESOLVE_ACTION) { return RESOLVE; } else if (action == SecurityConstants.SOCKET_CONNECT_ACTION) { @@ -568,7 +568,7 @@ implements java.io.Serializable switch(a[i-matchlen]) { case ',': seencomma = true; - /*FALLTHROUGH*/ + break; case ' ': case '\r': case '\n': case '\f': case '\t': break; diff --git a/src/share/classes/java/nio/channels/AsynchronousFileChannel.java b/src/share/classes/java/nio/channels/AsynchronousFileChannel.java index c47ba4255a9a5c5d2b82ffc75de21090c3462409..ba24eb113cfe8e5a749452f2202f6c0ce07f0f85 100644 --- a/src/share/classes/java/nio/channels/AsynchronousFileChannel.java +++ b/src/share/classes/java/nio/channels/AsynchronousFileChannel.java @@ -248,7 +248,7 @@ public abstract class AsynchronousFileChannel return provider.newAsynchronousFileChannel(file, options, executor, attrs); } - @SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction + @SuppressWarnings({"unchecked", "rawtypes"}) // generic array construction private static final FileAttribute[] NO_ATTRIBUTES = new FileAttribute[0]; /** diff --git a/src/share/classes/java/nio/channels/FileChannel.java b/src/share/classes/java/nio/channels/FileChannel.java index 1a6dc5fec85f964612ae59d6e9e9a6ee61b0c56c..f18f03e39c9fc05594eed9faaf63b3392b88d056 100644 --- a/src/share/classes/java/nio/channels/FileChannel.java +++ b/src/share/classes/java/nio/channels/FileChannel.java @@ -287,7 +287,7 @@ public abstract class FileChannel return provider.newFileChannel(path, options, attrs); } - @SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction + @SuppressWarnings({"unchecked", "rawtypes"}) // generic array construction private static final FileAttribute[] NO_ATTRIBUTES = new FileAttribute[0]; /** diff --git a/src/share/classes/java/security/interfaces/DSAKeyPairGenerator.java b/src/share/classes/java/security/interfaces/DSAKeyPairGenerator.java index d86bbbc6a4e7bbd897fb1dd8007ad833c8d7a877..96a091ef84a8d46e7a6ae06d47bf3cafe1cff399 100644 --- a/src/share/classes/java/security/interfaces/DSAKeyPairGenerator.java +++ b/src/share/classes/java/security/interfaces/DSAKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,6 +62,9 @@ import java.security.*; * interface is all that is needed when you accept defaults for algorithm-specific * parameters. * + *

Note: Some earlier implementations of this interface may not support + * larger sizes of DSA parameters such as 2048 and 3072-bit. + * * @see java.security.KeyPairGenerator */ public interface DSAKeyPairGenerator { @@ -78,7 +81,7 @@ public interface DSAKeyPairGenerator { * can be null. * * @exception InvalidParameterException if the params - * value is invalid or null. + * value is invalid, null, or unsupported. */ public void initialize(DSAParams params, SecureRandom random) throws InvalidParameterException; @@ -97,7 +100,7 @@ public interface DSAKeyPairGenerator { * default parameters for modulus lengths of 512 and 1024 bits. * * @param modlen the modulus length in bits. Valid values are any - * multiple of 8 between 512 and 1024, inclusive. + * multiple of 64 between 512 and 1024, inclusive, 2048, and 3072. * * @param random the random bit source to use to generate key bits; * can be null. @@ -105,10 +108,9 @@ public interface DSAKeyPairGenerator { * @param genParams whether or not to generate new parameters for * the modulus length requested. * - * @exception InvalidParameterException if modlen is not - * between 512 and 1024, or if genParams is false and - * there are no precomputed parameters for the requested modulus - * length. + * @exception InvalidParameterException if modlen is + * invalid, or unsupported, or if genParams is false and there + * are no precomputed parameters for the requested modulus length. */ public void initialize(int modlen, boolean genParams, SecureRandom random) throws InvalidParameterException; diff --git a/src/share/classes/java/security/spec/DSAGenParameterSpec.java b/src/share/classes/java/security/spec/DSAGenParameterSpec.java new file mode 100644 index 0000000000000000000000000000000000000000..a354c4807acfee0fcbb4461e69cd524cb32be5ed --- /dev/null +++ b/src/share/classes/java/security/spec/DSAGenParameterSpec.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. 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 java.security.spec; + +/** + * This immutable class specifies the set of parameters used for + * generating DSA parameters as specified in + * FIPS 186-3 Digital Signature Standard (DSS). + * + * @see AlgorithmParameterSpec + * + * @since 8 + */ +public final class DSAGenParameterSpec implements AlgorithmParameterSpec { + + private final int pLen; + private final int qLen; + private final int seedLen; + + /** + * Creates a domain parameter specification for DSA parameter + * generation using primePLen and subprimeQLen. + * The value of subprimeQLen is also used as the default + * length of the domain parameter seed in bits. + * @param primePLen the desired length of the prime P in bits. + * @param subprimeQLen the desired length of the sub-prime Q in bits. + * @exception IllegalArgumentException if primePLen + * or subprimeQLen is illegal per the specification of + * FIPS 186-3. + */ + public DSAGenParameterSpec(int primePLen, int subprimeQLen) { + this(primePLen, subprimeQLen, subprimeQLen); + } + + /** + * Creates a domain parameter specification for DSA parameter + * generation using primePLen, subprimeQLen, + * and seedLen. + * @param primePLen the desired length of the prime P in bits. + * @param subprimeQLen the desired length of the sub-prime Q in bits. + * @param seedLen the desired length of the domain parameter seed in bits, + * shall be equal to or greater than subprimeQLen. + * @exception IllegalArgumentException if primePLenLen, + * subprimeQLen, or seedLen is illegal per the + * specification of FIPS 186-3. + */ + public DSAGenParameterSpec(int primePLen, int subprimeQLen, int seedLen) { + switch (primePLen) { + case 1024: + if (subprimeQLen != 160) { + throw new IllegalArgumentException + ("subprimeQLen must be 160 when primePLen=1024"); + } + break; + case 2048: + if (subprimeQLen != 224 && subprimeQLen != 256) { + throw new IllegalArgumentException + ("subprimeQLen must be 224 or 256 when primePLen=2048"); + } + break; + case 3072: + if (subprimeQLen != 256) { + throw new IllegalArgumentException + ("subprimeQLen must be 256 when primePLen=3072"); + } + break; + default: + throw new IllegalArgumentException + ("primePLen must be 1024, 2048, or 3072"); + } + if (seedLen < subprimeQLen) { + throw new IllegalArgumentException + ("seedLen must be equal to or greater than subprimeQLen"); + } + this.pLen = primePLen; + this.qLen = subprimeQLen; + this.seedLen = seedLen; + } + + /** + * Returns the desired length of the prime P of the + * to-be-generated DSA domain parameters in bits. + * @return the length of the prime P. + */ + public int getPrimePLength() { + return pLen; + } + + /** + * Returns the desired length of the sub-prime Q of the + * to-be-generated DSA domain parameters in bits. + * @return the length of the sub-prime Q. + */ + public int getSubprimeQLength() { + return qLen; + } + + /** + * Returns the desired length of the domain parameter seed in bits. + * @return the length of the domain parameter seed. + */ + public int getSeedLength() { + return seedLen; + } +} diff --git a/src/share/classes/java/util/ArrayDeque.java b/src/share/classes/java/util/ArrayDeque.java index 8a9a0ee7b8b16665353d25581d28ba17efbf412f..476b223329856ae31ea3f9e8e2e84f2419b45c6b 100644 --- a/src/share/classes/java/util/ArrayDeque.java +++ b/src/share/classes/java/util/ArrayDeque.java @@ -121,6 +121,7 @@ public class ArrayDeque extends AbstractCollection * * @param numElements the number of elements to hold */ + @SuppressWarnings("unchecked") private void allocateElements(int numElements) { int initialCapacity = MIN_INITIAL_CAPACITY; // Find the best power of two to hold elements. @@ -152,10 +153,11 @@ public class ArrayDeque extends AbstractCollection int newCapacity = n << 1; if (newCapacity < 0) throw new IllegalStateException("Sorry, deque too big"); - Object[] a = new Object[newCapacity]; + @SuppressWarnings("unchecked") + E[] a = (E[]) new Object[newCapacity]; System.arraycopy(elements, p, a, 0, r); System.arraycopy(elements, 0, a, r, p); - elements = (E[])a; + elements = a; head = 0; tail = n; } @@ -182,6 +184,7 @@ public class ArrayDeque extends AbstractCollection * Constructs an empty array deque with an initial capacity * sufficient to hold 16 elements. */ + @SuppressWarnings("unchecked") public ArrayDeque() { elements = (E[]) new Object[16]; } @@ -793,6 +796,7 @@ public class ArrayDeque extends AbstractCollection * this deque * @throws NullPointerException if the specified array is null */ + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { int size = size(); if (a.length < size) diff --git a/src/share/classes/java/util/Arrays.java b/src/share/classes/java/util/Arrays.java index d0c3a60a05a41f50982c1871112d27657cf0b196..c4dde9bbedfd1cd330c650fe9fdb7041f1829ade 100644 --- a/src/share/classes/java/util/Arrays.java +++ b/src/share/classes/java/util/Arrays.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -560,7 +560,7 @@ public class Arrays { * off is the offset to generate corresponding low, high in src * To be removed in a future release. */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) private static void mergeSort(Object[] src, Object[] dest, int low, @@ -747,7 +747,7 @@ public class Arrays { * off is the offset into src corresponding to low in dest * To be removed in a future release. */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) private static void mergeSort(Object[] src, Object[] dest, int low, int high, int off, @@ -2832,6 +2832,7 @@ public class Arrays { * @return a list view of the specified array */ @SafeVarargs + @SuppressWarnings("varargs") public static List asList(T... a) { return new ArrayList<>(a); } diff --git a/src/share/classes/java/util/Collections.java b/src/share/classes/java/util/Collections.java index 533260326809ccf919f30c0c31eff90a20db657c..58eae6f950969366280567ddf9c3db7d2b597f5f 100644 --- a/src/share/classes/java/util/Collections.java +++ b/src/share/classes/java/util/Collections.java @@ -213,7 +213,7 @@ public class Collections { * @throws IllegalArgumentException (optional) if the comparator is * found to violate the {@link Comparator} contract */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) public static void sort(List list, Comparator c) { Object[] a = list.toArray(); Arrays.sort(a, (Comparator)c); @@ -418,7 +418,7 @@ public class Collections { * @throws UnsupportedOperationException if the specified list or * its list-iterator does not support the set operation. */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public static void reverse(List list) { int size = list.size(); if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) { @@ -497,7 +497,7 @@ public class Collections { * @throws UnsupportedOperationException if the specified list or its * list-iterator does not support the set operation. */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public static void shuffle(List list, Random rnd) { int size = list.size(); if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) { @@ -535,7 +535,7 @@ public class Collections { * || j < 0 || j >= list.size()). * @since 1.4 */ - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({"rawtypes", "unchecked"}) public static void swap(List list, int i, int j) { // instead of using a raw type here, it's possible to capture // the wildcard but it will require a call to a supplementary @@ -669,7 +669,7 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) public static T min(Collection coll, Comparator comp) { if (comp==null) return (T)min((Collection) coll); @@ -740,7 +740,7 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) public static T max(Collection coll, Comparator comp) { if (comp==null) return (T)max((Collection) coll); @@ -1403,7 +1403,7 @@ public class Collections { extends UnmodifiableSet> { private static final long serialVersionUID = 7854390611657943733L; - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) UnmodifiableEntrySet(Set> s) { // Need to cast to raw in order to work around a limitation in the type system super((Set)s); @@ -3172,7 +3172,7 @@ public class Collections { * * @see #emptySet() */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public static final Set EMPTY_SET = new EmptySet<>(); /** @@ -3271,10 +3271,13 @@ public class Collections { return new EmptySortedSet<>(); } - public Comparator comparator() { + @Override + public Comparator comparator() { return null; } + @Override + @SuppressWarnings("unchecked") public SortedSet subSet(Object fromElement, Object toElement) { Objects.requireNonNull(fromElement); Objects.requireNonNull(toElement); @@ -3294,6 +3297,7 @@ public class Collections { return emptySortedSet(); } + @Override public SortedSet headSet(Object toElement) { Objects.requireNonNull(toElement); @@ -3304,6 +3308,7 @@ public class Collections { return emptySortedSet(); } + @Override public SortedSet tailSet(Object fromElement) { Objects.requireNonNull(fromElement); @@ -3314,10 +3319,12 @@ public class Collections { return emptySortedSet(); } + @Override public E first() { throw new NoSuchElementException(); } + @Override public E last() { throw new NoSuchElementException(); } @@ -3328,7 +3335,7 @@ public class Collections { * * @see #emptyList() */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public static final List EMPTY_LIST = new EmptyList<>(); /** @@ -3402,7 +3409,7 @@ public class Collections { * @see #emptyMap() * @since 1.3 */ - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public static final Map EMPTY_MAP = new EmptyMap<>(); /** @@ -3685,6 +3692,7 @@ public class Collections { return a; } + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { final int n = this.n; if (a.length < n) { @@ -3731,6 +3739,7 @@ public class Collections { * the Comparable interface. * @see Comparable */ + @SuppressWarnings("unchecked") public static Comparator reverseOrder() { return (Comparator) ReverseComparator.REVERSE_ORDER; } diff --git a/src/share/classes/java/util/ComparableTimSort.java b/src/share/classes/java/util/ComparableTimSort.java index ae1ab6a1e817b30e5b3c2d324160cb76076802d2..dd7cb3a80ecb4a91fc8863635f58512941b0ba16 100644 --- a/src/share/classes/java/util/ComparableTimSort.java +++ b/src/share/classes/java/util/ComparableTimSort.java @@ -208,7 +208,7 @@ class ComparableTimSort { * @param start the index of the first element in the range that is * not already known to be sorted ({@code lo <= start <= hi}) */ - @SuppressWarnings({ "fallthrough", "rawtypes", "unchecked" }) + @SuppressWarnings({"fallthrough", "rawtypes", "unchecked"}) private static void binarySort(Object[] a, int lo, int hi, int start) { assert lo <= start && start <= hi; if (start == lo) @@ -277,7 +277,7 @@ class ComparableTimSort { * @return the length of the run beginning at the specified position in * the specified array */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) private static int countRunAndMakeAscending(Object[] a, int lo, int hi) { assert lo < hi; int runHi = lo + 1; @@ -612,7 +612,7 @@ class ComparableTimSort { * (must be aBase + aLen) * @param len2 length of second run to be merged (must be > 0) */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) private void mergeLo(int base1, int len1, int base2, int len2) { assert len1 > 0 && len2 > 0 && base1 + len1 == base2; @@ -729,7 +729,7 @@ class ComparableTimSort { * (must be aBase + aLen) * @param len2 length of second run to be merged (must be > 0) */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) private void mergeHi(int base1, int len1, int base2, int len2) { assert len1 > 0 && len2 > 0 && base1 + len1 == base2; diff --git a/src/share/classes/java/util/Currency.java b/src/share/classes/java/util/Currency.java index 11291d6b1e4670696355570550cfcddc68f32fe5..45e5747f069c79d382cd81707cfa08ea5a14a3b8 100644 --- a/src/share/classes/java/util/Currency.java +++ b/src/share/classes/java/util/Currency.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,6 +34,8 @@ import java.io.IOException; import java.io.Serializable; import java.security.AccessController; import java.security.PrivilegedAction; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.regex.Pattern; @@ -60,7 +62,14 @@ import sun.util.logging.PlatformLogger; * and the ISO 4217 currency data respectively. The value part consists of * three ISO 4217 values of a currency, i.e., an alphabetic code, a numeric * code, and a minor unit. Those three ISO 4217 values are separated by commas. - * The lines which start with '#'s are considered comment lines. For example, + * The lines which start with '#'s are considered comment lines. An optional UTC + * timestamp may be specified per currency entry if users need to specify a + * cutover date indicating when the new data comes into effect. The timestamp is + * appended to the end of the currency properties and uses a comma as a separator. + * If a UTC datestamp is present and valid, the JRE will only use the new currency + * properties if the current UTC date is later than the date specified at class + * loading time. The format of the timestamp must be of ISO 8601 format : + * {@code 'yyyy-MM-dd'T'HH:mm:ss'}. For example, *

* * #Sample currency properties
@@ -69,6 +78,20 @@ import sun.util.logging.PlatformLogger; *

* will supersede the currency data for Japan. * + *

+ * + * #Sample currency properties with cutover date
+ * JP=JPZ,999,0,2014-01-01T00:00:00 + *
+ *

+ * will supersede the currency data for Japan if {@code Currency} class is loaded after + * 1st January 2014 00:00:00 GMT. + *

+ * Where syntactically malformed entries are encountered, the entry is ignored + * and the remainder of entries in file are processed. For instances where duplicate + * country code entries exist, the behavior of the Currency information for that + * {@code Currency} is undefined and the remainder of entries in file are processed. + * * @since 1.4 */ public final class Currency implements Serializable { @@ -100,7 +123,6 @@ public final class Currency implements Serializable { private static ConcurrentMap instances = new ConcurrentHashMap<>(7); private static HashSet available; - // Class data: currency data obtained from currency.data file. // Purpose: // - determine valid country codes @@ -235,7 +257,9 @@ public final class Currency implements Serializable { } Set keys = props.stringPropertyNames(); Pattern propertiesPattern = - Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])"); + Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + + "([0-3])\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + + "\\d{2}:\\d{2})?"); for (String key : keys) { replaceCurrencyData(propertiesPattern, key.toUpperCase(Locale.ROOT), @@ -645,29 +669,38 @@ public final class Currency implements Serializable { * consists of "three-letter alphabet code", "three-digit numeric code", * and "one-digit (0,1,2, or 3) default fraction digit". * For example, "JPZ,392,0". - * @throws + * An optional UTC date can be appended to the string (comma separated) + * to allow a currency change take effect after date specified. + * For example, "JP=JPZ,999,0,2014-01-01T00:00:00" has no effect unless + * UTC time is past 1st January 2014 00:00:00 GMT. */ private static void replaceCurrencyData(Pattern pattern, String ctry, String curdata) { if (ctry.length() != 2) { // ignore invalid country code - String message = new StringBuilder() - .append("The entry in currency.properties for ") - .append(ctry).append(" is ignored because of the invalid country code.") - .toString(); - info(message, null); + info("currency.properties entry for " + ctry + + " is ignored because of the invalid country code.", null); return; } Matcher m = pattern.matcher(curdata); - if (!m.find()) { + if (!m.find() || (m.group(4) == null && countOccurrences(curdata, ',') >= 3)) { // format is not recognized. ignore the data - String message = new StringBuilder() - .append("The entry in currency.properties for ") - .append(ctry) - .append(" is ignored because the value format is not recognized.") - .toString(); - info(message, null); + // if group(4) date string is null and we've 4 values, bad date value + info("currency.properties entry for " + ctry + + " ignored because the value format is not recognized.", null); + return; + } + + try { + if (m.group(4) != null && !isPastCutoverDate(m.group(4))) { + info("currency.properties entry for " + ctry + + " ignored since cutover date has not passed :" + curdata, null); + return; + } + } catch (IndexOutOfBoundsException | NullPointerException | ParseException ex) { + info("currency.properties entry for " + ctry + + " ignored since exception encountered :" + ex.getMessage(), null); return; } @@ -695,6 +728,26 @@ public final class Currency implements Serializable { setMainTableEntry(ctry.charAt(0), ctry.charAt(1), entry); } + private static boolean isPastCutoverDate(String s) + throws IndexOutOfBoundsException, NullPointerException, ParseException { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + format.setLenient(false); + long time = format.parse(s.trim()).getTime(); + return System.currentTimeMillis() > time; + + } + + private static int countOccurrences(String value, char match) { + int count = 0; + for (char c : value.toCharArray()) { + if (c == match) { + ++count; + } + } + return count; + } + private static void info(String message, Throwable t) { PlatformLogger logger = PlatformLogger.getLogger("java.util.Currency"); if (logger.isLoggable(PlatformLogger.INFO)) { diff --git a/src/share/classes/java/util/HashMap.java b/src/share/classes/java/util/HashMap.java index 4687905e428ef22a2483cebc982a8accc8db6b7c..9990a6ef68c188b257d40791c87f388b02e96f25 100644 --- a/src/share/classes/java/util/HashMap.java +++ b/src/share/classes/java/util/HashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -230,7 +230,7 @@ public class HashMap this.loadFactor = loadFactor; threshold = (int)Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1); - table = new Entry[capacity]; + table = new Entry[capacity]; init(); } @@ -1078,7 +1078,7 @@ public class HashMap capacity <<= 1; } - table = new Entry[capacity]; + table = new Entry[capacity]; threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1); init(); // Give subclass a chance to do its thing. diff --git a/src/share/classes/java/util/JumboEnumSet.java b/src/share/classes/java/util/JumboEnumSet.java index 5db15bbdace54d1c1ad58cd6f643abfa9a4fdf5f..d2f3e83f7b1db1bfb6f10e1f1ff3dac7398d66aa 100644 --- a/src/share/classes/java/util/JumboEnumSet.java +++ b/src/share/classes/java/util/JumboEnumSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -121,6 +121,7 @@ class JumboEnumSet> extends EnumSet { unseen = elements[0]; } + @Override public boolean hasNext() { while (unseen == 0 && unseenIndex < elements.length - 1) unseen = elements[++unseenIndex]; @@ -128,6 +129,7 @@ class JumboEnumSet> extends EnumSet { } @Override + @SuppressWarnings("unchecked") public E next() { if (!hasNext()) throw new NoSuchElementException(); @@ -138,6 +140,7 @@ class JumboEnumSet> extends EnumSet { + Long.numberOfTrailingZeros(lastReturned)]; } + @Override public void remove() { if (lastReturned == 0) throw new IllegalStateException(); diff --git a/src/share/classes/java/util/PriorityQueue.java b/src/share/classes/java/util/PriorityQueue.java index bb9c114dd681f070e47a2a7fefbedab669f48c8d..dd67a0c5ba4d3c0908586443a3d86292873a82d3 100644 --- a/src/share/classes/java/util/PriorityQueue.java +++ b/src/share/classes/java/util/PriorityQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -330,6 +330,7 @@ public class PriorityQueue extends AbstractQueue return true; } + @SuppressWarnings("unchecked") public E peek() { if (size == 0) return null; diff --git a/src/share/classes/java/util/PropertyPermission.java b/src/share/classes/java/util/PropertyPermission.java index c89b28bf4d2425edd6a45e97f90ac3cabed54846..aed6f5c48c7709163f6986ae541bf5cfe6de53f8 100644 --- a/src/share/classes/java/util/PropertyPermission.java +++ b/src/share/classes/java/util/PropertyPermission.java @@ -246,7 +246,8 @@ public final class PropertyPermission extends BasicPermission { return mask; } - // Check against use of constants (used heavily within the JDK) + // Use object identity comparison against known-interned strings for + // performance benefit (these values are used heavily within the JDK). if (actions == SecurityConstants.PROPERTY_READ_ACTION) { return READ; } if (actions == SecurityConstants.PROPERTY_WRITE_ACTION) { diff --git a/src/share/classes/java/util/PropertyResourceBundle.java b/src/share/classes/java/util/PropertyResourceBundle.java index c7fe3b460a19be0b0c27841fe23c71282cf73d69..98ebd3b0f419241a4a3844133d42076d0bac0df3 100644 --- a/src/share/classes/java/util/PropertyResourceBundle.java +++ b/src/share/classes/java/util/PropertyResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -125,6 +125,7 @@ public class PropertyResourceBundle extends ResourceBundle { * @throws IOException if an I/O error occurs * @throws NullPointerException if stream is null */ + @SuppressWarnings({"unchecked", "rawtypes"}) public PropertyResourceBundle (InputStream stream) throws IOException { Properties properties = new Properties(); properties.load(stream); @@ -143,6 +144,7 @@ public class PropertyResourceBundle extends ResourceBundle { * @throws NullPointerException if reader is null * @since 1.6 */ + @SuppressWarnings({"unchecked", "rawtypes"}) public PropertyResourceBundle (Reader reader) throws IOException { Properties properties = new Properties(); properties.load(reader); diff --git a/src/share/classes/java/util/jar/JarVerifier.java b/src/share/classes/java/util/jar/JarVerifier.java index 5c80d5013db337c4be80e9dc80998dacc9f5953c..a455fb1f2f7c2786086734205aff87cfa2e2ed3b 100644 --- a/src/share/classes/java/util/jar/JarVerifier.java +++ b/src/share/classes/java/util/jar/JarVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -325,6 +325,7 @@ class JarVerifier { * the given file in the jar. * @deprecated */ + @Deprecated public java.security.cert.Certificate[] getCerts(String name) { return mapSignersToCertArray(getCodeSigners(name)); diff --git a/src/share/classes/java/util/jar/Pack200.java b/src/share/classes/java/util/jar/Pack200.java index bb7cc2b47fef6551ad7f9121bfe600fe2063c863..0f28a14b5272e35b6d3032483627c5d3a59fbf06 100644 --- a/src/share/classes/java/util/jar/Pack200.java +++ b/src/share/classes/java/util/jar/Pack200.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003,2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003,2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -726,13 +726,13 @@ public abstract class Pack200 { private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer"; private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker"; - private static Class packerImpl; - private static Class unpackerImpl; + private static Class packerImpl; + private static Class unpackerImpl; private synchronized static Object newInstance(String prop) { String implName = "(unknown)"; try { - Class impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl; + Class impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl; if (impl == null) { // The first time, we must decide which class to use. implName = java.security.AccessController.doPrivileged( diff --git a/src/share/classes/javax/swing/ClientPropertyKey.java b/src/share/classes/javax/swing/ClientPropertyKey.java index a58c4d955d3148c68246e548e2bffbef21328b8c..f51332def085a9c290b8c090a050cac006b05d34 100644 --- a/src/share/classes/javax/swing/ClientPropertyKey.java +++ b/src/share/classes/javax/swing/ClientPropertyKey.java @@ -25,6 +25,8 @@ package javax.swing; +import sun.awt.AWTAccessor; + /** * An enumeration for keys used as client properties within the Swing * implementation. @@ -86,6 +88,15 @@ enum ClientPropertyKey { */ private final boolean reportValueNotSerializable; + static { + AWTAccessor.setClientPropertyKeyAccessor( + new AWTAccessor.ClientPropertyKeyAccessor() { + public Object getJComponent_TRANSFER_HANDLER() { + return JComponent_TRANSFER_HANDLER; + } + }); + } + /** * Constructs a key with the {@code reportValueNotSerializable} property * set to {@code false}. diff --git a/src/share/classes/javax/swing/JTable.java b/src/share/classes/javax/swing/JTable.java index 17b6b23d1354ca4b07bf901dd48808ff975d4e6a..fbd61d9a9fc8adde300b1b4ba7294fb4aaaf9666 100644 --- a/src/share/classes/javax/swing/JTable.java +++ b/src/share/classes/javax/swing/JTable.java @@ -8590,7 +8590,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * null if this object is not on the screen */ public Point getLocationOnScreen() { - if (parent != null) { + if (parent != null && parent.isShowing()) { Point parentLocation = parent.getLocationOnScreen(); Point componentLocation = getLocation(); componentLocation.translate(parentLocation.x, parentLocation.y); @@ -9391,7 +9391,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * null if this object is not on the screen */ public Point getLocationOnScreen() { - if (parent != null) { + if (parent != null && parent.isShowing()) { Point parentLocation = parent.getLocationOnScreen(); Point componentLocation = getLocation(); componentLocation.translate(parentLocation.x, parentLocation.y); diff --git a/src/share/classes/sun/awt/AWTAccessor.java b/src/share/classes/sun/awt/AWTAccessor.java index 04a2799fe5f46f70351de649a2b300802e2b685a..0679f108f54969b831fa009d56b8bcb753795e73 100644 --- a/src/share/classes/sun/awt/AWTAccessor.java +++ b/src/share/classes/sun/awt/AWTAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,12 +29,15 @@ import sun.misc.Unsafe; import java.awt.*; import java.awt.KeyboardFocusManager; +import java.awt.DefaultKeyboardFocusManager; import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.awt.geom.Point2D; import java.awt.peer.ComponentPeer; import java.security.AccessControlContext; import java.io.File; +import java.util.Vector; /** * The AWTAccessor utility class. @@ -314,7 +317,7 @@ public final class AWTAccessor { void setTrayIconWindow(Window w, boolean isTrayIconWindow); } - /* + /** * An accessor for the AWTEvent class. */ public interface AWTEventAccessor { @@ -334,12 +337,20 @@ public final class AWTAccessor { */ boolean isSystemGenerated(AWTEvent ev); - - /* + /** * Returns the acc this event was constructed with. */ AccessControlContext getAccessControlContext(AWTEvent ev); + /** + * Returns binary data associated with this event; + */ + byte[] getBData(AWTEvent ev); + + /** + * Associates binary data with this event; + */ + void setBData(AWTEvent ev, byte[] bdata); } public interface InputEventAccessor { @@ -367,11 +378,11 @@ public final class AWTAccessor { Rectangle getMaximizedBounds(Frame frame); } - /* + /** * An interface of accessor for the java.awt.KeyboardFocusManager class. */ public interface KeyboardFocusManagerAccessor { - /* + /** * Indicates whether the native implementation should * proceed with a pending focus request for the heavyweight. */ @@ -381,7 +392,7 @@ public final class AWTAccessor { boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause); - /* + /** * Delivers focus for the lightweight descendant of the heavyweight * synchronously. */ @@ -390,23 +401,28 @@ public final class AWTAccessor { boolean temporary, boolean focusedWindowChangeAllowed, long time); - /* + /** * Removes the last focus request for the heavyweight from the queue. */ void removeLastFocusRequest(Component heavyweight); - /* + /** * Sets the most recent focus owner in the window. */ void setMostRecentFocusOwner(Window window, Component component); - /* + /** * Returns current KFM of the specified AppContext. */ KeyboardFocusManager getCurrentKeyboardFocusManager(AppContext ctx); + + /** + * Return the current focus cycle root + */ + Container getCurrentFocusCycleRoot(); } - /* + /** * An accessor for the MenuComponent class. */ public interface MenuComponentAccessor { @@ -424,20 +440,42 @@ public final class AWTAccessor { * Returns the menu container of the menu component */ MenuContainer getParent(MenuComponent menuComp); + + /** + * Gets the font used for this menu component. + */ + Font getFont_NoClientCode(MenuComponent menuComp); } - /* + /** * An accessor for the EventQueue class */ public interface EventQueueAccessor { - /* + /** * Gets the event dispatch thread. */ Thread getDispatchThread(EventQueue eventQueue); - /* + + /** * Checks if the current thread is EDT for the given EQ. */ public boolean isDispatchThreadImpl(EventQueue eventQueue); + + /** + * Removes any pending events for the specified source object. + */ + void removeSourceEvents(EventQueue eventQueue, Object source, boolean removeAllEvents); + + /** + * Returns whether an event is pending on any of the separate Queues. + */ + boolean noEvents(EventQueue eventQueue); + + /** + * Called from PostEventQueue.postEvent to notify that a new event + * appeared. + */ + void wakeup(EventQueue eventQueue, boolean isShutdown); } /* @@ -486,6 +524,148 @@ public final class AWTAccessor { final int type); } + /** + * An accessor for the CheckboxMenuItem class + */ + public interface CheckboxMenuItemAccessor { + /** + * Returns whether menu item is checked + */ + boolean getState(CheckboxMenuItem cmi); + } + + /** + * An accessor for the Cursor class + */ + public interface CursorAccessor { + /** + * Returns pData of the Cursor class + */ + long getPData(Cursor cursor); + + /** + * Sets pData to the Cursor class + */ + void setPData(Cursor cursor, long pData); + + /** + * Return type of the Cursor class + */ + int getType(Cursor cursor); + } + + /** + * An accessor for the MenuBar class + */ + public interface MenuBarAccessor { + /** + * Returns help menu + */ + Menu getHelpMenu(MenuBar menuBar); + + /** + * Returns menus + */ + Vector getMenus(MenuBar menuBar); + } + + /** + * An accessor for the MenuItem class + */ + public interface MenuItemAccessor { + /** + * Returns whether menu item is enabled + */ + boolean isEnabled(MenuItem item); + + /** + * Gets the command name of the action event that is fired + * by this menu item. + */ + String getActionCommandImpl(MenuItem item); + + /** + * Returns true if the item and all its ancestors are + * enabled, false otherwise + */ + boolean isItemEnabled(MenuItem item); + + /** + * Returns label + */ + String getLabel(MenuItem item); + + /** + * Returns shortcut + */ + MenuShortcut getShortcut(MenuItem item); + } + + /** + * An accessor for the Menu class + */ + public interface MenuAccessor { + /** + * Returns vector of the items that are part of the Menu + */ + Vector getItems(Menu menu); + } + + /** + * An accessor for the KeyEvent class + */ + public interface KeyEventAccessor { + /** + * Sets rawCode field for KeyEvent + */ + void setRawCode(KeyEvent ev, long rawCode); + + /** + * Sets primaryLevelUnicode field for KeyEvent + */ + void setPrimaryLevelUnicode(KeyEvent ev, long primaryLevelUnicode); + + /** + * Sets extendedKeyCode field for KeyEvent + */ + void setExtendedKeyCode(KeyEvent ev, long extendedKeyCode); + } + + /** + * An accessor for the ClientPropertyKey class + */ + public interface ClientPropertyKeyAccessor { + /** + * Retrieves JComponent_TRANSFER_HANDLER enum object + */ + Object getJComponent_TRANSFER_HANDLER(); + } + + /** + * An accessor for the SystemTray class + */ + public interface SystemTrayAccessor { + /** + * Support for reporting bound property changes for Object properties. + */ + void firePropertyChange(SystemTray tray, String propertyName, Object oldValue, Object newValue); + } + + /** + * An accessor for the TrayIcon class + */ + public interface TrayIconAccessor { + void addNotify(TrayIcon trayIcon) throws AWTException; + void removeNotify(TrayIcon trayIcon); + } + + /** + * An accessor for the DefaultKeyboardFocusManager class + */ + public interface DefaultKeyboardFocusManagerAccessor { + public void consumeNextKeyTyped(DefaultKeyboardFocusManager dkfm, KeyEvent e); + } + /* * Accessor instances are initialized in the static initializers of * corresponding AWT classes by using setters defined below. @@ -502,6 +682,16 @@ public final class AWTAccessor { private static PopupMenuAccessor popupMenuAccessor; private static FileDialogAccessor fileDialogAccessor; private static ScrollPaneAdjustableAccessor scrollPaneAdjustableAccessor; + private static CheckboxMenuItemAccessor checkboxMenuItemAccessor; + private static CursorAccessor cursorAccessor; + private static MenuBarAccessor menuBarAccessor; + private static MenuItemAccessor menuItemAccessor; + private static MenuAccessor menuAccessor; + private static KeyEventAccessor keyEventAccessor; + private static ClientPropertyKeyAccessor clientPropertyKeyAccessor; + private static SystemTrayAccessor systemTrayAccessor; + private static TrayIconAccessor trayIconAccessor; + private static DefaultKeyboardFocusManagerAccessor defaultKeyboardFocusManagerAccessor; /* * Set an accessor object for the java.awt.Component class. @@ -709,4 +899,174 @@ public final class AWTAccessor { } return scrollPaneAdjustableAccessor; } + + /** + * Set an accessor object for the java.awt.CheckboxMenuItem class. + */ + public static void setCheckboxMenuItemAccessor(CheckboxMenuItemAccessor cmia) { + checkboxMenuItemAccessor = cmia; + } + + /** + * Retrieve the accessor object for the java.awt.CheckboxMenuItem class. + */ + public static CheckboxMenuItemAccessor getCheckboxMenuItemAccessor() { + if (checkboxMenuItemAccessor == null) { + unsafe.ensureClassInitialized(CheckboxMenuItemAccessor.class); + } + return checkboxMenuItemAccessor; + } + + /** + * Set an accessor object for the java.awt.Cursor class. + */ + public static void setCursorAccessor(CursorAccessor ca) { + cursorAccessor = ca; + } + + /** + * Retrieve the accessor object for the java.awt.Cursor class. + */ + public static CursorAccessor getCursorAccessor() { + if (cursorAccessor == null) { + unsafe.ensureClassInitialized(CursorAccessor.class); + } + return cursorAccessor; + } + + /** + * Set an accessor object for the java.awt.MenuBar class. + */ + public static void setMenuBarAccessor(MenuBarAccessor mba) { + menuBarAccessor = mba; + } + + /** + * Retrieve the accessor object for the java.awt.MenuBar class. + */ + public static MenuBarAccessor getMenuBarAccessor() { + if (menuBarAccessor == null) { + unsafe.ensureClassInitialized(MenuBarAccessor.class); + } + return menuBarAccessor; + } + + /** + * Set an accessor object for the java.awt.MenuItem class. + */ + public static void setMenuItemAccessor(MenuItemAccessor mia) { + menuItemAccessor = mia; + } + + /** + * Retrieve the accessor object for the java.awt.MenuItem class. + */ + public static MenuItemAccessor getMenuItemAccessor() { + if (menuItemAccessor == null) { + unsafe.ensureClassInitialized(MenuItemAccessor.class); + } + return menuItemAccessor; + } + + /** + * Set an accessor object for the java.awt.Menu class. + */ + public static void setMenuAccessor(MenuAccessor ma) { + menuAccessor = ma; + } + + /** + * Retrieve the accessor object for the java.awt.Menu class. + */ + public static MenuAccessor getMenuAccessor() { + if (menuAccessor == null) { + unsafe.ensureClassInitialized(MenuAccessor.class); + } + return menuAccessor; + } + + /** + * Set an accessor object for the java.awt.event.KeyEvent class. + */ + public static void setKeyEventAccessor(KeyEventAccessor kea) { + keyEventAccessor = kea; + } + + /** + * Retrieve the accessor object for the java.awt.event.KeyEvent class. + */ + public static KeyEventAccessor getKeyEventAccessor() { + if (keyEventAccessor == null) { + unsafe.ensureClassInitialized(KeyEventAccessor.class); + } + return keyEventAccessor; + } + + /** + * Set an accessor object for the javax.swing.ClientPropertyKey class. + */ + public static void setClientPropertyKeyAccessor(ClientPropertyKeyAccessor cpka) { + clientPropertyKeyAccessor = cpka; + } + + /** + * Retrieve the accessor object for the javax.swing.ClientPropertyKey class. + */ + public static ClientPropertyKeyAccessor getClientPropertyKeyAccessor() { + if (clientPropertyKeyAccessor == null) { + unsafe.ensureClassInitialized(ClientPropertyKeyAccessor.class); + } + return clientPropertyKeyAccessor; + } + + /** + * Set an accessor object for the java.awt.SystemTray class. + */ + public static void setSystemTrayAccessor(SystemTrayAccessor sta) { + systemTrayAccessor = sta; + } + + /** + * Retrieve the accessor object for the java.awt.SystemTray class. + */ + public static SystemTrayAccessor getSystemTrayAccessor() { + if (systemTrayAccessor == null) { + unsafe.ensureClassInitialized(SystemTrayAccessor.class); + } + return systemTrayAccessor; + } + + /** + * Set an accessor object for the java.awt.TrayIcon class. + */ + public static void setTrayIconAccessor(TrayIconAccessor tia) { + trayIconAccessor = tia; + } + + /** + * Retrieve the accessor object for the java.awt.TrayIcon class. + */ + public static TrayIconAccessor getTrayIconAccessor() { + if (trayIconAccessor == null) { + unsafe.ensureClassInitialized(TrayIconAccessor.class); + } + return trayIconAccessor; + } + + /** + * Set an accessor object for the java.awt.DefaultKeyboardFocusManager class. + */ + public static void setDefaultKeyboardFocusManagerAccessor(DefaultKeyboardFocusManagerAccessor dkfma) { + defaultKeyboardFocusManagerAccessor = dkfma; + } + + /** + * Retrieve the accessor object for the java.awt.DefaultKeyboardFocusManager class. + */ + public static DefaultKeyboardFocusManagerAccessor getDefaultKeyboardFocusManagerAccessor() { + if (defaultKeyboardFocusManagerAccessor == null) { + unsafe.ensureClassInitialized(DefaultKeyboardFocusManagerAccessor.class); + } + return defaultKeyboardFocusManagerAccessor; + } } diff --git a/src/share/classes/sun/awt/EmbeddedFrame.java b/src/share/classes/sun/awt/EmbeddedFrame.java index 7d61c2b3aab3bdbb5800a0dac25e097fc5415ab6..d05e30fe742e6c611782acf15b1290b00631b3a4 100644 --- a/src/share/classes/sun/awt/EmbeddedFrame.java +++ b/src/share/classes/sun/awt/EmbeddedFrame.java @@ -29,12 +29,6 @@ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.peer.*; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.lang.reflect.Field; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.util.Set; @@ -66,8 +60,6 @@ public abstract class EmbeddedFrame extends Frame implements KeyEventDispatcher, PropertyChangeListener { private boolean isCursorAllowed = true; - private static Field fieldPeer; - private static Field currentCycleRoot; private boolean supportsXEmbed = false; private KeyboardFocusManager appletKFM; // JDK 1.1 compatibility @@ -213,39 +205,8 @@ public abstract class EmbeddedFrame extends Frame */ public boolean dispatchKeyEvent(KeyEvent e) { - // We can't guarantee that this is called on the same AppContext as EmbeddedFrame - // belongs to. That's why we can't use public methods to find current focus cycle - // root. Instead, we access KFM's private field directly. - if (currentCycleRoot == null) { - currentCycleRoot = AccessController.doPrivileged(new PrivilegedAction() { - public Field run() { - try { - Field unaccessibleRoot = KeyboardFocusManager.class. - getDeclaredField("currentFocusCycleRoot"); - if (unaccessibleRoot != null) { - unaccessibleRoot.setAccessible(true); - } - return unaccessibleRoot; - } catch (NoSuchFieldException e1) { - assert false; - } catch (SecurityException e2) { - assert false; - } - return null; - } - }); - } - - Container currentRoot = null; - if (currentCycleRoot != null) { - try { - // The field is static, so we can pass null to Field.get() as the argument. - currentRoot = (Container)currentCycleRoot.get(null); - } catch (IllegalAccessException e3) { - // This is impossible: currentCycleRoot would be null if setAccessible failed. - assert false; - } - } + Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor() + .getCurrentFocusCycleRoot(); // if we are not in EmbeddedFrame's cycle, we should not try to leave. if (this != currentRoot) { @@ -389,32 +350,8 @@ public abstract class EmbeddedFrame extends Frame @SuppressWarnings("deprecation") protected void setPeer(final ComponentPeer p){ - if (fieldPeer == null) { - fieldPeer = AccessController.doPrivileged(new PrivilegedAction() { - public Field run() { - try { - Field lnkPeer = Component.class.getDeclaredField("peer"); - if (lnkPeer != null) { - lnkPeer.setAccessible(true); - } - return lnkPeer; - } catch (NoSuchFieldException e) { - assert false; - } catch (SecurityException e) { - assert false; - } - return null; - }//run - }); - } - try{ - if (fieldPeer != null){ - fieldPeer.set(EmbeddedFrame.this, p); - } - } catch (IllegalAccessException e) { - assert false; - } - }; //setPeer method ends + AWTAccessor.getComponentAccessor().setPeer(EmbeddedFrame.this, p); + }; /** * Synthesize native message to activate or deactivate EmbeddedFrame window diff --git a/src/share/classes/sun/awt/SunToolkit.java b/src/share/classes/sun/awt/SunToolkit.java index 68ec628b6ed4cbf918be982bddb1b6182d639ea7..701f01b0ca8c30154fd23bef37c85a825a528105 100644 --- a/src/share/classes/sun/awt/SunToolkit.java +++ b/src/share/classes/sun/awt/SunToolkit.java @@ -51,14 +51,8 @@ import sun.awt.im.InputContext; import sun.awt.image.*; import sun.security.action.GetPropertyAction; import sun.security.action.GetBooleanAction; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; public abstract class SunToolkit extends Toolkit implements WindowClosingSupport, WindowClosingListener, @@ -80,7 +74,6 @@ public abstract class SunToolkit extends Toolkit */ public static final int GRAB_EVENT_MASK = 0x80000000; - private static Method wakeupMethod; /* The key to put()/get() the PostEventQueue into/from the AppContext. */ private static final String POST_EVENT_QUEUE_KEY = "PostEventQueue"; @@ -295,52 +288,8 @@ public abstract class SunToolkit extends Toolkit return appContext; } - public static Field getField(final Class klass, final String fieldName) { - return AccessController.doPrivileged(new PrivilegedAction() { - public Field run() { - try { - Field field = klass.getDeclaredField(fieldName); - assert (field != null); - field.setAccessible(true); - return field; - } catch (SecurityException e) { - assert false; - } catch (NoSuchFieldException e) { - assert false; - } - return null; - }//run - }); - } - static void wakeupEventQueue(EventQueue q, boolean isShutdown){ - if (wakeupMethod == null){ - wakeupMethod = AccessController.doPrivileged(new PrivilegedAction() { - public Method run() { - try { - Method method = EventQueue.class.getDeclaredMethod("wakeup",new Class [] {Boolean.TYPE} ); - if (method != null) { - method.setAccessible(true); - } - return method; - } catch (NoSuchMethodException e) { - assert false; - } catch (SecurityException e) { - assert false; - } - return null; - }//run - }); - } - try{ - if (wakeupMethod != null){ - wakeupMethod.invoke(q, new Object[]{Boolean.valueOf(isShutdown)}); - } - } catch (InvocationTargetException e){ - assert false; - } catch (IllegalAccessException e) { - assert false; - } + AWTAccessor.getEventQueueAccessor().wakeup(q, isShutdown); } /* @@ -1460,22 +1409,6 @@ public abstract class SunToolkit extends Toolkit || comp instanceof Window); } - public static Method getMethod(final Class clz, final String methodName, final Class[] params) { - Method res = null; - try { - res = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Method run() throws Exception { - Method m = clz.getDeclaredMethod(methodName, params); - m.setAccessible(true); - return m; - } - }); - } catch (PrivilegedActionException ex) { - ex.printStackTrace(); - } - return res; - } - @SuppressWarnings("serial") public static class OperationTimedOut extends RuntimeException { public OperationTimedOut(String msg) { @@ -1622,21 +1555,9 @@ public abstract class SunToolkit extends Toolkit private boolean queueEmpty = false; private final Object waitLock = "Wait Lock"; - static Method eqNoEvents; - private boolean isEQEmpty() { EventQueue queue = getSystemEventQueueImpl(); - synchronized(SunToolkit.class) { - if (eqNoEvents == null) { - eqNoEvents = getMethod(java.awt.EventQueue.class, "noEvents", null); - } - } - try { - return (Boolean)eqNoEvents.invoke(queue); - } catch (Exception e) { - e.printStackTrace(); - return false; - } + return AWTAccessor.getEventQueueAccessor().noEvents(queue); } /** @@ -1892,20 +1813,14 @@ public abstract class SunToolkit extends Toolkit * consumeNextKeyTyped() method is not currently used, * however Swing could use it in the future. */ - private static Method consumeNextKeyTypedMethod = null; public static synchronized void consumeNextKeyTyped(KeyEvent keyEvent) { - if (consumeNextKeyTypedMethod == null) { - consumeNextKeyTypedMethod = getMethod(DefaultKeyboardFocusManager.class, - "consumeNextKeyTyped", - new Class[] {KeyEvent.class}); - } try { - consumeNextKeyTypedMethod.invoke(KeyboardFocusManager.getCurrentKeyboardFocusManager(), - keyEvent); - } catch (IllegalAccessException iae) { - iae.printStackTrace(); - } catch (InvocationTargetException ite) { - ite.printStackTrace(); + AWTAccessor.getDefaultKeyboardFocusManagerAccessor().consumeNextKeyTyped( + (DefaultKeyboardFocusManager)KeyboardFocusManager. + getCurrentKeyboardFocusManager(), + keyEvent); + } catch (ClassCastException cce) { + cce.printStackTrace(); } } @@ -1925,24 +1840,6 @@ public abstract class SunToolkit extends Toolkit return (Window)comp; } - /** - * Returns the value of the system property indicated by the specified key. - */ - public static String getSystemProperty(final String key) { - return AccessController.doPrivileged(new PrivilegedAction() { - public String run() { - return System.getProperty(key); - } - }); - } - - /** - * Returns the boolean value of the system property indicated by the specified key. - */ - protected static Boolean getBooleanSystemProperty(String key) { - return AccessController.doPrivileged(new GetBooleanAction(key)); - } - private static Boolean sunAwtDisableMixing = null; /** @@ -1951,7 +1848,8 @@ public abstract class SunToolkit extends Toolkit */ public synchronized static boolean getSunAwtDisableMixing() { if (sunAwtDisableMixing == null) { - sunAwtDisableMixing = getBooleanSystemProperty("sun.awt.disableMixing"); + sunAwtDisableMixing = AccessController.doPrivileged( + new GetBooleanAction("sun.awt.disableMixing")); } return sunAwtDisableMixing.booleanValue(); } diff --git a/src/share/classes/sun/awt/TextureSizeConstraining.java b/src/share/classes/sun/awt/TextureSizeConstraining.java new file mode 100644 index 0000000000000000000000000000000000000000..306c3e762c088d55d639d8d94ec3d07cdf8b802e --- /dev/null +++ b/src/share/classes/sun/awt/TextureSizeConstraining.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. 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.awt; + +/** + * A GraphicsConfiguration implements the TextureSizeConstraining + * interface to indicate that it imposes certain limitations on the + * maximum size of supported textures. + */ +public interface TextureSizeConstraining { + + /** + * Returns the maximum width of any texture image. + */ + public int getMaxTextureWidth(); + + /** + * Returns the maximum height of any texture image. + */ + public int getMaxTextureHeight(); + +} diff --git a/src/share/classes/sun/security/ec/SunECEntries.java b/src/share/classes/sun/security/ec/SunECEntries.java index e359ccc79f1d09c627b7e313ec5803e68b03c6cc..fe810ee8abfce7653d3d0a4f585c0db3481b67bc 100644 --- a/src/share/classes/sun/security/ec/SunECEntries.java +++ b/src/share/classes/sun/security/ec/SunECEntries.java @@ -134,6 +134,9 @@ final class SunECEntries { "sun.security.ec.ECDSASignature$Raw"); map.put("Signature.SHA1withECDSA", "sun.security.ec.ECDSASignature$SHA1"); + map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.1", "SHA1withECDSA"); + map.put("Alg.Alias.Signature.1.2.840.10045.4.1", "SHA1withECDSA"); + map.put("Signature.SHA224withECDSA", "sun.security.ec.ECDSASignature$SHA224"); map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.1", "SHA224withECDSA"); diff --git a/src/share/classes/sun/security/pkcs11/P11Cipher.java b/src/share/classes/sun/security/pkcs11/P11Cipher.java index 8179dc016823d3680009efdb7209a2b0aee15e91..c7d62ff6b46c275a052546aadd16d0a14c8e4a71 100644 --- a/src/share/classes/sun/security/pkcs11/P11Cipher.java +++ b/src/share/classes/sun/security/pkcs11/P11Cipher.java @@ -164,6 +164,10 @@ final class P11Cipher extends CipherSpi { // if we do the padding private int bytesBuffered; + // length of key size in bytes; currently only used by AES given its oid + // specification mandates a fixed size of the key + private int fixedKeySize = -1; + P11Cipher(Token token, String algorithm, long mechanism) throws PKCS11Exception, NoSuchAlgorithmException { super(); @@ -172,19 +176,26 @@ final class P11Cipher extends CipherSpi { this.mechanism = mechanism; String algoParts[] = algorithm.split("/"); - keyAlgorithm = algoParts[0]; - if (keyAlgorithm.equals("AES")) { + if (algoParts[0].startsWith("AES")) { blockSize = 16; - } else if (keyAlgorithm.equals("RC4") || - keyAlgorithm.equals("ARCFOUR")) { - blockSize = 0; - } else { // DES, DESede, Blowfish - blockSize = 8; - } - this.blockMode = + int index = algoParts[0].indexOf('_'); + if (index != -1) { + // should be well-formed since we specify what we support + fixedKeySize = Integer.parseInt(algoParts[0].substring(index+1))/8; + } + keyAlgorithm = "AES"; + } else { + keyAlgorithm = algoParts[0]; + if (keyAlgorithm.equals("RC4") || + keyAlgorithm.equals("ARCFOUR")) { + blockSize = 0; + } else { // DES, DESede, Blowfish + blockSize = 8; + } + this.blockMode = (algoParts.length > 1 ? parseMode(algoParts[1]) : MODE_ECB); - + } String defPadding = (blockSize == 0 ? "NoPadding" : "PKCS5Padding"); String paddingStr = (algoParts.length > 2 ? algoParts[2] : defPadding); @@ -333,6 +344,9 @@ final class P11Cipher extends CipherSpi { SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { cancelOperation(); + if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) { + throw new InvalidKeyException("Key size is invalid"); + } switch (opmode) { case Cipher.ENCRYPT_MODE: encrypt = true; diff --git a/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/src/share/classes/sun/security/pkcs11/SunPKCS11.java index bac38137f16412ecb564c43939e508b62069fa73..d138d675a48d6330eedec1accf9bf19d1c7e3cad 100644 --- a/src/share/classes/sun/security/pkcs11/SunPKCS11.java +++ b/src/share/classes/sun/security/pkcs11/SunPKCS11.java @@ -399,12 +399,8 @@ public final class SunPKCS11 extends AuthProvider { return System.identityHashCode(this); } - private static String[] s(String s1) { - return new String[] {s1}; - } - - private static String[] s(String s1, String s2) { - return new String[] {s1, s2}; + private static String[] s(String ...aliases) { + return aliases; } private static final class Descriptor { @@ -521,7 +517,8 @@ public final class SunPKCS11 extends AuthProvider { m(CKM_MD2)); d(MD, "MD5", P11Digest, m(CKM_MD5)); - d(MD, "SHA1", P11Digest, s("SHA", "SHA-1"), + d(MD, "SHA1", P11Digest, + s("SHA", "SHA-1", "1.3.14.3.2.26", "OID.1.3.14.3.2.26"), m(CKM_SHA_1)); d(MD, "SHA-224", P11Digest, @@ -540,6 +537,7 @@ public final class SunPKCS11 extends AuthProvider { d(MAC, "HmacMD5", P11MAC, m(CKM_MD5_HMAC)); d(MAC, "HmacSHA1", P11MAC, + s("1.2.840.113549.2.7", "OID.1.2.840.113549.2.7"), m(CKM_SHA_1_HMAC)); d(MAC, "HmacSHA224", P11MAC, s("1.2.840.113549.2.8", "OID.1.2.840.113549.2.8"), @@ -561,6 +559,7 @@ public final class SunPKCS11 extends AuthProvider { d(KPG, "RSA", P11KeyPairGenerator, m(CKM_RSA_PKCS_KEY_PAIR_GEN)); d(KPG, "DSA", P11KeyPairGenerator, + s("1.3.14.3.2.12", "1.2.840.10040.4.1", "OID.1.2.840.10040.4.1"), m(CKM_DSA_KEY_PAIR_GEN)); d(KPG, "DH", P11KeyPairGenerator, s("DiffieHellman"), m(CKM_DH_PKCS_KEY_PAIR_GEN)); @@ -583,6 +582,7 @@ public final class SunPKCS11 extends AuthProvider { d(KF, "RSA", P11RSAKeyFactory, m(CKM_RSA_PKCS_KEY_PAIR_GEN, CKM_RSA_PKCS, CKM_RSA_X_509)); d(KF, "DSA", P11DSAKeyFactory, + s("1.3.14.3.2.12", "1.2.840.10040.4.1", "OID.1.2.840.10040.4.1"), m(CKM_DSA_KEY_PAIR_GEN, CKM_DSA, CKM_DSA_SHA1)); d(KF, "DH", P11DHKeyFactory, s("DiffieHellman"), m(CKM_DH_PKCS_KEY_PAIR_GEN, CKM_DH_PKCS_DERIVE)); @@ -609,6 +609,7 @@ public final class SunPKCS11 extends AuthProvider { d(SKF, "DESede", P11SecretKeyFactory, m(CKM_DES3_CBC)); d(SKF, "AES", P11SecretKeyFactory, + s("2.16.840.1.101.3.4.1", "OID.2.16.840.1.101.3.4.1"), m(CKM_AES_CBC)); d(SKF, "Blowfish", P11SecretKeyFactory, m(CKM_BLOWFISH_CBC)); @@ -635,10 +636,28 @@ public final class SunPKCS11 extends AuthProvider { m(CKM_DES3_ECB)); d(CIP, "AES/CBC/NoPadding", P11Cipher, m(CKM_AES_CBC)); + d(CIP, "AES_128/CBC/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.2", "OID.2.16.840.1.101.3.4.1.2"), + m(CKM_AES_CBC)); + d(CIP, "AES_192/CBC/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.22", "OID.2.16.840.1.101.3.4.1.22"), + m(CKM_AES_CBC)); + d(CIP, "AES_256/CBC/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.42", "OID.2.16.840.1.101.3.4.1.42"), + m(CKM_AES_CBC)); d(CIP, "AES/CBC/PKCS5Padding", P11Cipher, m(CKM_AES_CBC_PAD, CKM_AES_CBC)); d(CIP, "AES/ECB/NoPadding", P11Cipher, m(CKM_AES_ECB)); + d(CIP, "AES_128/ECB/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.1", "OID.2.16.840.1.101.3.4.1.1"), + m(CKM_AES_ECB)); + d(CIP, "AES_192/ECB/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.21", "OID.2.16.840.1.101.3.4.1.21"), + m(CKM_AES_ECB)); + d(CIP, "AES_256/ECB/NoPadding", P11Cipher, + s("2.16.840.1.101.3.4.1.41", "OID.2.16.840.1.101.3.4.1.41"), + m(CKM_AES_ECB)); d(CIP, "AES/ECB/PKCS5Padding", P11Cipher, s("AES"), m(CKM_AES_ECB)); d(CIP, "AES/CTR/NoPadding", P11Cipher, @@ -654,13 +673,16 @@ public final class SunPKCS11 extends AuthProvider { d(CIP, "RSA/ECB/NoPadding", P11RSACipher, m(CKM_RSA_X_509)); - d(SIG, "RawDSA", P11Signature, s("NONEwithDSA"), + d(SIG, "RawDSA", P11Signature, s("NONEwithDSA"), m(CKM_DSA)); - d(SIG, "DSA", P11Signature, s("SHA1withDSA"), + d(SIG, "DSA", P11Signature, + s("SHA1withDSA", "1.3.14.3.2.13", "1.3.14.3.2.27", + "1.2.840.10040.4.3", "OID.1.2.840.10040.4.3"), m(CKM_DSA_SHA1, CKM_DSA)); d(SIG, "NONEwithECDSA", P11Signature, m(CKM_ECDSA)); - d(SIG, "SHA1withECDSA", P11Signature, s("ECDSA"), + d(SIG, "SHA1withECDSA", P11Signature, + s("ECDSA", "1.2.840.10045.4.1", "OID.1.2.840.10045.4.1"), m(CKM_ECDSA_SHA1, CKM_ECDSA)); d(SIG, "SHA224withECDSA", P11Signature, s("1.2.840.10045.4.3.1", "OID.1.2.840.10045.4.3.1"), @@ -675,10 +697,14 @@ public final class SunPKCS11 extends AuthProvider { s("1.2.840.10045.4.3.4", "OID.1.2.840.10045.4.3.4"), m(CKM_ECDSA)); d(SIG, "MD2withRSA", P11Signature, + s("1.2.840.113549.1.1.2", "OID.1.2.840.113549.1.1.2"), m(CKM_MD2_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "MD5withRSA", P11Signature, + s("1.2.840.113549.1.1.4", "OID.1.2.840.113549.1.1.4"), m(CKM_MD5_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA1withRSA", P11Signature, + s("1.2.840.113549.1.1.5", "OID.1.2.840.113549.1.1.5", + "1.3.14.3.2.29"), m(CKM_SHA1_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA224withRSA", P11Signature, s("1.2.840.113549.1.1.14", "OID.1.2.840.113549.1.1.14"), diff --git a/src/share/classes/sun/security/provider/DSA.java b/src/share/classes/sun/security/provider/DSA.java index a59679ccc6f807ade150819eb267cb90d686833a..411563f42e4b9d996ec66e1b0a1e59c453f086be 100644 --- a/src/share/classes/sun/security/provider/DSA.java +++ b/src/share/classes/sun/security/provider/DSA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,14 +45,15 @@ import sun.security.jca.JCAUtil; /** * The Digital Signature Standard (using the Digital Signature - * Algorithm), as described in fips186 of the National Instute of - * Standards and Technology (NIST), using fips180-1 (SHA-1). + * Algorithm), as described in fips186-3 of the National Instute of + * Standards and Technology (NIST), using SHA digest algorithms + * from FIPS180-3. * * This file contains both the signature implementation for the - * commonly used SHA1withDSA (DSS) as well as RawDSA, used by TLS - * among others. RawDSA expects the 20 byte SHA-1 digest as input - * via update rather than the original data like other signature - * implementations. + * commonly used SHA1withDSA (DSS), SHA224withDSA, SHA256withDSA, + * as well as RawDSA, used by TLS among others. RawDSA expects + * the 20 byte SHA-1 digest as input via update rather than the + * original data like other signature implementations. * * @author Benjamin Renaud * @@ -78,129 +79,19 @@ abstract class DSA extends SignatureSpi { /* The private key, if any */ private BigInteger presetX; - /* The random seed used to generate k */ - private int[] Kseed; - - /* The random seed used to generate k (specified by application) */ - private byte[] KseedAsByteArray; - - /* - * The random seed used to generate k - * (prevent the same Kseed from being used twice in a row - */ - private int[] previousKseed; - /* The RNG used to output a seed for generating k */ private SecureRandom signingRandom; + /* The message digest object used */ + private final MessageDigest md; + /** * Construct a blank DSA object. It must be * initialized before being usable for signing or verifying. */ - DSA() { + DSA(MessageDigest md) { super(); - } - - /** - * Return the 20 byte hash value and reset the digest. - */ - abstract byte[] getDigest() throws SignatureException; - - /** - * Reset the digest. - */ - abstract void resetDigest(); - - /** - * Standard SHA1withDSA implementation. - */ - public static final class SHA1withDSA extends DSA { - - /* The SHA hash for the data */ - private final MessageDigest dataSHA; - - public SHA1withDSA() throws NoSuchAlgorithmException { - dataSHA = MessageDigest.getInstance("SHA-1"); - } - - /** - * Update a byte to be signed or verified. - */ - protected void engineUpdate(byte b) { - dataSHA.update(b); - } - - /** - * Update an array of bytes to be signed or verified. - */ - protected void engineUpdate(byte[] data, int off, int len) { - dataSHA.update(data, off, len); - } - - protected void engineUpdate(ByteBuffer b) { - dataSHA.update(b); - } - - byte[] getDigest() { - return dataSHA.digest(); - } - - void resetDigest() { - dataSHA.reset(); - } - } - - /** - * RawDSA implementation. - * - * RawDSA requires the data to be exactly 20 bytes long. If it is - * not, a SignatureException is thrown when sign()/verify() is called - * per JCA spec. - */ - public static final class RawDSA extends DSA { - - // length of the SHA-1 digest (20 bytes) - private final static int SHA1_LEN = 20; - - // 20 byte digest buffer - private final byte[] digestBuffer; - - // offset into the buffer - private int ofs; - - public RawDSA() { - digestBuffer = new byte[SHA1_LEN]; - } - - protected void engineUpdate(byte b) { - if (ofs == SHA1_LEN) { - ofs = SHA1_LEN + 1; - return; - } - digestBuffer[ofs++] = b; - } - - protected void engineUpdate(byte[] data, int off, int len) { - if (ofs + len > SHA1_LEN) { - ofs = SHA1_LEN + 1; - return; - } - System.arraycopy(data, off, digestBuffer, ofs, len); - ofs += len; - } - - byte[] getDigest() throws SignatureException { - if (ofs != SHA1_LEN) { - throw new SignatureException - ("Data for RawDSA must be exactly 20 bytes long"); - } - ofs = 0; - return digestBuffer; - } - - void resetDigest() { - ofs = 0; - } + this.md = md; } /** @@ -217,13 +108,25 @@ abstract class DSA extends SignatureSpi { throw new InvalidKeyException("not a DSA private key: " + privateKey); } + java.security.interfaces.DSAPrivateKey priv = (java.security.interfaces.DSAPrivateKey)privateKey; + + // check for algorithm specific constraints before doing initialization + DSAParams params = priv.getParams(); + if (params == null) { + throw new InvalidKeyException("DSA private key lacks parameters"); + } + checkKey(params); + + this.params = params; this.presetX = priv.getX(); this.presetY = null; - initialize(priv.getParams()); + this.presetP = params.getP(); + this.presetQ = params.getQ(); + this.presetG = params.getG(); + this.md.reset(); } - /** * Initialize the DSA object with a DSA public key. * @@ -240,16 +143,42 @@ abstract class DSA extends SignatureSpi { } java.security.interfaces.DSAPublicKey pub = (java.security.interfaces.DSAPublicKey)publicKey; + + // check for algorithm specific constraints before doing initialization + DSAParams params = pub.getParams(); + if (params == null) { + throw new InvalidKeyException("DSA public key lacks parameters"); + } + checkKey(params); + + this.params = params; this.presetY = pub.getY(); this.presetX = null; - initialize(pub.getParams()); + this.presetP = params.getP(); + this.presetQ = params.getQ(); + this.presetG = params.getG(); + this.md.reset(); + } + + /** + * Update a byte to be signed or verified. + */ + protected void engineUpdate(byte b) { + md.update(b); + } + + /** + * Update an array of bytes to be signed or verified. + */ + protected void engineUpdate(byte[] data, int off, int len) { + md.update(data, off, len); } - private void initialize(DSAParams params) throws InvalidKeyException { - resetDigest(); - setParams(params); + protected void engineUpdate(ByteBuffer b) { + md.update(b); } + /** * Sign all the data thus far updated. The signature is formatted * according to the Canonical Encoding Rules, returned as a DER @@ -352,23 +281,51 @@ abstract class DSA extends SignatureSpi { } } + @Deprecated + protected void engineSetParameter(String key, Object param) { + throw new InvalidParameterException("No parameter accepted"); + } + + @Deprecated + protected Object engineGetParameter(String key) { + return null; + } + + protected void checkKey(DSAParams params) throws InvalidKeyException { + // FIPS186-3 states in sec4.2 that a hash function which provides + // a lower security strength than the (L, N) pair ordinarily should + // not be used. + int valueN = params.getQ().bitLength(); + if (valueN > md.getDigestLength()*8) { + throw new InvalidKeyException("Key is too strong for this signature algorithm"); + } + } + private BigInteger generateR(BigInteger p, BigInteger q, BigInteger g, BigInteger k) { BigInteger temp = g.modPow(k, p); - return temp.remainder(q); - } + return temp.mod(q); + } private BigInteger generateS(BigInteger x, BigInteger q, BigInteger r, BigInteger k) throws SignatureException { - byte[] s2 = getDigest(); - BigInteger temp = new BigInteger(1, s2); + byte[] s2; + try { + s2 = md.digest(); + } catch (RuntimeException re) { + // Only for RawDSA due to its 20-byte length restriction + throw new SignatureException(re.getMessage()); + } + // get the leftmost min(N, outLen) bits of the digest value + int nBytes = q.bitLength()/8; + if (nBytes < s2.length) { + s2 = Arrays.copyOfRange(s2, 0, nBytes); + } + BigInteger z = new BigInteger(1, s2); BigInteger k1 = k.modInverse(q); - BigInteger s = x.multiply(r); - s = temp.add(s); - s = k1.multiply(s); - return s.remainder(q); + return x.multiply(r).add(z).multiply(k1).mod(q); } private BigInteger generateW(BigInteger p, BigInteger q, @@ -380,54 +337,41 @@ abstract class DSA extends SignatureSpi { BigInteger q, BigInteger g, BigInteger w, BigInteger r) throws SignatureException { - byte[] s2 = getDigest(); - BigInteger temp = new BigInteger(1, s2); - - temp = temp.multiply(w); - BigInteger u1 = temp.remainder(q); + byte[] s2; + try { + s2 = md.digest(); + } catch (RuntimeException re) { + // Only for RawDSA due to its 20-byte length restriction + throw new SignatureException(re.getMessage()); + } + // get the leftmost min(N, outLen) bits of the digest value + int nBytes = q.bitLength()/8; + if (nBytes < s2.length) { + s2 = Arrays.copyOfRange(s2, 0, nBytes); + } + BigInteger z = new BigInteger(1, s2); - BigInteger u2 = (r.multiply(w)).remainder(q); + BigInteger u1 = z.multiply(w).mod(q); + BigInteger u2 = (r.multiply(w)).mod(q); BigInteger t1 = g.modPow(u1,p); BigInteger t2 = y.modPow(u2,p); BigInteger t3 = t1.multiply(t2); - BigInteger t5 = t3.remainder(p); - return t5.remainder(q); + BigInteger t5 = t3.mod(p); + return t5.mod(q); } - /* - * Please read bug report 4044247 for an alternative, faster, - * NON-FIPS approved method to generate K - */ - private BigInteger generateK(BigInteger q) { - - BigInteger k = null; - - // The application specified a Kseed for us to use. - // Note that we do not allow usage of the same Kseed twice in a row - if (Kseed != null && !Arrays.equals(Kseed, previousKseed)) { - k = generateK(Kseed, q); - if (k.signum() > 0 && k.compareTo(q) < 0) { - previousKseed = new int [Kseed.length]; - System.arraycopy(Kseed, 0, previousKseed, 0, Kseed.length); - return k; - } - } - - // The application did not specify a Kseed for us to use. - // We'll generate a new Kseed by getting random bytes from - // a SecureRandom object. + // NOTE: This following impl is defined in FIPS 186-3 AppendixB.2.2. + // Original DSS algos such as SHA1withDSA and RawDSA uses a different + // algorithm defined in FIPS 186-1 Sec3.2, and thus need to override this. + protected BigInteger generateK(BigInteger q) { SecureRandom random = getSigningRandom(); + byte[] kValue = new byte[q.bitLength()/8]; while (true) { - int[] seed = new int[5]; - - for (int i = 0; i < 5; i++) - seed[i] = random.nextInt(); - k = generateK(seed, q); + random.nextBytes(kValue); + BigInteger k = new BigInteger(1, kValue).mod(q); if (k.signum() > 0 && k.compareTo(q) < 0) { - previousKseed = new int [seed.length]; - System.arraycopy(seed, 0, previousKseed, 0, seed.length); return k; } } @@ -435,7 +379,7 @@ abstract class DSA extends SignatureSpi { // Use the application-specified SecureRandom Object if provided. // Otherwise, use our default SecureRandom Object. - private SecureRandom getSigningRandom() { + protected SecureRandom getSigningRandom() { if (signingRandom == null) { if (appRandom != null) { signingRandom = appRandom; @@ -447,232 +391,356 @@ abstract class DSA extends SignatureSpi { } /** - * Compute k for a DSA signature. - * - * @param seed the seed for generating k. This seed should be - * secure. This is what is refered to as the KSEED in the DSA - * specification. - * - * @param g the g parameter from the DSA key pair. + * Return a human readable rendition of the engine. */ - private BigInteger generateK(int[] seed, BigInteger q) { - - // check out t in the spec. - int[] t = { 0xEFCDAB89, 0x98BADCFE, 0x10325476, - 0xC3D2E1F0, 0x67452301 }; - // - int[] tmp = DSA.SHA_7(seed, t); - byte[] tmpBytes = new byte[tmp.length * 4]; - for (int i = 0; i < tmp.length; i++) { - int k = tmp[i]; - for (int j = 0; j < 4; j++) { - tmpBytes[(i * 4) + j] = (byte) (k >>> (24 - (j * 8))); - } + public String toString() { + String printable = "DSA Signature"; + if (presetP != null && presetQ != null && presetG != null) { + printable += "\n\tp: " + Debug.toHexString(presetP); + printable += "\n\tq: " + Debug.toHexString(presetQ); + printable += "\n\tg: " + Debug.toHexString(presetG); + } else { + printable += "\n\t P, Q or G not initialized."; } - BigInteger k = new BigInteger(1, tmpBytes).mod(q); - return k; + if (presetY != null) { + printable += "\n\ty: " + Debug.toHexString(presetY); + } + if (presetY == null && presetX == null) { + printable += "\n\tUNINIIALIZED"; + } + return printable; } - // Constants for each round - private static final int round1_kt = 0x5a827999; - private static final int round2_kt = 0x6ed9eba1; - private static final int round3_kt = 0x8f1bbcdc; - private static final int round4_kt = 0xca62c1d6; - - /** - * Computes set 1 thru 7 of SHA-1 on m1. */ - static int[] SHA_7(int[] m1, int[] h) { - - int[] W = new int[80]; - System.arraycopy(m1,0,W,0,m1.length); - int temp = 0; - - for (int t = 16; t <= 79; t++){ - temp = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]; - W[t] = ((temp << 1) | (temp >>>(32 - 1))); - } - - int a = h[0],b = h[1],c = h[2], d = h[3], e = h[4]; - for (int i = 0; i < 20; i++) { - temp = ((a<<5) | (a>>>(32-5))) + - ((b&c)|((~b)&d))+ e + W[i] + round1_kt; - e = d; - d = c; - c = ((b<<30) | (b>>>(32-30))); - b = a; - a = temp; - } - - // Round 2 - for (int i = 20; i < 40; i++) { - temp = ((a<<5) | (a>>>(32-5))) + - (b ^ c ^ d) + e + W[i] + round2_kt; - e = d; - d = c; - c = ((b<<30) | (b>>>(32-30))); - b = a; - a = temp; - } - - // Round 3 - for (int i = 40; i < 60; i++) { - temp = ((a<<5) | (a>>>(32-5))) + - ((b&c)|(b&d)|(c&d)) + e + W[i] + round3_kt; - e = d; - d = c; - c = ((b<<30) | (b>>>(32-30))); - b = a; - a = temp; - } - - // Round 4 - for (int i = 60; i < 80; i++) { - temp = ((a<<5) | (a>>>(32-5))) + - (b ^ c ^ d) + e + W[i] + round4_kt; - e = d; - d = c; - c = ((b<<30) | (b>>>(32-30))); - b = a; - a = temp; - } - int[] md = new int[5]; - md[0] = h[0] + a; - md[1] = h[1] + b; - md[2] = h[2] + c; - md[3] = h[3] + d; - md[4] = h[4] + e; - return md; - } - + private static void debug(Exception e) { + if (debug) { + e.printStackTrace(); + } + } - /** - * This implementation recognizes the following parameter:

- * - *
Kseed - * - *
a byte array. - * - *
- * - * @deprecated - */ - @Deprecated - protected void engineSetParameter(String key, Object param) { - if (key.equals("KSEED")) { - if (param instanceof byte[]) { - Kseed = byteArray2IntArray((byte[])param); - KseedAsByteArray = (byte[])param; - } else { - debug("unrecognized param: " + key); - throw new InvalidParameterException("Kseed not a byte array"); - } - } else { - throw new InvalidParameterException("invalid parameter"); + private static void debug(String s) { + if (debug) { + System.err.println(s); } } /** - * Return the value of the requested parameter. Recognized - * parameters are: - * - *
- * - *
Kseed - * - *
a byte array. - * - *
- * - * @return the value of the requested parameter. - * - * @see java.security.SignatureEngine - * - * @deprecated + * Standard SHA224withDSA implementation as defined in FIPS186-3. */ - @Deprecated - protected Object engineGetParameter(String key) { - if (key.equals("KSEED")) { - return KseedAsByteArray; - } else { - return null; + public static final class SHA224withDSA extends DSA { + public SHA224withDSA() throws NoSuchAlgorithmException { + super(MessageDigest.getInstance("SHA-224")); } } /** - * Set the algorithm object. + * Standard SHA256withDSA implementation as defined in FIPS186-3. */ - private void setParams(DSAParams params) throws InvalidKeyException { - if (params == null) { - throw new InvalidKeyException("DSA public key lacks parameters"); + public static final class SHA256withDSA extends DSA { + public SHA256withDSA() throws NoSuchAlgorithmException { + super(MessageDigest.getInstance("SHA-256")); } - this.params = params; - this.presetP = params.getP(); - this.presetQ = params.getQ(); - this.presetG = params.getG(); } - /** - * Return a human readable rendition of the engine. - */ - public String toString() { - String printable = "DSA Signature"; - if (presetP != null && presetQ != null && presetG != null) { - printable += "\n\tp: " + Debug.toHexString(presetP); - printable += "\n\tq: " + Debug.toHexString(presetQ); - printable += "\n\tg: " + Debug.toHexString(presetG); - } else { - printable += "\n\t P, Q or G not initialized."; + static class LegacyDSA extends DSA { + /* The random seed used to generate k */ + private int[] kSeed; + /* The random seed used to generate k (specified by application) */ + private byte[] kSeedAsByteArray; + /* + * The random seed used to generate k + * (prevent the same Kseed from being used twice in a row + */ + private int[] kSeedLast; + + public LegacyDSA(MessageDigest md) throws NoSuchAlgorithmException { + super(md); + } + + @Deprecated + protected void engineSetParameter(String key, Object param) { + if (key.equals("KSEED")) { + if (param instanceof byte[]) { + kSeed = byteArray2IntArray((byte[])param); + kSeedAsByteArray = (byte[])param; + } else { + debug("unrecognized param: " + key); + throw new InvalidParameterException("kSeed not a byte array"); + } + } else { + throw new InvalidParameterException("Unsupported parameter"); + } } - if (presetY != null) { - printable += "\n\ty: " + Debug.toHexString(presetY); + + @Deprecated + protected Object engineGetParameter(String key) { + if (key.equals("KSEED")) { + return kSeedAsByteArray; + } else { + return null; + } } - if (presetY == null && presetX == null) { - printable += "\n\tUNINIIALIZED"; + + @Override + protected void checkKey(DSAParams params) throws InvalidKeyException { + int valueL = params.getP().bitLength(); + if (valueL > 1024) { + throw new InvalidKeyException("Key is too long for this algorithm"); + } } - return printable; - } - /* - * Utility routine for converting a byte array into an int array - */ - private int[] byteArray2IntArray(byte[] byteArray) { + /* + * Please read bug report 4044247 for an alternative, faster, + * NON-FIPS approved method to generate K + */ + @Override + protected BigInteger generateK(BigInteger q) { + BigInteger k = null; + + // The application specified a kSeed for us to use. + // Note: we dis-allow usage of the same Kseed twice in a row + if (kSeed != null && !Arrays.equals(kSeed, kSeedLast)) { + k = generateKUsingKSeed(kSeed, q); + if (k.signum() > 0 && k.compareTo(q) < 0) { + kSeedLast = kSeed.clone(); + return k; + } + } + + // The application did not specify a Kseed for us to use. + // We'll generate a new Kseed by getting random bytes from + // a SecureRandom object. + SecureRandom random = getSigningRandom(); + + while (true) { + int[] seed = new int[5]; + + for (int i = 0; i < 5; i++) seed[i] = random.nextInt(); + + k = generateKUsingKSeed(seed, q); + if (k.signum() > 0 && k.compareTo(q) < 0) { + kSeedLast = seed; + return k; + } + } + } + + /** + * Compute k for the DSA signature as defined in the original DSS, + * i.e. FIPS186. + * + * @param seed the seed for generating k. This seed should be + * secure. This is what is refered to as the KSEED in the DSA + * specification. + * + * @param g the g parameter from the DSA key pair. + */ + private BigInteger generateKUsingKSeed(int[] seed, BigInteger q) { + + // check out t in the spec. + int[] t = { 0xEFCDAB89, 0x98BADCFE, 0x10325476, + 0xC3D2E1F0, 0x67452301 }; + // + int[] tmp = SHA_7(seed, t); + byte[] tmpBytes = new byte[tmp.length * 4]; + for (int i = 0; i < tmp.length; i++) { + int k = tmp[i]; + for (int j = 0; j < 4; j++) { + tmpBytes[(i * 4) + j] = (byte) (k >>> (24 - (j * 8))); + } + } + BigInteger k = new BigInteger(1, tmpBytes).mod(q); + return k; + } + + // Constants for each round + private static final int round1_kt = 0x5a827999; + private static final int round2_kt = 0x6ed9eba1; + private static final int round3_kt = 0x8f1bbcdc; + private static final int round4_kt = 0xca62c1d6; + + /** + * Computes set 1 thru 7 of SHA-1 on m1. */ + static int[] SHA_7(int[] m1, int[] h) { + + int[] W = new int[80]; + System.arraycopy(m1,0,W,0,m1.length); + int temp = 0; + + for (int t = 16; t <= 79; t++){ + temp = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]; + W[t] = ((temp << 1) | (temp >>>(32 - 1))); + } + + int a = h[0],b = h[1],c = h[2], d = h[3], e = h[4]; + for (int i = 0; i < 20; i++) { + temp = ((a<<5) | (a>>>(32-5))) + + ((b&c)|((~b)&d))+ e + W[i] + round1_kt; + e = d; + d = c; + c = ((b<<30) | (b>>>(32-30))); + b = a; + a = temp; + } + + // Round 2 + for (int i = 20; i < 40; i++) { + temp = ((a<<5) | (a>>>(32-5))) + + (b ^ c ^ d) + e + W[i] + round2_kt; + e = d; + d = c; + c = ((b<<30) | (b>>>(32-30))); + b = a; + a = temp; + } + + // Round 3 + for (int i = 40; i < 60; i++) { + temp = ((a<<5) | (a>>>(32-5))) + + ((b&c)|(b&d)|(c&d)) + e + W[i] + round3_kt; + e = d; + d = c; + c = ((b<<30) | (b>>>(32-30))); + b = a; + a = temp; + } + + // Round 4 + for (int i = 60; i < 80; i++) { + temp = ((a<<5) | (a>>>(32-5))) + + (b ^ c ^ d) + e + W[i] + round4_kt; + e = d; + d = c; + c = ((b<<30) | (b>>>(32-30))); + b = a; + a = temp; + } + int[] md = new int[5]; + md[0] = h[0] + a; + md[1] = h[1] + b; + md[2] = h[2] + c; + md[3] = h[3] + d; + md[4] = h[4] + e; + return md; + } + + /* + * Utility routine for converting a byte array into an int array + */ + private int[] byteArray2IntArray(byte[] byteArray) { - int j = 0; - byte[] newBA; - int mod = byteArray.length % 4; + int j = 0; + byte[] newBA; + int mod = byteArray.length % 4; - // guarantee that the incoming byteArray is a multiple of 4 - // (pad with 0's) - switch (mod) { + // guarantee that the incoming byteArray is a multiple of 4 + // (pad with 0's) + switch (mod) { case 3: newBA = new byte[byteArray.length + 1]; break; case 2: newBA = new byte[byteArray.length + 2]; break; case 1: newBA = new byte[byteArray.length + 3]; break; default: newBA = new byte[byteArray.length + 0]; break; - } - System.arraycopy(byteArray, 0, newBA, 0, byteArray.length); + } + System.arraycopy(byteArray, 0, newBA, 0, byteArray.length); + + // copy each set of 4 bytes in the byte array into an integer + int[] newSeed = new int[newBA.length / 4]; + for (int i = 0; i < newBA.length; i += 4) { + newSeed[j] = newBA[i + 3] & 0xFF; + newSeed[j] |= (newBA[i + 2] << 8) & 0xFF00; + newSeed[j] |= (newBA[i + 1] << 16) & 0xFF0000; + newSeed[j] |= (newBA[i + 0] << 24) & 0xFF000000; + j++; + } - // copy each set of 4 bytes in the byte array into an integer - int[] newSeed = new int[newBA.length / 4]; - for (int i = 0; i < newBA.length; i += 4) { - newSeed[j] = newBA[i + 3] & 0xFF; - newSeed[j] |= (newBA[i + 2] << 8) & 0xFF00; - newSeed[j] |= (newBA[i + 1] << 16) & 0xFF0000; - newSeed[j] |= (newBA[i + 0] << 24) & 0xFF000000; - j++; + return newSeed; } - - return newSeed; } - private static void debug(Exception e) { - if (debug) { - e.printStackTrace(); + public static final class SHA1withDSA extends LegacyDSA { + public SHA1withDSA() throws NoSuchAlgorithmException { + super(MessageDigest.getInstance("SHA-1")); } } - private static void debug(String s) { - if (debug) { - System.err.println(s); + /** + * RawDSA implementation. + * + * RawDSA requires the data to be exactly 20 bytes long. If it is + * not, a SignatureException is thrown when sign()/verify() is called + * per JCA spec. + */ + public static final class RawDSA extends LegacyDSA { + // Internal special-purpose MessageDigest impl for RawDSA + // Only override whatever methods used + // NOTE: no clone support + public static final class NullDigest20 extends MessageDigest { + // 20 byte digest buffer + private final byte[] digestBuffer = new byte[20]; + + // offset into the buffer; use Integer.MAX_VALUE to indicate + // out-of-bound condition + private int ofs = 0; + + protected NullDigest20() { + super("NullDigest20"); + } + protected void engineUpdate(byte input) { + if (ofs == digestBuffer.length) { + ofs = Integer.MAX_VALUE; + } else { + digestBuffer[ofs++] = input; + } + } + protected void engineUpdate(byte[] input, int offset, int len) { + if (ofs + len > digestBuffer.length) { + ofs = Integer.MAX_VALUE; + } else { + System.arraycopy(input, offset, digestBuffer, ofs, len); + ofs += len; + } + } + protected final void engineUpdate(ByteBuffer input) { + int inputLen = input.remaining(); + if (ofs + inputLen > digestBuffer.length) { + ofs = Integer.MAX_VALUE; + } else { + input.get(digestBuffer, ofs, inputLen); + ofs += inputLen; + } + } + protected byte[] engineDigest() throws RuntimeException { + if (ofs != digestBuffer.length) { + throw new RuntimeException + ("Data for RawDSA must be exactly 20 bytes long"); + } + reset(); + return digestBuffer; + } + protected int engineDigest(byte[] buf, int offset, int len) + throws DigestException { + if (ofs != digestBuffer.length) { + throw new DigestException + ("Data for RawDSA must be exactly 20 bytes long"); + } + if (len < digestBuffer.length) { + throw new DigestException + ("Output buffer too small; must be at least 20 bytes"); + } + System.arraycopy(digestBuffer, 0, buf, offset, digestBuffer.length); + reset(); + return digestBuffer.length; + } + + protected void engineReset() { + ofs = 0; + } + protected final int engineGetDigestLength() { + return digestBuffer.length; + } + } + + public RawDSA() throws NoSuchAlgorithmException { + super(new NullDigest20()); } } } diff --git a/src/share/classes/sun/security/provider/DSAKeyPairGenerator.java b/src/share/classes/sun/security/provider/DSAKeyPairGenerator.java index 9adab7b6b6ee5b79f0f788795db9827cfdae9389..579d60e0fea9b532090fc4a4202c473943b536db 100644 --- a/src/share/classes/sun/security/provider/DSAKeyPairGenerator.java +++ b/src/share/classes/sun/security/provider/DSAKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,8 +48,9 @@ import sun.security.jca.JCAUtil; public class DSAKeyPairGenerator extends KeyPairGenerator implements java.security.interfaces.DSAKeyPairGenerator { - /* The modulus length */ - private int modlen; + /* Length for prime P and subPrime Q in bits */ + private int plen; + private int qlen; /* whether to force new parameters to be generated for each KeyPair */ private boolean forceNewParameters; @@ -65,20 +66,23 @@ implements java.security.interfaces.DSAKeyPairGenerator { initialize(1024, null); } - private static void checkStrength(int strength) { - if ((strength < 512) || (strength > 1024) || (strength % 64 != 0)) { + private static void checkStrength(int sizeP, int sizeQ) { + if ((sizeP >= 512) && (sizeP <= 1024) && (sizeP % 64 == 0) + && sizeQ == 160) { + // traditional - allow for backward compatibility + // L=multiples of 64 and between 512 and 1024 (inclusive) + // N=160 + } else if (sizeP == 2048 && (sizeQ == 224 || sizeQ == 256)) { + // L=2048, N=224 or 256 + } else { throw new InvalidParameterException - ("Modulus size must range from 512 to 1024 " - + "and be a multiple of 64"); + ("Unsupported prime and subprime size combination: " + + sizeP + ", " + sizeQ); } } public void initialize(int modlen, SecureRandom random) { - checkStrength(modlen); - this.random = random; - this.modlen = modlen; - this.params = null; - this.forceNewParameters = false; + initialize(modlen, false, random); } /** @@ -86,18 +90,27 @@ implements java.security.interfaces.DSAKeyPairGenerator { * is false, a set of pre-computed parameters is used. */ public void initialize(int modlen, boolean genParams, SecureRandom random) { - checkStrength(modlen); + int subPrimeLen = -1; + if (modlen <= 1024) { + subPrimeLen = 160; + } else if (modlen == 2048) { + subPrimeLen = 224; + } + checkStrength(modlen, subPrimeLen); if (genParams) { params = null; } else { - params = ParameterCache.getCachedDSAParameterSpec(modlen); + params = ParameterCache.getCachedDSAParameterSpec(modlen, + subPrimeLen); if (params == null) { throw new InvalidParameterException ("No precomputed parameters for requested modulus size " + "available"); } + } - this.modlen = modlen; + this.plen = modlen; + this.qlen = subPrimeLen; this.random = random; this.forceNewParameters = genParams; } @@ -136,9 +149,11 @@ implements java.security.interfaces.DSAKeyPairGenerator { } private void initialize0(DSAParameterSpec params, SecureRandom random) { - int modlen = params.getP().bitLength(); - checkStrength(modlen); - this.modlen = modlen; + int sizeP = params.getP().bitLength(); + int sizeQ = params.getQ().bitLength(); + checkStrength(sizeP, sizeQ); + this.plen = sizeP; + this.qlen = sizeQ; this.params = params; this.random = random; this.forceNewParameters = false; @@ -156,11 +171,11 @@ implements java.security.interfaces.DSAKeyPairGenerator { try { if (forceNewParameters) { // generate new parameters each time - spec = ParameterCache.getNewDSAParameterSpec(modlen, random); + spec = ParameterCache.getNewDSAParameterSpec(plen, qlen, random); } else { if (params == null) { params = - ParameterCache.getDSAParameterSpec(modlen, random); + ParameterCache.getDSAParameterSpec(plen, qlen, random); } spec = params; } @@ -203,43 +218,14 @@ implements java.security.interfaces.DSAKeyPairGenerator { */ private BigInteger generateX(SecureRandom random, BigInteger q) { BigInteger x = null; + byte[] temp = new byte[qlen]; while (true) { - int[] seed = new int[5]; - for (int i = 0; i < 5; i++) { - seed[i] = random.nextInt(); - } - x = generateX(seed, q); + random.nextBytes(temp); + x = new BigInteger(1, temp).mod(q); if (x.signum() > 0 && (x.compareTo(q) < 0)) { - break; - } - } - return x; - } - - /** - * Given a seed, generate the private key component of the key - * pair. In the terminology used in the DSA specification - * (FIPS-186) seed is the XSEED quantity. - * - * @param seed the seed to use to generate the private key. - */ - BigInteger generateX(int[] seed, BigInteger q) { - - // check out t in the spec. - int[] t = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, - 0x10325476, 0xC3D2E1F0 }; - // - - int[] tmp = DSA.SHA_7(seed, t); - byte[] tmpBytes = new byte[tmp.length * 4]; - for (int i = 0; i < tmp.length; i++) { - int k = tmp[i]; - for (int j = 0; j < 4; j++) { - tmpBytes[(i * 4) + j] = (byte) (k >>> (24 - (j * 8))); + return x; } } - BigInteger x = new BigInteger(1, tmpBytes).mod(q); - return x; } /** diff --git a/src/share/classes/sun/security/provider/DSAParameterGenerator.java b/src/share/classes/sun/security/provider/DSAParameterGenerator.java index 953d7151166f0e3a6c0972e9dc2ceb824e4e7553..9c6be21d58082b0b1701233acfc00701777edc1d 100644 --- a/src/share/classes/sun/security/provider/DSAParameterGenerator.java +++ b/src/share/classes/sun/security/provider/DSAParameterGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,10 +32,12 @@ import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.InvalidParameterException; +import java.security.MessageDigest; import java.security.SecureRandom; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; import java.security.spec.DSAParameterSpec; +import java.security.spec.DSAGenParameterSpec; /** * This class generates parameters for the DSA algorithm. It uses a default @@ -54,8 +56,14 @@ import java.security.spec.DSAParameterSpec; public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { - // the modulus length - private int modLen = 1024; // default + // the default parameters + private static final DSAGenParameterSpec DEFAULTS = + new DSAGenParameterSpec(1024, 160, 160); + + // the length of prime P, subPrime Q, and seed in bits + private int valueL = -1; + private int valueN = -1; + private int seedLen = -1; // the source of randomness private SecureRandom random; @@ -65,11 +73,7 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { private static final BigInteger ONE = BigInteger.valueOf(1); private static final BigInteger TWO = BigInteger.valueOf(2); - // Make a SHA-1 hash function - private SHA sha; - public DSAParameterGenerator() { - this.sha = new SHA(); } /** @@ -80,19 +84,18 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { * @param random the source of randomness */ protected void engineInit(int strength, SecureRandom random) { - /* - * Bruce Schneier, "Applied Cryptography", 2nd Edition, - * Description of DSA: - * [...] The algorithm uses the following parameter: - * p=a prime number L bits long, when L ranges from 512 to 1024 and is - * a multiple of 64. [...] - */ - if ((strength < 512) || (strength > 1024) || (strength % 64 != 0)) { + if ((strength >= 512) && (strength <= 1024) && (strength % 64 == 0)) { + this.valueN = 160; + } else if (strength == 2048) { + this.valueN = 224; +// } else if (strength == 3072) { +// this.valueN = 256; + } else { throw new InvalidParameterException - ("Prime size must range from 512 to 1024 " - + "and be a multiple of 64"); + ("Prime size should be 512 - 1024, or 2048"); } - this.modLen = strength; + this.valueL = strength; + this.seedLen = valueN; this.random = random; } @@ -100,7 +103,7 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { * Initializes this parameter generator with a set of * algorithm-specific parameter generation values. * - * @param params the set of algorithm-specific parameter generation values + * @param genParamSpec the set of algorithm-specific parameter generation values * @param random the source of randomness * * @exception InvalidAlgorithmParameterException if the given parameter @@ -109,7 +112,19 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { protected void engineInit(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException { + if (!(genParamSpec instanceof DSAGenParameterSpec)) { throw new InvalidAlgorithmParameterException("Invalid parameter"); + } + DSAGenParameterSpec dsaGenParams = (DSAGenParameterSpec) genParamSpec; + if (dsaGenParams.getPrimePLength() > 2048) { + throw new InvalidParameterException + ("Prime size should be 512 - 1024, or 2048"); + } + // directly initialize using the already validated values + this.valueL = dsaGenParams.getPrimePLength(); + this.valueN = dsaGenParams.getSubprimeQLength(); + this.seedLen = dsaGenParams.getSeedLength(); + this.random = random; } /** @@ -123,15 +138,21 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { if (this.random == null) { this.random = new SecureRandom(); } - - BigInteger[] pAndQ = generatePandQ(this.random, this.modLen); + if (valueL == -1) { + try { + engineInit(DEFAULTS, this.random); + } catch (InvalidAlgorithmParameterException iape) { + // should never happen + } + } + BigInteger[] pAndQ = generatePandQ(this.random, valueL, + valueN, seedLen); BigInteger paramP = pAndQ[0]; BigInteger paramQ = pAndQ[1]; BigInteger paramG = generateG(paramP, paramQ); - DSAParameterSpec dsaParamSpec = new DSAParameterSpec(paramP, - paramQ, - paramG); + DSAParameterSpec dsaParamSpec = + new DSAParameterSpec(paramP, paramQ, paramG); algParams = AlgorithmParameters.getInstance("DSA", "SUN"); algParams.init(dsaParamSpec); } catch (InvalidParameterSpecException e) { @@ -156,102 +177,98 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { * * @param random the source of randomness to generate the * seed - * @param L the size of p, in bits. + * @param valueL the size of p, in bits. + * @param valueN the size of q, in bits. + * @param seedLen the length of seed, in bits. * * @return an array of BigInteger, with p at index 0 and - * q at index 1. - */ - BigInteger[] generatePandQ(SecureRandom random, int L) { - BigInteger[] result = null; - byte[] seed = new byte[20]; - - while(result == null) { - for (int i = 0; i < 20; i++) { - seed[i] = (byte)random.nextInt(); - } - result = generatePandQ(seed, L); - } - return result; - } - - /* - * Generates the prime and subprime parameters for DSA. - * - *

The seed parameter corresponds to the SEED parameter - * referenced in the FIPS specification of the DSA algorithm, - * and L is the size of p, in bits. - * - * @param seed the seed to generate the parameters - * @param L the size of p, in bits. - * - * @return an array of BigInteger, with p at index 0, * q at index 1, the seed at index 2, and the counter value - * at index 3, or null if the seed does not yield suitable numbers. + * at index 3. */ - BigInteger[] generatePandQ(byte[] seed, int L) { - - /* Useful variables */ - int g = seed.length * 8; - int n = (L - 1) / 160; - int b = (L - 1) % 160; - - BigInteger SEED = new BigInteger(1, seed); - BigInteger TWOG = TWO.pow(2 * g); - - /* Step 2 (Step 1 is getting seed). */ - byte[] U1 = SHA(seed); - byte[] U2 = SHA(toByteArray((SEED.add(ONE)).mod(TWOG))); - - xor(U1, U2); - byte[] U = U1; - - /* Step 3: For q by setting the msb and lsb to 1 */ - U[0] |= 0x80; - U[19] |= 1; - BigInteger q = new BigInteger(1, U); - - /* Step 5 */ - if (!q.isProbablePrime(80)) { - return null; - - } else { - BigInteger V[] = new BigInteger[n + 1]; - BigInteger offset = TWO; - - /* Step 6 */ - for (int counter = 0; counter < 4096; counter++) { - - /* Step 7 */ - for (int k = 0; k <= n; k++) { - BigInteger K = BigInteger.valueOf(k); - BigInteger tmp = (SEED.add(offset).add(K)).mod(TWOG); - V[k] = new BigInteger(1, SHA(toByteArray(tmp))); - } - - /* Step 8 */ - BigInteger W = V[0]; - for (int i = 1; i < n; i++) { - W = W.add(V[i].multiply(TWO.pow(i * 160))); - } - W = W.add((V[n].mod(TWO.pow(b))).multiply(TWO.pow(n * 160))); - - BigInteger TWOLm1 = TWO.pow(L - 1); - BigInteger X = W.add(TWOLm1); + private static BigInteger[] generatePandQ(SecureRandom random, int valueL, + int valueN, int seedLen) { + String hashAlg = null; + if (valueN == 160) { + hashAlg = "SHA"; + } else if (valueN == 224) { + hashAlg = "SHA-224"; + } else if (valueN == 256) { + hashAlg = "SHA-256"; + } + MessageDigest hashObj = null; + try { + hashObj = MessageDigest.getInstance(hashAlg); + } catch (NoSuchAlgorithmException nsae) { + // should never happen + nsae.printStackTrace(); + } - /* Step 9 */ - BigInteger c = X.mod(q.multiply(TWO)); - BigInteger p = X.subtract(c.subtract(ONE)); + /* Step 3, 4: Useful variables */ + int outLen = hashObj.getDigestLength()*8; + int n = (valueL - 1) / outLen; + int b = (valueL - 1) % outLen; + byte[] seedBytes = new byte[seedLen/8]; + BigInteger twoSl = TWO.pow(seedLen); + int primeCertainty = 80; // for 1024-bit prime P + if (valueL == 2048) { + primeCertainty = 112; + //} else if (valueL == 3072) { + // primeCertainty = 128; + } - /* Step 10 - 13 */ - if (p.compareTo(TWOLm1) > -1 && p.isProbablePrime(80)) { - BigInteger[] result = {p, q, SEED, - BigInteger.valueOf(counter)}; - return result; - } - offset = offset.add(BigInteger.valueOf(n)).add(ONE); + BigInteger resultP, resultQ, seed = null; + int counter; + while (true) { + do { + /* Step 5 */ + random.nextBytes(seedBytes); + seed = new BigInteger(1, seedBytes); + + /* Step 6 */ + BigInteger U = new BigInteger(1, hashObj.digest(seedBytes)). + mod(TWO.pow(valueN - 1)); + + /* Step 7 */ + resultQ = TWO.pow(valueN - 1).add(U).add(ONE). subtract(U.mod(TWO)); + } while (!resultQ.isProbablePrime(primeCertainty)); + + /* Step 10 */ + BigInteger offset = ONE; + /* Step 11 */ + for (counter = 0; counter < 4*valueL; counter++) { + BigInteger V[] = new BigInteger[n + 1]; + /* Step 11.1 */ + for (int j = 0; j <= n; j++) { + BigInteger J = BigInteger.valueOf(j); + BigInteger tmp = (seed.add(offset).add(J)).mod(twoSl); + byte[] vjBytes = hashObj.digest(toByteArray(tmp)); + V[j] = new BigInteger(1, vjBytes); + } + /* Step 11.2 */ + BigInteger W = V[0]; + for (int i = 1; i < n; i++) { + W = W.add(V[i].multiply(TWO.pow(i * outLen))); + } + W = W.add((V[n].mod(TWO.pow(b))).multiply(TWO.pow(n * outLen))); + /* Step 11.3 */ + BigInteger twoLm1 = TWO.pow(valueL - 1); + BigInteger X = W.add(twoLm1); + /* Step 11.4, 11.5 */ + BigInteger c = X.mod(resultQ.multiply(TWO)); + resultP = X.subtract(c.subtract(ONE)); + /* Step 11.6, 11.7 */ + if (resultP.compareTo(twoLm1) > -1 + && resultP.isProbablePrime(primeCertainty)) { + /* Step 11.8 */ + BigInteger[] result = {resultP, resultQ, seed, + BigInteger.valueOf(counter)}; + return result; + } + /* Step 11.9 */ + offset = offset.add(BigInteger.valueOf(n)).add(ONE); } - return null; - } + } + } /* @@ -262,31 +279,24 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { * * @param the g */ - BigInteger generateG(BigInteger p, BigInteger q) { + private static BigInteger generateG(BigInteger p, BigInteger q) { BigInteger h = ONE; + /* Step 1 */ BigInteger pMinusOneOverQ = (p.subtract(ONE)).divide(q); - BigInteger g = ONE; - while (g.compareTo(TWO) < 0) { - g = h.modPow(pMinusOneOverQ, p); + BigInteger resultG = ONE; + while (resultG.compareTo(TWO) < 0) { + /* Step 3 */ + resultG = h.modPow(pMinusOneOverQ, p); h = h.add(ONE); } - return g; - } - - /* - * Returns the SHA-1 digest of some data - */ - private byte[] SHA(byte[] array) { - sha.engineReset(); - sha.engineUpdate(array, 0, array.length); - return sha.engineDigest(); + return resultG; } /* * Converts the result of a BigInteger.toByteArray call to an exact * signed magnitude representation for any positive number. */ - private byte[] toByteArray(BigInteger bigInt) { + private static byte[] toByteArray(BigInteger bigInt) { byte[] result = bigInt.toByteArray(); if (result[0] == 0) { byte[] tmp = new byte[result.length - 1]; @@ -295,13 +305,4 @@ public class DSAParameterGenerator extends AlgorithmParameterGeneratorSpi { } return result; } - - /* - * XORs U2 into U1 - */ - private void xor(byte[] U1, byte[] U2) { - for (int i = 0; i < U1.length; i++) { - U1[i] ^= U2[i]; - } - } } diff --git a/src/share/classes/sun/security/provider/ParameterCache.java b/src/share/classes/sun/security/provider/ParameterCache.java index f263fb7ea2672a8a841f0910d63a1df2900be6e3..419bbd685221147aaea20e7eaa066d03aba5c5a4 100644 --- a/src/share/classes/sun/security/provider/ParameterCache.java +++ b/src/share/classes/sun/security/provider/ParameterCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package sun.security.provider; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.math.BigInteger; import java.security.*; @@ -55,11 +56,17 @@ public final class ParameterCache { private final static Map dhCache; /** - * Return cached DSA parameters for the given keylength, or null if none - * are available in the cache. + * Return cached DSA parameters for the given length combination of + * prime and subprime, or null if none are available in the cache. */ - public static DSAParameterSpec getCachedDSAParameterSpec(int keyLength) { - return dsaCache.get(Integer.valueOf(keyLength)); + public static DSAParameterSpec getCachedDSAParameterSpec(int primeLen, + int subprimeLen) { + // ensure the sum is unique in all cases, i.e. + // case#1: (512 <= p <= 1024) AND q=160 + // case#2: p=2048 AND q=224 + // case#3: p=2048 AND q=256 + // (NOT-YET-SUPPORTED)case#4: p=3072 AND q=256 + return dsaCache.get(Integer.valueOf(primeLen+subprimeLen)); } /** @@ -71,18 +78,39 @@ public final class ParameterCache { } /** - * Return DSA parameters for the given keylength. Uses cache if possible, - * generates new parameters and adds them to the cache otherwise. + * Return DSA parameters for the given primeLen. Uses cache if + * possible, generates new parameters and adds them to the cache + * otherwise. */ - public static DSAParameterSpec getDSAParameterSpec(int keyLength, + public static DSAParameterSpec getDSAParameterSpec(int primeLen, SecureRandom random) - throws NoSuchAlgorithmException, InvalidParameterSpecException { - DSAParameterSpec spec = getCachedDSAParameterSpec(keyLength); + throws NoSuchAlgorithmException, InvalidParameterSpecException, + InvalidAlgorithmParameterException { + if (primeLen <= 1024) { + return getDSAParameterSpec(primeLen, 160, random); + } else if (primeLen == 2048) { + return getDSAParameterSpec(primeLen, 224, random); + } else { + return null; + } + } + + /** + * Return DSA parameters for the given primeLen and subprimeLen. + * Uses cache if possible, generates new parameters and adds them to the + * cache otherwise. + */ + public static DSAParameterSpec getDSAParameterSpec(int primeLen, + int subprimeLen, SecureRandom random) + throws NoSuchAlgorithmException, InvalidParameterSpecException, + InvalidAlgorithmParameterException { + DSAParameterSpec spec = + getCachedDSAParameterSpec(primeLen, subprimeLen); if (spec != null) { return spec; } - spec = getNewDSAParameterSpec(keyLength, random); - dsaCache.put(Integer.valueOf(keyLength), spec); + spec = getNewDSAParameterSpec(primeLen, subprimeLen, random); + dsaCache.put(Integer.valueOf(primeLen + subprimeLen), spec); return spec; } @@ -107,28 +135,28 @@ public final class ParameterCache { } /** - * Return new DSA parameters for the given keylength. Do not lookup in - * cache and do not cache the newly generated parameters. This method - * really only exists for the legacy method + * Return new DSA parameters for the given length combination of prime and + * sub prime. Do not lookup in cache and do not cache the newly generated + * parameters. This method really only exists for the legacy method * DSAKeyPairGenerator.initialize(int, boolean, SecureRandom). */ - public static DSAParameterSpec getNewDSAParameterSpec(int keyLength, - SecureRandom random) - throws NoSuchAlgorithmException, InvalidParameterSpecException { + public static DSAParameterSpec getNewDSAParameterSpec(int primeLen, + int subprimeLen, SecureRandom random) + throws NoSuchAlgorithmException, InvalidParameterSpecException, + InvalidAlgorithmParameterException { AlgorithmParameterGenerator gen = AlgorithmParameterGenerator.getInstance("DSA"); - gen.init(keyLength, random); + DSAGenParameterSpec genParams = + new DSAGenParameterSpec(primeLen, subprimeLen); + gen.init(genParams, random); AlgorithmParameters params = gen.generateParameters(); DSAParameterSpec spec = params.getParameterSpec(DSAParameterSpec.class); return spec; } static { - // XXX change to ConcurrentHashMap once available - dhCache = Collections.synchronizedMap - (new HashMap()); - dsaCache = Collections.synchronizedMap - (new HashMap()); + dhCache = new ConcurrentHashMap(); + dsaCache = new ConcurrentHashMap(); /* * We support precomputed parameter for 512, 768 and 1024 bit @@ -210,17 +238,99 @@ public final class ParameterCache { "83dfe15ae59f06928b665e807b552564014c3bfecf" + "492a", 16); - dsaCache.put(Integer.valueOf(512), + dsaCache.put(Integer.valueOf(512+160), new DSAParameterSpec(p512, q512, g512)); - dsaCache.put(Integer.valueOf(768), + dsaCache.put(Integer.valueOf(768+160), new DSAParameterSpec(p768, q768, g768)); - dsaCache.put(Integer.valueOf(1024), + dsaCache.put(Integer.valueOf(1024+160), new DSAParameterSpec(p1024, q1024, g1024)); + /* + * L = 2048, N = 224 + * SEED = 584236080cfa43c09b02354135f4cc5198a19efada08bd866d601ba4 + * counter = 2666 + */ + BigInteger p2048_224 = + new BigInteger("8f7935d9b9aae9bfabed887acf4951b6f32ec59e3b" + + "af3718e8eac4961f3efd3606e74351a9c4183339b8" + + "09e7c2ae1c539ba7475b85d011adb8b47987754984" + + "695cac0e8f14b3360828a22ffa27110a3d62a99345" + + "3409a0fe696c4658f84bdd20819c3709a01057b195" + + "adcd00233dba5484b6291f9d648ef883448677979c" + + "ec04b434a6ac2e75e9985de23db0292fc1118c9ffa" + + "9d8181e7338db792b730d7b9e349592f6809987215" + + "3915ea3d6b8b4653c633458f803b32a4c2e0f27290" + + "256e4e3f8a3b0838a1c450e4e18c1a29a37ddf5ea1" + + "43de4b66ff04903ed5cf1623e158d487c608e97f21" + + "1cd81dca23cb6e380765f822e342be484c05763939" + + "601cd667", 16); + + BigInteger q2048_224 = + new BigInteger("baf696a68578f7dfdee7fa67c977c785ef32b233ba" + + "e580c0bcd5695d", 16); + + BigInteger g2048_224 = + new BigInteger("16a65c58204850704e7502a39757040d34da3a3478" + + "c154d4e4a5c02d242ee04f96e61e4bd0904abdac8f" + + "37eeb1e09f3182d23c9043cb642f88004160edf9ca" + + "09b32076a79c32a627f2473e91879ba2c4e744bd20" + + "81544cb55b802c368d1fa83ed489e94e0fa0688e32" + + "428a5c78c478c68d0527b71c9a3abb0b0be12c4468" + + "9639e7d3ce74db101a65aa2b87f64c6826db3ec72f" + + "4b5599834bb4edb02f7c90e9a496d3a55d535bebfc" + + "45d4f619f63f3dedbb873925c2f224e07731296da8" + + "87ec1e4748f87efb5fdeb75484316b2232dee553dd" + + "af02112b0d1f02da30973224fe27aeda8b9d4b2922" + + "d9ba8be39ed9e103a63c52810bc688b7e2ed4316e1" + + "ef17dbde", 16); + dsaCache.put(Integer.valueOf(2048+224), + new DSAParameterSpec(p2048_224, q2048_224, g2048_224)); + + /* + * L = 2048, N = 256 + * SEED = b0b4417601b59cbc9d8ac8f935cadaec4f5fbb2f23785609ae466748d9b5a536 + * counter = 497 + */ + BigInteger p2048_256 = + new BigInteger("95475cf5d93e596c3fcd1d902add02f427f5f3c721" + + "0313bb45fb4d5bb2e5fe1cbd678cd4bbdd84c9836b" + + "e1f31c0777725aeb6c2fc38b85f48076fa76bcd814" + + "6cc89a6fb2f706dd719898c2083dc8d896f84062e2" + + "c9c94d137b054a8d8096adb8d51952398eeca852a0" + + "af12df83e475aa65d4ec0c38a9560d5661186ff98b" + + "9fc9eb60eee8b030376b236bc73be3acdbd74fd61c" + + "1d2475fa3077b8f080467881ff7e1ca56fee066d79" + + "506ade51edbb5443a563927dbc4ba520086746175c" + + "8885925ebc64c6147906773496990cb714ec667304" + + "e261faee33b3cbdf008e0c3fa90650d97d3909c927" + + "5bf4ac86ffcb3d03e6dfc8ada5934242dd6d3bcca2" + + "a406cb0b", 16); + + BigInteger q2048_256 = + new BigInteger("f8183668ba5fc5bb06b5981e6d8b795d30b8978d43" + + "ca0ec572e37e09939a9773", 16); + + BigInteger g2048_256 = + new BigInteger("42debb9da5b3d88cc956e08787ec3f3a09bba5f48b" + + "889a74aaf53174aa0fbe7e3c5b8fcd7a53bef563b0" + + "e98560328960a9517f4014d3325fc7962bf1e04937" + + "0d76d1314a76137e792f3f0db859d095e4a5b93202" + + "4f079ecf2ef09c797452b0770e1350782ed57ddf79" + + "4979dcef23cb96f183061965c4ebc93c9c71c56b92" + + "5955a75f94cccf1449ac43d586d0beee43251b0b22" + + "87349d68de0d144403f13e802f4146d882e057af19" + + "b6f6275c6676c8fa0e3ca2713a3257fd1b27d0639f" + + "695e347d8d1cf9ac819a26ca9b04cb0eb9b7b03598" + + "8d15bbac65212a55239cfc7e58fae38d7250ab9991" + + "ffbc97134025fe8ce04c4399ad96569be91a546f49" + + "78693c7a", 16); + dsaCache.put(Integer.valueOf(2048+256), + new DSAParameterSpec(p2048_256, q2048_256, g2048_256)); // use DSA parameters for DH as well dhCache.put(Integer.valueOf(512), new DHParameterSpec(p512, g512)); dhCache.put(Integer.valueOf(768), new DHParameterSpec(p768, g768)); dhCache.put(Integer.valueOf(1024), new DHParameterSpec(p1024, g1024)); + dhCache.put(Integer.valueOf(2048), new DHParameterSpec(p2048_224, g2048_224)); } } diff --git a/src/share/classes/sun/security/provider/SunEntries.java b/src/share/classes/sun/security/provider/SunEntries.java index 3f0ef1084ced21ad50ad65ef73380d71e881cb32..3876acbf3be7193f09c26f308a3ee53f7ad16aac 100644 --- a/src/share/classes/sun/security/provider/SunEntries.java +++ b/src/share/classes/sun/security/provider/SunEntries.java @@ -47,6 +47,10 @@ import java.security.*; * SHA-2 family of hash functions includes SHA-224, SHA-256, SHA-384, * and SHA-512. * + * - SHA-224withDSA/SHA-256withDSA are the signature schemes + * described in FIPS 186-3. The associated object identifiers are + * "OID.2.16.840.1.101.3.4.3.1", and "OID.2.16.840.1.101.3.4.3.2". + * - DSA is the key generation scheme as described in FIPS 186. * Aliases for DSA include the OID strings "OID.1.3.14.3.2.12" * and "OID.1.2.840.10040.4.1". @@ -106,11 +110,15 @@ final class SunEntries { map.put("Signature.SHA1withDSA", "sun.security.provider.DSA$SHA1withDSA"); map.put("Signature.NONEwithDSA", "sun.security.provider.DSA$RawDSA"); map.put("Alg.Alias.Signature.RawDSA", "NONEwithDSA"); + map.put("Signature.SHA224withDSA", "sun.security.provider.DSA$SHA224withDSA"); + map.put("Signature.SHA256withDSA", "sun.security.provider.DSA$SHA256withDSA"); String dsaKeyClasses = "java.security.interfaces.DSAPublicKey" + "|java.security.interfaces.DSAPrivateKey"; map.put("Signature.SHA1withDSA SupportedKeyClasses", dsaKeyClasses); map.put("Signature.NONEwithDSA SupportedKeyClasses", dsaKeyClasses); + map.put("Signature.SHA224withDSA SupportedKeyClasses", dsaKeyClasses); + map.put("Signature.SHA256withDSA SupportedKeyClasses", dsaKeyClasses); map.put("Alg.Alias.Signature.DSA", "SHA1withDSA"); map.put("Alg.Alias.Signature.DSS", "SHA1withDSA"); @@ -124,6 +132,10 @@ final class SunEntries { map.put("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA1withDSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.13", "SHA1withDSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.27", "SHA1withDSA"); + map.put("Alg.Alias.Signature.OID.2.16.840.1.101.3.4.3.1", "SHA224withDSA"); + map.put("Alg.Alias.Signature.2.16.840.1.101.3.4.3.1", "SHA224withDSA"); + map.put("Alg.Alias.Signature.OID.2.16.840.1.101.3.4.3.2", "SHA256withDSA"); + map.put("Alg.Alias.Signature.2.16.840.1.101.3.4.3.2", "SHA256withDSA"); /* * Key Pair Generator engines @@ -143,6 +155,8 @@ final class SunEntries { map.put("Alg.Alias.MessageDigest.SHA-1", "SHA"); map.put("Alg.Alias.MessageDigest.SHA1", "SHA"); + map.put("Alg.Alias.MessageDigest.1.3.14.3.2.26", "SHA"); + map.put("Alg.Alias.MessageDigest.OID.1.3.14.3.2.26", "SHA"); map.put("MessageDigest.SHA-224", "sun.security.provider.SHA2$SHA224"); map.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.4", "SHA-224"); @@ -169,15 +183,17 @@ final class SunEntries { */ map.put("AlgorithmParameters.DSA", "sun.security.provider.DSAParameters"); - map.put("Alg.Alias.AlgorithmParameters.1.3.14.3.2.12", "DSA"); + map.put("Alg.Alias.AlgorithmParameters.OID.1.2.840.10040.4.1", "DSA"); map.put("Alg.Alias.AlgorithmParameters.1.2.840.10040.4.1", "DSA"); + map.put("Alg.Alias.AlgorithmParameters.1.3.14.3.2.12", "DSA"); /* * Key factories */ map.put("KeyFactory.DSA", "sun.security.provider.DSAKeyFactory"); - map.put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA"); + map.put("Alg.Alias.KeyFactory.OID.1.2.840.10040.4.1", "DSA"); map.put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA"); + map.put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA"); /* * Certificates @@ -234,9 +250,13 @@ final class SunEntries { /* * KeySize */ + map.put("Signature.NONEwithDSA KeySize", "1024"); map.put("Signature.SHA1withDSA KeySize", "1024"); - map.put("KeyPairGenerator.DSA KeySize", "1024"); - map.put("AlgorithmParameterGenerator.DSA KeySize", "1024"); + map.put("Signature.SHA224withDSA KeySize", "2048"); + map.put("Signature.SHA256withDSA KeySize", "2048"); + + map.put("KeyPairGenerator.DSA KeySize", "2048"); + map.put("AlgorithmParameterGenerator.DSA KeySize", "2048"); /* * Implementation type: software or hardware diff --git a/src/share/classes/sun/security/util/Debug.java b/src/share/classes/sun/security/util/Debug.java index 3356cf856e1098c3f54c8c86908852778920a1e3..5c666797036c78a7c24d80c2c035e53fb043d88b 100644 --- a/src/share/classes/sun/security/util/Debug.java +++ b/src/share/classes/sun/security/util/Debug.java @@ -70,15 +70,22 @@ public class Debug { System.err.println(); System.err.println("all turn on all debugging"); System.err.println("access print all checkPermission results"); + System.err.println("certpath PKIX CertPathBuilder and"); + System.err.println(" CertPathValidator debugging"); System.err.println("combiner SubjectDomainCombiner debugging"); System.err.println("gssloginconfig"); + System.err.println(" GSS LoginConfigImpl debugging"); System.err.println("configfile JAAS ConfigFile loading"); System.err.println("configparser JAAS ConfigFile parsing"); - System.err.println(" GSS LoginConfigImpl debugging"); System.err.println("jar jar verification"); System.err.println("logincontext login context results"); + System.err.println("jca JCA engine class debugging"); System.err.println("policy loading and granting"); System.err.println("provider security provider debugging"); + System.err.println("pkcs11 PKCS11 session manager debugging"); + System.err.println("pkcs11keystore"); + System.err.println(" PKCS11 KeyStore debugging"); + System.err.println("sunpkcs11 SunPKCS11 provider debugging"); System.err.println("scl permissions SecureClassLoader assigns"); System.err.println("ts timestamping"); System.err.println(); diff --git a/src/share/classes/sun/security/x509/AlgorithmId.java b/src/share/classes/sun/security/x509/AlgorithmId.java index 7124920956ddf7744b5ee44edb3cec6fe7673677..e2d6c60c11182b0909cb7b6279c1b931454e974e 100644 --- a/src/share/classes/sun/security/x509/AlgorithmId.java +++ b/src/share/classes/sun/security/x509/AlgorithmId.java @@ -498,6 +498,9 @@ public class AlgorithmId implements Serializable, DerEncoder { if (name.equalsIgnoreCase("EC")) { return EC_oid; } + if (name.equalsIgnoreCase("ECDH")) { + return AlgorithmId.ECDH_oid; + } // Common signature types if (name.equalsIgnoreCase("MD5withRSA") @@ -517,6 +520,12 @@ public class AlgorithmId implements Serializable, DerEncoder { || name.equalsIgnoreCase("SHA-1/DSA")) { return AlgorithmId.sha1WithDSA_oid; } + if (name.equalsIgnoreCase("SHA224WithDSA")) { + return AlgorithmId.sha224WithDSA_oid; + } + if (name.equalsIgnoreCase("SHA256WithDSA")) { + return AlgorithmId.sha256WithDSA_oid; + } if (name.equalsIgnoreCase("SHA1WithRSA") || name.equalsIgnoreCase("SHA1/RSA")) { return AlgorithmId.sha1WithRSAEncryption_oid; @@ -647,6 +656,7 @@ public class AlgorithmId implements Serializable, DerEncoder { public static final ObjectIdentifier DSA_oid; public static final ObjectIdentifier DSA_OIW_oid; public static final ObjectIdentifier EC_oid = oid(1, 2, 840, 10045, 2, 1); + public static final ObjectIdentifier ECDH_oid = oid(1, 3, 132, 1, 12); public static final ObjectIdentifier RSA_oid; public static final ObjectIdentifier RSAEncryption_oid; @@ -687,6 +697,10 @@ public class AlgorithmId implements Serializable, DerEncoder { public static final ObjectIdentifier shaWithDSA_OIW_oid; public static final ObjectIdentifier sha1WithDSA_OIW_oid; public static final ObjectIdentifier sha1WithDSA_oid; + public static final ObjectIdentifier sha224WithDSA_oid = + oid(2, 16, 840, 1, 101, 3, 4, 3, 1); + public static final ObjectIdentifier sha256WithDSA_oid = + oid(2, 16, 840, 1, 101, 3, 4, 3, 2); public static final ObjectIdentifier sha1WithECDSA_oid = oid(1, 2, 840, 10045, 4, 1); @@ -718,7 +732,6 @@ public class AlgorithmId implements Serializable, DerEncoder { public static ObjectIdentifier pbeWithSHA1AndRC2_40_oid = ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 6}); - static { /* * Note the preferred OIDs are named simply with no "OIW" or @@ -878,6 +891,8 @@ public class AlgorithmId implements Serializable, DerEncoder { nameTable.put(DSA_oid, "DSA"); nameTable.put(DSA_OIW_oid, "DSA"); nameTable.put(EC_oid, "EC"); + nameTable.put(ECDH_oid, "ECDH"); + nameTable.put(sha1WithECDSA_oid, "SHA1withECDSA"); nameTable.put(sha224WithECDSA_oid, "SHA224withECDSA"); nameTable.put(sha256WithECDSA_oid, "SHA256withECDSA"); @@ -888,6 +903,8 @@ public class AlgorithmId implements Serializable, DerEncoder { nameTable.put(sha1WithDSA_oid, "SHA1withDSA"); nameTable.put(sha1WithDSA_OIW_oid, "SHA1withDSA"); nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA"); + nameTable.put(sha224WithDSA_oid, "SHA224withDSA"); + nameTable.put(sha256WithDSA_oid, "SHA256withDSA"); nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA"); nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA"); nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA"); diff --git a/src/share/classes/sun/security/x509/CertificateIssuerUniqueIdentity.java b/src/share/classes/sun/security/x509/CertificateIssuerUniqueIdentity.java deleted file mode 100644 index 26595b0a639739b1026ebafcd3b4f5dc8f914d7b..0000000000000000000000000000000000000000 --- a/src/share/classes/sun/security/x509/CertificateIssuerUniqueIdentity.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. 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.security.x509; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Enumeration; - -import sun.security.util.*; - -/** - * This class defines the subject/issuer unique identity attribute - * for the Certificate. - * - * @author Amit Kapoor - * @author Hemma Prafullchandra - * @see CertAttrSet - */ -public class CertificateIssuerUniqueIdentity implements CertAttrSet { - private UniqueIdentity id; - - /** - * Identifier for this attribute, to be used with the - * get, set, delete methods of Certificate, x509 type. - */ - public static final String IDENT = "x509.info.issuerID"; - /** - * Sub attributes name for this CertAttrSet. - */ - public static final String NAME = "issuerID"; - public static final String ID = "id"; - - /** - * Default constructor for the certificate attribute. - * - * @param key the UniqueIdentity - */ - public CertificateIssuerUniqueIdentity(UniqueIdentity id) { - this.id = id; - } - - /** - * Create the object, decoding the values from the passed DER stream. - * - * @param in the DerInputStream to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateIssuerUniqueIdentity(DerInputStream in) - throws IOException { - id = new UniqueIdentity(in); - } - - /** - * Create the object, decoding the values from the passed stream. - * - * @param in the InputStream to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateIssuerUniqueIdentity(InputStream in) - throws IOException { - DerValue val = new DerValue(in); - id = new UniqueIdentity(val); - } - - /** - * Create the object, decoding the values from the passed DER value. - * - * @param in the DerValue to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateIssuerUniqueIdentity(DerValue val) - throws IOException { - id = new UniqueIdentity(val); - } - - /** - * Return the identity as user readable string. - */ - public String toString() { - if (id == null) return ""; - return (id.toString()); - } - - /** - * Encode the identity in DER form to the stream. - * - * @param out the DerOutputStream to marshal the contents to. - * @exception IOException on errors. - */ - public void encode(OutputStream out) throws IOException { - DerOutputStream tmp = new DerOutputStream(); - id.encode(tmp,DerValue.createTag(DerValue.TAG_CONTEXT,false,(byte)1)); - - out.write(tmp.toByteArray()); - } - - /** - * Set the attribute value. - */ - public void set(String name, Object obj) throws IOException { - if (!(obj instanceof UniqueIdentity)) { - throw new IOException("Attribute must be of type UniqueIdentity."); - } - if (name.equalsIgnoreCase(ID)) { - id = (UniqueIdentity)obj; - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateIssuerUniqueIdentity."); - } - } - - /** - * Get the attribute value. - */ - public UniqueIdentity get(String name) throws IOException { - if (name.equalsIgnoreCase(ID)) { - return (id); - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateIssuerUniqueIdentity."); - } - } - - /** - * Delete the attribute value. - */ - public void delete(String name) throws IOException { - if (name.equalsIgnoreCase(ID)) { - id = null; - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateIssuerUniqueIdentity."); - } - } - - /** - * Return an enumeration of names of attributes existing within this - * attribute. - */ - public Enumeration getElements() { - AttributeNameEnumeration elements = new AttributeNameEnumeration(); - elements.addElement(ID); - - return (elements.elements()); - } - - /** - * Return the name of this attribute. - */ - public String getName() { - return (NAME); - } -} diff --git a/src/share/classes/sun/security/x509/CertificateSubjectUniqueIdentity.java b/src/share/classes/sun/security/x509/CertificateSubjectUniqueIdentity.java deleted file mode 100644 index 7e439412b0be3cf0b2a93253342e82398af7bbeb..0000000000000000000000000000000000000000 --- a/src/share/classes/sun/security/x509/CertificateSubjectUniqueIdentity.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. 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.security.x509; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; - -import sun.security.util.*; - -/** - * This class defines the subject/issuer unique identity attribute - * for the Certificate. - * - * @author Amit Kapoor - * @author Hemma Prafullchandra - * @see CertAttrSet - */ -public class CertificateSubjectUniqueIdentity implements CertAttrSet { - /** - * Identifier for this attribute, to be used with the - * get, set, delete methods of Certificate, x509 type. - */ - public static final String IDENT = "x509.info.subjectID"; - /** - * Sub attributes name for this CertAttrSet. - */ - public static final String NAME = "subjectID"; - public static final String ID = "id"; - - private UniqueIdentity id; - - /** - * Default constructor for the certificate attribute. - * - * @param key the UniqueIdentity - */ - public CertificateSubjectUniqueIdentity(UniqueIdentity id) { - this.id = id; - } - - /** - * Create the object, decoding the values from the passed DER stream. - * - * @param in the DerInputStream to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateSubjectUniqueIdentity(DerInputStream in) - throws IOException { - id = new UniqueIdentity(in); - } - - /** - * Create the object, decoding the values from the passed stream. - * - * @param in the InputStream to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateSubjectUniqueIdentity(InputStream in) - throws IOException { - DerValue val = new DerValue(in); - id = new UniqueIdentity(val); - } - - /** - * Create the object, decoding the values from the passed DER value. - * - * @param in the DerValue to read the UniqueIdentity from. - * @exception IOException on decoding errors. - */ - public CertificateSubjectUniqueIdentity(DerValue val) - throws IOException { - id = new UniqueIdentity(val); - } - - /** - * Return the identity as user readable string. - */ - public String toString() { - if (id == null) return ""; - return(id.toString()); - } - - /** - * Encode the identity in DER form to the stream. - * - * @param out the DerOutputStream to marshal the contents to. - * @exception IOException on errors. - */ - public void encode(OutputStream out) throws IOException { - DerOutputStream tmp = new DerOutputStream(); - id.encode(tmp,DerValue.createTag(DerValue.TAG_CONTEXT,false,(byte)2)); - - out.write(tmp.toByteArray()); - } - - /** - * Set the attribute value. - */ - public void set(String name, Object obj) throws IOException { - if (!(obj instanceof UniqueIdentity)) { - throw new IOException("Attribute must be of type UniqueIdentity."); - } - if (name.equalsIgnoreCase(ID)) { - id = (UniqueIdentity)obj; - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateSubjectUniqueIdentity."); - } - } - - /** - * Get the attribute value. - */ - public UniqueIdentity get(String name) throws IOException { - if (name.equalsIgnoreCase(ID)) { - return(id); - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateSubjectUniqueIdentity."); - } - } - - /** - * Delete the attribute value. - */ - public void delete(String name) throws IOException { - if (name.equalsIgnoreCase(ID)) { - id = null; - } else { - throw new IOException("Attribute name not recognized by " + - "CertAttrSet: CertificateSubjectUniqueIdentity."); - } - } - - /** - * Return an enumeration of names of attributes existing within this - * attribute. - */ - public Enumeration getElements() { - AttributeNameEnumeration elements = new AttributeNameEnumeration(); - elements.addElement(ID); - - return (elements.elements()); - } - - /** - * Return the name of this attribute. - */ - public String getName() { - return (NAME); - } -} diff --git a/src/share/classes/sun/security/x509/X509CertImpl.java b/src/share/classes/sun/security/x509/X509CertImpl.java index efa6d4b3151fe4552844f4252a363ed742efd33f..b031de9f598a35be1a51563d31c35a235d67c522 100644 --- a/src/share/classes/sun/security/x509/X509CertImpl.java +++ b/src/share/classes/sun/security/x509/X509CertImpl.java @@ -1070,8 +1070,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { return null; try { UniqueIdentity id = (UniqueIdentity)info.get( - CertificateIssuerUniqueIdentity.NAME - + DOT + CertificateIssuerUniqueIdentity.ID); + X509CertInfo.ISSUER_ID); if (id == null) return null; else @@ -1091,8 +1090,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder { return null; try { UniqueIdentity id = (UniqueIdentity)info.get( - CertificateSubjectUniqueIdentity.NAME - + DOT + CertificateSubjectUniqueIdentity.ID); + X509CertInfo.SUBJECT_ID); if (id == null) return null; else diff --git a/src/share/classes/sun/security/x509/X509CertInfo.java b/src/share/classes/sun/security/x509/X509CertInfo.java index d654a5875a4d0896eb2a054d0012fd930f71a502..9379f270043daa05fb8217dbd4a8f02b857678d7 100644 --- a/src/share/classes/sun/security/x509/X509CertInfo.java +++ b/src/share/classes/sun/security/x509/X509CertInfo.java @@ -75,8 +75,8 @@ public class X509CertInfo implements CertAttrSet { public static final String VALIDITY = CertificateValidity.NAME; public static final String SUBJECT = CertificateSubjectName.NAME; public static final String KEY = CertificateX509Key.NAME; - public static final String ISSUER_ID = CertificateIssuerUniqueIdentity.NAME; - public static final String SUBJECT_ID = CertificateSubjectUniqueIdentity.NAME; + public static final String ISSUER_ID = "issuerID"; + public static final String SUBJECT_ID = "subjectID"; public static final String EXTENSIONS = CertificateExtensions.NAME; // X509.v1 data @@ -89,8 +89,8 @@ public class X509CertInfo implements CertAttrSet { protected CertificateX509Key pubKey = null; // X509.v2 & v3 extensions - protected CertificateIssuerUniqueIdentity issuerUniqueId = null; - protected CertificateSubjectUniqueIdentity subjectUniqueId = null; + protected UniqueIdentity issuerUniqueId = null; + protected UniqueIdentity subjectUniqueId = null; // X509.v3 extensions protected CertificateExtensions extensions = null; @@ -431,19 +431,11 @@ public class X509CertInfo implements CertAttrSet { break; case ATTR_ISSUER_ID: - if (suffix == null) { - setIssuerUniqueId(val); - } else { - issuerUniqueId.set(suffix, val); - } + setIssuerUniqueId(val); break; case ATTR_SUBJECT_ID: - if (suffix == null) { - setSubjectUniqueId(val); - } else { - subjectUniqueId.set(suffix, val); - } + setSubjectUniqueId(val); break; case ATTR_EXTENSIONS: @@ -529,18 +521,10 @@ public class X509CertInfo implements CertAttrSet { } break; case (ATTR_ISSUER_ID): - if (suffix == null) { - issuerUniqueId = null; - } else { - issuerUniqueId.delete(suffix); - } + issuerUniqueId = null; break; case (ATTR_SUBJECT_ID): - if (suffix == null) { - subjectUniqueId = null; - } else { - subjectUniqueId.delete(suffix); - } + subjectUniqueId = null; break; case (ATTR_EXTENSIONS): if (suffix == null) { @@ -626,23 +610,9 @@ public class X509CertInfo implements CertAttrSet { return(serialNum.get(suffix)); } case (ATTR_ISSUER_ID): - if (suffix == null) { - return(issuerUniqueId); - } else { - if (issuerUniqueId == null) - return null; - else - return(issuerUniqueId.get(suffix)); - } + return(issuerUniqueId); case (ATTR_SUBJECT_ID): - if (suffix == null) { - return(subjectUniqueId); - } else { - if (subjectUniqueId == null) - return null; - else - return(subjectUniqueId.get(suffix)); - } + return(subjectUniqueId); } return null; } @@ -711,7 +681,7 @@ public class X509CertInfo implements CertAttrSet { // Get the issuerUniqueId if present tmp = in.getDerValue(); if (tmp.isContextSpecific((byte)1)) { - issuerUniqueId = new CertificateIssuerUniqueIdentity(tmp); + issuerUniqueId = new UniqueIdentity(tmp); if (in.available() == 0) return; tmp = in.getDerValue(); @@ -719,7 +689,7 @@ public class X509CertInfo implements CertAttrSet { // Get the subjectUniqueId if present. if (tmp.isContextSpecific((byte)2)) { - subjectUniqueId = new CertificateSubjectUniqueIdentity(tmp); + subjectUniqueId = new UniqueIdentity(tmp); if (in.available() == 0) return; tmp = in.getDerValue(); @@ -814,10 +784,12 @@ public class X509CertInfo implements CertAttrSet { // Encode issuerUniqueId & subjectUniqueId. if (issuerUniqueId != null) { - issuerUniqueId.encode(tmp); + issuerUniqueId.encode(tmp, DerValue.createTag(DerValue.TAG_CONTEXT, + false,(byte)1)); } if (subjectUniqueId != null) { - subjectUniqueId.encode(tmp); + subjectUniqueId.encode(tmp, DerValue.createTag(DerValue.TAG_CONTEXT, + false,(byte)2)); } // Write all the extensions. @@ -946,11 +918,11 @@ public class X509CertInfo implements CertAttrSet { if (version.compare(CertificateVersion.V2) < 0) { throw new CertificateException("Invalid version"); } - if (!(val instanceof CertificateIssuerUniqueIdentity)) { + if (!(val instanceof UniqueIdentity)) { throw new CertificateException( "IssuerUniqueId class type invalid."); } - issuerUniqueId = (CertificateIssuerUniqueIdentity)val; + issuerUniqueId = (UniqueIdentity)val; } /** @@ -963,11 +935,11 @@ public class X509CertInfo implements CertAttrSet { if (version.compare(CertificateVersion.V2) < 0) { throw new CertificateException("Invalid version"); } - if (!(val instanceof CertificateSubjectUniqueIdentity)) { + if (!(val instanceof UniqueIdentity)) { throw new CertificateException( "SubjectUniqueId class type invalid."); } - subjectUniqueId = (CertificateSubjectUniqueIdentity)val; + subjectUniqueId = (UniqueIdentity)val; } /** diff --git a/src/share/classes/sun/util/PreHashedMap.java b/src/share/classes/sun/util/PreHashedMap.java index 2a257751a6ffe19e0ad991f6cb5e81bdb3df2f73..c09425ce6e4426cdca63deccd32123b0da9f4cd1 100644 --- a/src/share/classes/sun/util/PreHashedMap.java +++ b/src/share/classes/sun/util/PreHashedMap.java @@ -126,7 +126,7 @@ public abstract class PreHashedMap */ protected abstract void init(Object[] ht); - // @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") private V toV(Object x) { return (V)x; } @@ -259,8 +259,7 @@ public abstract class PreHashedMap return true; if (!(ob instanceof Map.Entry)) return false; - Map.Entry that - = (Map.Entry)ob; + Map.Entry that = (Map.Entry)ob; return ((this.getKey() == null ? that.getKey() == null : this.getKey() diff --git a/src/share/native/sun/awt/medialib/mlib_sys.c b/src/share/native/sun/awt/medialib/mlib_sys.c index e78e118c9695a44a0cc35b10914e1ab75046338b..70d052051fdddb20f886eb43e96c4d8d7273b019 100644 --- a/src/share/native/sun/awt/medialib/mlib_sys.c +++ b/src/share/native/sun/awt/medialib/mlib_sys.c @@ -29,6 +29,8 @@ #ifdef MACOSX #include #include +#else +#include #endif #include #include diff --git a/src/solaris/bin/jexec.c b/src/solaris/bin/jexec.c index b2efc99c48da9aa075a399434380edb0e82ea8ab..2e478d8f1a7facf565320231f666e255cf5995a0 100644 --- a/src/solaris/bin/jexec.c +++ b/src/solaris/bin/jexec.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,6 +80,7 @@ # include # include # include +# include "jni.h" # include "manifest_info.h" #endif diff --git a/src/solaris/classes/sun/awt/X11/XCheckboxMenuItemPeer.java b/src/solaris/classes/sun/awt/X11/XCheckboxMenuItemPeer.java index 00f08778a2d4c2279d41b12608984119ec849a70..485dce9f3c01abf0274e32e535ec254de75b6757 100644 --- a/src/solaris/classes/sun/awt/X11/XCheckboxMenuItemPeer.java +++ b/src/solaris/classes/sun/awt/X11/XCheckboxMenuItemPeer.java @@ -29,25 +29,10 @@ import java.awt.*; import java.awt.peer.*; import java.awt.event.*; -import java.lang.reflect.Field; -import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; class XCheckboxMenuItemPeer extends XMenuItemPeer implements CheckboxMenuItemPeer { - /************************************************ - * - * Data members - * - ************************************************/ - - /* - * CheckboxMenuItem's fields - */ - private final static Field f_state; - static { - f_state = SunToolkit.getField(CheckboxMenuItem.class, "state"); - } - /************************************************ * * Construction @@ -74,16 +59,8 @@ class XCheckboxMenuItemPeer extends XMenuItemPeer implements CheckboxMenuItemPee * ************************************************/ boolean getTargetState() { - MenuItem target = getTarget(); - if (target == null) { - return false; - } - try { - return f_state.getBoolean(target); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return false; + return AWTAccessor.getCheckboxMenuItemAccessor() + .getState((CheckboxMenuItem)getTarget()); } /************************************************ diff --git a/src/solaris/classes/sun/awt/X11/XEmbedCanvasPeer.java b/src/solaris/classes/sun/awt/X11/XEmbedCanvasPeer.java index 2d8a5285fcb568c0eb408fe029bacc762663bf31..683a33eeee5c88f8413218e083e5f67410061f0f 100644 --- a/src/solaris/classes/sun/awt/X11/XEmbedCanvasPeer.java +++ b/src/solaris/classes/sun/awt/X11/XEmbedCanvasPeer.java @@ -29,13 +29,8 @@ import java.awt.*; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetListener; import java.awt.event.*; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; -import java.awt.peer.*; import sun.awt.*; -import java.lang.reflect.*; +import sun.awt.AWTAccessor; import sun.util.logging.PlatformLogger; import java.util.*; import static sun.awt.X11.XEmbedHelper.*; @@ -454,16 +449,8 @@ public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener } } - static Field bdataField; static byte[] getBData(KeyEvent e) { - try { - if (bdataField == null) { - bdataField = SunToolkit.getField(java.awt.AWTEvent.class, "bdata"); - } - return (byte[])bdataField.get(e); - } catch (IllegalAccessException ex) { - return null; - } + return AWTAccessor.getAWTEventAccessor().getBData(e); } void forwardKeyEvent(KeyEvent e) { diff --git a/src/solaris/classes/sun/awt/X11/XEmbeddingContainer.java b/src/solaris/classes/sun/awt/X11/XEmbeddingContainer.java index 624dfd35c8be600a3842078f197f50a4a48087e0..2d313c107ce2a8cd531fb3290e707f4f268ff0aa 100644 --- a/src/solaris/classes/sun/awt/X11/XEmbeddingContainer.java +++ b/src/solaris/classes/sun/awt/X11/XEmbeddingContainer.java @@ -29,7 +29,7 @@ import java.awt.*; import java.util.HashMap; import java.awt.event.KeyEvent; import java.lang.reflect.*; -import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; public class XEmbeddingContainer extends XEmbedHelper implements XEventDispatcher { HashMap children = new HashMap(); @@ -127,20 +127,8 @@ public class XEmbeddingContainer extends XEmbedHelper implements XEventDispatche } } - static Field bdata; - byte[] getBData(KeyEvent e) { - try { - if (bdata == null) { - bdata = SunToolkit.getField(java.awt.AWTEvent.class, "bdata"); - } - return (byte[])bdata.get(e); - } catch (IllegalAccessException ex) { - return null; - } - } - void forwardKeyEvent(long child, KeyEvent e) { - byte[] bdata = getBData(e); + byte[] bdata = AWTAccessor.getAWTEventAccessor().getBData(e); long data = Native.toData(bdata); if (data == 0) { return; diff --git a/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java b/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java index a8703cb7877291d986d9f47c9675b6e6d5171784..3034fbc9f6337036e32efcc0efc43267cb118916 100644 --- a/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java +++ b/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java @@ -27,10 +27,7 @@ package sun.awt.X11; import java.awt.*; import java.awt.peer.ComponentPeer; -import java.awt.peer.LightweightPeer; import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import sun.awt.AWTAccessor; import sun.awt.GlobalCursorManager; @@ -38,23 +35,6 @@ import sun.awt.SunToolkit; public final class XGlobalCursorManager extends GlobalCursorManager { - private static Field field_pData; - private static Field field_type; - private static Class cursorClass; - private static Method method_setPData; - static { - cursorClass = java.awt.Cursor.class; - field_pData = SunToolkit.getField(cursorClass, "pData"); - field_type = SunToolkit.getField(cursorClass, "type"); - method_setPData = SunToolkit.getMethod(cursorClass, "setPData", new Class[] {long.class}); - if (field_pData == null || field_type == null || method_setPData == null) { - System.out.println("Unable to initialize XGlobalCursorManager: "); - Thread.dumpStack(); - - } - } - - // cached nativeContainer private WeakReference nativeContainer; @@ -213,8 +193,8 @@ public final class XGlobalCursorManager extends GlobalCursorManager { long pData = 0; int type = 0; try { - pData = field_pData.getLong(c); - type = field_type.getInt(c); + pData = AWTAccessor.getCursorAccessor().getPData(c); + type = AWTAccessor.getCursorAccessor().getType(c); } catch (Exception e) { @@ -284,7 +264,7 @@ public final class XGlobalCursorManager extends GlobalCursorManager { static void setPData(Cursor c, long pData) { try { - method_setPData.invoke(c, pData); + AWTAccessor.getCursorAccessor().setPData(c, pData); } catch (Exception e) { diff --git a/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java b/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java index 33163a802a428fa95e72a715069cde8afa009aa5..7de670903e80ba86b520e583cb822684c73d45ac 100644 --- a/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java +++ b/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java @@ -28,10 +28,9 @@ import java.awt.*; import java.awt.peer.*; import java.awt.event.*; -import java.lang.reflect.Field; import java.util.Vector; import sun.util.logging.PlatformLogger; -import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer { @@ -67,15 +66,6 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer { private final static int BAR_ITEM_MARGIN_TOP = 2; private final static int BAR_ITEM_MARGIN_BOTTOM = 2; - //fields - private static Field f_helpMenu; - private static Field f_menus; - - static { - f_helpMenu = SunToolkit.getField(MenuBar.class, "helpMenu"); - f_menus = SunToolkit.getField(MenuBar.class, "menus"); - } - /************************************************ * * Mapping data @@ -204,16 +194,12 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer { */ void postInit(XCreateWindowParams params) { super.postInit(params); - Vector targetMenuVector = null; - Menu targetHelpMenu = null; - try { - // Get menus from the target. - targetMenuVector = (Vector)f_menus.get(menuBarTarget); - targetHelpMenu = (Menu)f_helpMenu.get(menuBarTarget); - reloadItems(targetMenuVector); - } catch (IllegalAccessException iae) { - iae.printStackTrace(); - } + // Get menus from the target. + Vector targetMenuVector = AWTAccessor.getMenuBarAccessor() + .getMenus(menuBarTarget); + Menu targetHelpMenu = AWTAccessor.getMenuBarAccessor() + .getHelpMenu(menuBarTarget); + reloadItems(targetMenuVector); if (targetHelpMenu != null) { addHelpMenu(targetHelpMenu); } diff --git a/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java b/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java index c79fdc3bea31448df13cac705273ebc65026de35..496524c10b3f2073e66b6338e2fe369a889376b9 100644 --- a/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java +++ b/src/solaris/classes/sun/awt/X11/XMenuItemPeer.java @@ -28,10 +28,7 @@ import java.awt.*; import java.awt.peer.*; import java.awt.event.*; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; -import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; public class XMenuItemPeer implements MenuItemPeer { @@ -81,24 +78,6 @@ public class XMenuItemPeer implements MenuItemPeer { private final static int SEPARATOR_WIDTH = 20; private final static int SEPARATOR_HEIGHT = 5; - /* - * MenuItem's fields & methods - */ - private final static Field f_enabled; - private final static Field f_label; - private final static Field f_shortcut; - private final static Method m_getFont; - private final static Method m_isItemEnabled; - private final static Method m_getActionCommand; - static { - f_enabled = SunToolkit.getField(MenuItem.class, "enabled"); - f_label = SunToolkit.getField(MenuItem.class, "label"); - f_shortcut = SunToolkit.getField(MenuItem.class, "shortcut"); - - m_getFont = SunToolkit.getMethod(MenuComponent.class, "getFont_NoClientCode", null); - m_getActionCommand = SunToolkit.getMethod(MenuItem.class, "getActionCommandImpl", null); - m_isItemEnabled = SunToolkit.getMethod(MenuItem.class, "isItemEnabled", null); - } /************************************************ * * Text Metrics @@ -216,39 +195,22 @@ public class XMenuItemPeer implements MenuItemPeer { if (target == null) { return XWindow.getDefaultFont(); } - try { - return (Font)m_getFont.invoke(target, new Object[0]); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - return XWindow.getDefaultFont(); + return AWTAccessor.getMenuComponentAccessor().getFont_NoClientCode(target); } String getTargetLabel() { if (target == null) { return ""; } - try { - String label = (String)f_label.get(target); - return (label == null) ? "" : label; - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return ""; + String label = AWTAccessor.getMenuItemAccessor().getLabel(target); + return (label == null) ? "" : label; } boolean isTargetEnabled() { if (target == null) { return false; } - try { - return f_enabled.getBoolean(target); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return false; + return AWTAccessor.getMenuItemAccessor().isEnabled(target); } /** @@ -260,40 +222,21 @@ public class XMenuItemPeer implements MenuItemPeer { if (target == null) { return false; } - try { - return ((Boolean)m_isItemEnabled.invoke(target, new Object[0])).booleanValue(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - return false; + return AWTAccessor.getMenuItemAccessor().isItemEnabled(target); } String getTargetActionCommand() { if (target == null) { return ""; } - try { - return (String) m_getActionCommand.invoke(target,(Object[]) null); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - return ""; + return AWTAccessor.getMenuItemAccessor().getActionCommandImpl(target); } MenuShortcut getTargetShortcut() { if (target == null) { return null; } - try { - return (MenuShortcut)f_shortcut.get(target); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return null; + return AWTAccessor.getMenuItemAccessor().getShortcut(target); } String getShortcutText() { diff --git a/src/solaris/classes/sun/awt/X11/XMenuPeer.java b/src/solaris/classes/sun/awt/X11/XMenuPeer.java index a27253bc8e5741ff88ea780f8eea521fd2545eca..bd25cdbabcef0d7fedfc2c703ffa9a2bd3ab2ed9 100644 --- a/src/solaris/classes/sun/awt/X11/XMenuPeer.java +++ b/src/solaris/classes/sun/awt/X11/XMenuPeer.java @@ -27,10 +27,9 @@ package sun.awt.X11; import java.awt.*; import java.awt.peer.*; -import java.lang.reflect.Field; import java.util.Vector; import sun.util.logging.PlatformLogger; -import sun.awt.SunToolkit; +import sun.awt.AWTAccessor; public class XMenuPeer extends XMenuItemPeer implements MenuPeer { @@ -46,16 +45,6 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer { */ XMenuWindow menuWindow; - - /* - * Menu's fields & methods - */ - private final static Field f_items; - - static { - f_items = SunToolkit.getField(Menu.class, "items"); - } - /************************************************ * * Construction @@ -153,12 +142,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer { * ************************************************/ Vector getTargetItems() { - try { - return (Vector)f_items.get(getTarget()); - } catch (IllegalAccessException iae) { - iae.printStackTrace(); - return null; - } + return AWTAccessor.getMenuAccessor().getItems((Menu)getTarget()); } /************************************************ diff --git a/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java b/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java index f93bdfd49678bc8ea2439f7d7f6e697f3fe838a6..5dc3defea6a0249f75af1b148a8f81f50bed1967 100644 --- a/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java +++ b/src/solaris/classes/sun/awt/X11/XPopupMenuPeer.java @@ -28,15 +28,10 @@ import java.awt.*; import java.awt.peer.*; import java.awt.event.*; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - import java.util.Vector; +import sun.awt.AWTAccessor; import sun.util.logging.PlatformLogger; -import sun.awt.SunToolkit; - public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer { /************************************************ @@ -66,24 +61,6 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer { private final static int CAPTION_MARGIN_TOP = 4; private final static int CAPTION_SEPARATOR_HEIGHT = 6; - /* - * Menu's fields & methods - */ - //Fix for 6184485: Popup menu is not disabled on XToolkit even when calling setEnabled (false) - private final static Field f_enabled; - //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit - private final static Field f_label; - private final static Method m_getFont; - private final static Field f_items; - - static { - f_enabled = SunToolkit.getField(MenuItem.class, "enabled"); - f_label = SunToolkit.getField(MenuItem.class, "label"); - f_items = SunToolkit.getField(Menu.class, "items"); - m_getFont = SunToolkit.getMethod(MenuComponent.class, "getFont_NoClientCode", null); - } - - /************************************************ * * Construction @@ -96,7 +73,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer { /************************************************ * - * Implementaion of interface methods + * Implementation of interface methods * ************************************************/ /* @@ -189,27 +166,16 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer { if (popupMenuTarget == null) { return XWindow.getDefaultFont(); } - try { - return (Font)m_getFont.invoke(popupMenuTarget, new Object[0]); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - return XWindow.getDefaultFont(); + return AWTAccessor.getMenuComponentAccessor() + .getFont_NoClientCode(popupMenuTarget); } + //Fix for 6267144: PIT: Popup menu label is not shown, XToolkit String getTargetLabel() { if (target == null) { return ""; } - try { - String label = (String)f_label.get(popupMenuTarget); - return (label == null) ? "" : label; - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return ""; + return AWTAccessor.getMenuItemAccessor().getLabel(popupMenuTarget); } //Fix for 6184485: Popup menu is not disabled on XToolkit even when calling setEnabled (false) @@ -217,21 +183,14 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer { if (popupMenuTarget == null) { return false; } - try { - return f_enabled.getBoolean(popupMenuTarget); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return false; + return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget); } Vector getMenuTargetItems() { - try { - return (Vector)f_items.get(popupMenuTarget); - } catch (IllegalAccessException iae) { - iae.printStackTrace(); + if (popupMenuTarget == null) { return null; } + return AWTAccessor.getMenuAccessor().getItems(popupMenuTarget); } /************************************************ diff --git a/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java b/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java index afd8613f24d06e46dc9d5a3660b9663e27632739..f4956ed6399ff3167feea6f44b8f5396b8f73bd8 100644 --- a/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java +++ b/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java @@ -31,7 +31,6 @@ import java.awt.peer.*; import java.lang.reflect.*; import sun.awt.AWTAccessor; -import sun.awt.SunToolkit; class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollbarClient { diff --git a/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java b/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java index 6105172593c5f50b23d4690ed03aa115a8e42b5d..faa33eac9e245cd2ad6e2ec8df007137ff841672 100644 --- a/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java +++ b/src/solaris/classes/sun/awt/X11/XSystemTrayPeer.java @@ -27,10 +27,9 @@ package sun.awt.X11; import java.awt.*; import java.awt.peer.SystemTrayPeer; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import sun.awt.SunToolkit; import sun.awt.AppContext; +import sun.awt.AWTAccessor; import sun.util.logging.PlatformLogger; public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener { @@ -42,11 +41,6 @@ public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener { private volatile boolean available; private final XMSelection selection = new XMSelection("_NET_SYSTEM_TRAY"); - private static final Method firePropertyChangeMethod = - XToolkit.getMethod(SystemTray.class, "firePropertyChange", new Class[] {String.class, Object.class, Object.class}); - private static final Method addNotifyMethod = XToolkit.getMethod(TrayIcon.class, "addNotify", null); - private static final Method removeNotifyMethod = XToolkit.getMethod(TrayIcon.class, "removeNotify", null); - private static final int SCREEN = 0; private static final String SYSTEM_TRAY_PROPERTY_NAME = "systemTray"; private static final XAtom _NET_SYSTEM_TRAY = XAtom.get("_NET_SYSTEM_TRAY_S" + SCREEN); @@ -157,46 +151,45 @@ public class XSystemTrayPeer implements SystemTrayPeer, XMSelectionListener { return peerInstance; } - private void firePropertyChange(final String propertyName, final Object oldValue, final Object newValue) { + private void firePropertyChange(final String propertyName, + final Object oldValue, + final Object newValue) { Runnable runnable = new Runnable() { public void run() { - Object[] args = new Object[] {propertyName, oldValue, newValue}; - invokeMethod(firePropertyChangeMethod, target, args); + AWTAccessor.getSystemTrayAccessor() + .firePropertyChange(target, propertyName, oldValue, newValue); } }; invokeOnEachAppContext(runnable); } private void createTrayPeers() { - invokeOnEachTrayIcon(addNotifyMethod); + Runnable runnable = new Runnable() { + public void run() { + TrayIcon[] icons = target.getTrayIcons(); + try { + for (TrayIcon ti : icons) { + AWTAccessor.getTrayIconAccessor().addNotify(ti); + } + } catch (AWTException e) { + } + } + }; + invokeOnEachAppContext(runnable); } private void removeTrayPeers() { - invokeOnEachTrayIcon(removeNotifyMethod); - } - - private void invokeOnEachTrayIcon(final Method method) { Runnable runnable = new Runnable() { public void run() { TrayIcon[] icons = target.getTrayIcons(); for (TrayIcon ti : icons) { - invokeMethod(method, ti, (Object[]) null); + AWTAccessor.getTrayIconAccessor().removeNotify(ti); } } }; invokeOnEachAppContext(runnable); } - private void invokeMethod(Method method, Object obj, Object[] args) { - try{ - method.invoke(obj, args); - } catch (InvocationTargetException e){ - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - private void invokeOnEachAppContext(Runnable runnable) { for (AppContext appContext : AppContext.getAppContexts()) { SunToolkit.invokeLaterOnAppContext(appContext, runnable); diff --git a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index 952998f2286b88868fa69cf36ad8f9af46b3e5c6..fcefc02bbfd90acf0096466233e0a9c38e4e2cce 100644 --- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -1008,8 +1008,10 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { // loading SystemFlavorMap and associated classes. public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) - getClientProperty(XTextTransferHelper.getTransferHandlerKey()); - putClientProperty(XTextTransferHelper.getTransferHandlerKey(), + getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() + .getJComponent_TRANSFER_HANDLER()); + putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() + .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); diff --git a/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java b/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java index c67a2be1f5f31f7cb84431f8a49f57c0326e6047..3b069f78f023f7ccb1c5422d2de282d59397a016 100644 --- a/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java @@ -691,8 +691,10 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { // loading SystemFlavorMap and associated classes. public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler) - getClientProperty(XTextTransferHelper.getTransferHandlerKey()); - putClientProperty(XTextTransferHelper.getTransferHandlerKey(), + getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() + .getJComponent_TRANSFER_HANDLER()); + putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() + .getJComponent_TRANSFER_HANDLER(), newHandler); firePropertyChange("transferHandler", oldHandler, newHandler); diff --git a/src/solaris/classes/sun/awt/X11/XTextTransferHelper.java b/src/solaris/classes/sun/awt/X11/XTextTransferHelper.java deleted file mode 100644 index d57d02f04235868450651eb48f8ef6b97586cf9f..0000000000000000000000000000000000000000 --- a/src/solaris/classes/sun/awt/X11/XTextTransferHelper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2003, 2007, 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.awt.X11; - -import java.lang.reflect.Field; -import sun.awt.SunToolkit; - -class XTextTransferHelper { - private static Object transferHandlerKey = null; - static Object getTransferHandlerKey() { - if (transferHandlerKey == null) { - try { - Class clazz = Class.forName("javax.swing.ClientPropertyKey"); - Field field = SunToolkit.getField(clazz, "JComponent_TRANSFER_HANDLER"); - transferHandlerKey = field.get(null); - } catch (IllegalAccessException ex) { - return null; - } catch (ClassNotFoundException cnfe) { - cnfe.printStackTrace(); - } - } - return transferHandlerKey; - } -} diff --git a/src/solaris/classes/sun/awt/X11/XToolkit.java b/src/solaris/classes/sun/awt/X11/XToolkit.java index e49f78338d2e116cf78c4c1a9546d281e024f8e8..9db352d0cb2254ce04265178a7ebee77add20bfb 100644 --- a/src/solaris/classes/sun/awt/X11/XToolkit.java +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java @@ -41,8 +41,6 @@ import java.awt.im.spi.InputMethodDescriptor; import java.awt.image.ColorModel; import java.awt.peer.*; import java.beans.PropertyChangeListener; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; @@ -50,10 +48,10 @@ import javax.swing.LookAndFeel; import javax.swing.UIDefaults; import sun.awt.*; import sun.font.FontConfigManager; -import sun.font.FontManager; import sun.java2d.SunGraphicsEnvironment; import sun.misc.PerformanceLogger; import sun.print.PrintJob2D; +import sun.security.action.GetPropertyAction; import sun.security.action.GetBooleanAction; import sun.util.logging.PlatformLogger; @@ -113,7 +111,6 @@ public final class XToolkit extends UNIXToolkit implements Runnable { private static volatile int screenWidth = -1, screenHeight = -1; // Dimensions of default screen static long awt_defaultFg; // Pixel private static XMouseInfoPeer xPeer; - private static Method m_removeSourceEvents; static { initSecurityWarning(); @@ -131,8 +128,6 @@ public final class XToolkit extends UNIXToolkit implements Runnable { initIDs(); setBackingStoreType(); } - m_removeSourceEvents = SunToolkit.getMethod(EventQueue.class, "removeSourceEvents", new Class[] {Object.class, Boolean.TYPE}) ; - noisyAwtHandler = AccessController.doPrivileged(new GetBooleanAction("sun.awt.noisyerrorhandler")); } @@ -223,7 +218,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable { static void initSecurityWarning() { // Enable warning only for internal builds - String runtime = getSystemProperty("java.runtime.version"); + String runtime = AccessController.doPrivileged( + new GetPropertyAction("java.runtime.version")); securityWarningEnabled = (runtime != null && runtime.contains("internal")); } @@ -1101,8 +1097,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable { */ public synchronized static boolean getSunAwtDisableGtkFileDialogs() { if (sunAwtDisableGtkFileDialogs == null) { - sunAwtDisableGtkFileDialogs = - getBooleanSystemProperty("sun.awt.disableGtkFileDialogs"); + sunAwtDisableGtkFileDialogs = AccessController.doPrivileged( + new GetBooleanAction("sun.awt.disableGtkFileDialogs")); } return sunAwtDisableGtkFileDialogs.booleanValue(); } @@ -2090,17 +2086,11 @@ public final class XToolkit extends UNIXToolkit implements Runnable { return null; } - static void removeSourceEvents(EventQueue queue, Object source, boolean removeAllEvents) { - try { - m_removeSourceEvents.invoke(queue, source, removeAllEvents); - } - catch (IllegalAccessException e) - { - e.printStackTrace(); - } - catch (InvocationTargetException e) { - e.printStackTrace(); - } + static void removeSourceEvents(EventQueue queue, + Object source, + boolean removeAllEvents) { + AWTAccessor.getEventQueueAccessor() + .removeSourceEvents(queue, source, removeAllEvents); } public boolean isAlwaysOnTopSupported() { diff --git a/src/solaris/classes/sun/awt/X11/XWindow.java b/src/solaris/classes/sun/awt/X11/XWindow.java index 85494407b2b4dae8093fcc3d4be524f3dbb0fcfe..a4c039c207401f767811082f6767adba58588496 100644 --- a/src/solaris/classes/sun/awt/X11/XWindow.java +++ b/src/solaris/classes/sun/awt/X11/XWindow.java @@ -126,10 +126,6 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { native void getWindowBounds(long window, long x, long y, long width, long height); private native static void initIDs(); - private static Field isPostedField; - private static Field rawCodeField; - private static Field primaryLevelUnicodeField; - private static Field extendedKeyCodeField; static { initIDs(); } @@ -398,20 +394,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { static Method m_sendMessage; static void sendEvent(final AWTEvent e) { - if (isPostedField == null) { - isPostedField = SunToolkit.getField(AWTEvent.class, "isPosted"); - } // The uses of this method imply that the incoming event is system-generated SunToolkit.setSystemGenerated(e); PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { public void run() { - try { - isPostedField.setBoolean(e, true); - } catch (IllegalArgumentException e) { - assert(false); - } catch (IllegalAccessException e) { - assert(false); - } + AWTAccessor.getAWTEventAccessor().setPosted(e); ((Component)e.getSource()).dispatchEvent(e); } }, PeerEvent.ULTIMATE_PRIORITY_EVENT); @@ -1428,16 +1415,8 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { } - static Field bdata; static void setBData(KeyEvent e, byte[] data) { - try { - if (bdata == null) { - bdata = SunToolkit.getField(java.awt.AWTEvent.class, "bdata"); - } - bdata.set(e, data); - } catch (IllegalAccessException ex) { - assert false; - } + AWTAccessor.getAWTEventAccessor().setBData(e, data); } public void postKeyEvent(int id, long when, int keyCode, int keyChar, @@ -1447,15 +1426,6 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { { long jWhen = XToolkit.nowMillisUTC_offset(when); int modifiers = getModifiers(state, 0, keyCode); - if (rawCodeField == null) { - rawCodeField = XToolkit.getField(KeyEvent.class, "rawCode"); - } - if (primaryLevelUnicodeField == null) { - primaryLevelUnicodeField = XToolkit.getField(KeyEvent.class, "primaryLevelUnicode"); - } - if (extendedKeyCodeField == null) { - extendedKeyCodeField = XToolkit.getField(KeyEvent.class, "extendedKeyCode"); - } KeyEvent ke = new KeyEvent((Component)getEventSource(), id, jWhen, modifiers, keyCode, (char)keyChar, keyLocation); @@ -1463,15 +1433,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { byte[] data = Native.toBytes(event, eventSize); setBData(ke, data); } - try { - rawCodeField.set(ke, rawCode); - primaryLevelUnicodeField.set(ke, (long)unicodeFromPrimaryKeysym); - extendedKeyCodeField.set(ke, (long)extendedKeyCode); - } catch (IllegalArgumentException e) { - assert(false); - } catch (IllegalAccessException e) { - assert(false); - } + + AWTAccessor.KeyEventAccessor kea = AWTAccessor.getKeyEventAccessor(); + kea.setRawCode(ke, rawCode); + kea.setPrimaryLevelUnicode(ke, (long)unicodeFromPrimaryKeysym); + kea.setExtendedKeyCode(ke, (long)extendedKeyCode); postEventToEventQueue(ke); } diff --git a/src/solaris/classes/sun/awt/X11/XlibWrapper.java b/src/solaris/classes/sun/awt/X11/XlibWrapper.java index 7edc012b63585b14bfd710b1a82b595d87da1cc4..2d8fc851d0663ff31786882f59311b81cca32174 100644 --- a/src/solaris/classes/sun/awt/X11/XlibWrapper.java +++ b/src/solaris/classes/sun/awt/X11/XlibWrapper.java @@ -27,6 +27,7 @@ package sun.awt.X11; import java.security.AccessController; import java.security.PrivilegedAction; +import sun.security.action.GetPropertyAction; import sun.misc.*; final public class XlibWrapper @@ -590,12 +591,8 @@ static native String XSetLocaleModifiers(String modifier_list); static final boolean isBuildInternal; static { - String dataModelProp = (String)AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - return System.getProperty("sun.arch.data.model"); - } - }); + String dataModelProp = AccessController.doPrivileged( + new GetPropertyAction("sun.arch.data.model")); try { dataModel = Integer.parseInt(dataModelProp); } catch (Exception e) { @@ -647,7 +644,8 @@ static native String XSetLocaleModifiers(String modifier_list); } private static boolean getBuildInternal() { - String javaVersion = XToolkit.getSystemProperty("java.version"); + String javaVersion = AccessController.doPrivileged( + new GetPropertyAction("java.version")); return javaVersion != null && javaVersion.contains("internal"); } diff --git a/src/windows/classes/sun/awt/windows/WCanvasPeer.java b/src/windows/classes/sun/awt/windows/WCanvasPeer.java index bba468cfe79ed018f6b3c9bc931f0d7f4d69dcd7..254b01f9dbd933c1485520aef90ef8626430a26e 100644 --- a/src/windows/classes/sun/awt/windows/WCanvasPeer.java +++ b/src/windows/classes/sun/awt/windows/WCanvasPeer.java @@ -27,7 +27,6 @@ package sun.awt.windows; import java.awt.*; import java.awt.peer.*; import java.lang.ref.WeakReference; -import java.lang.reflect.Method; import sun.awt.SunToolkit; import sun.awt.Win32GraphicsDevice; import sun.awt.PaintEventDispatcher; diff --git a/src/windows/classes/sun/awt/windows/WMouseDragGestureRecognizer.java b/src/windows/classes/sun/awt/windows/WMouseDragGestureRecognizer.java index 27084fe44cfc0716158464f19fb6dd2434a3a94d..c0e37a9751087bb7ba45a7dc706f5a38b165d30b 100644 --- a/src/windows/classes/sun/awt/windows/WMouseDragGestureRecognizer.java +++ b/src/windows/classes/sun/awt/windows/WMouseDragGestureRecognizer.java @@ -39,8 +39,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.lang.reflect.*; - import sun.awt.dnd.SunDragSourceContextPeer; /** diff --git a/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java b/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java index 5f3e3570aecb269e40976d374d41913cc6b35596..afc0ff6404ffb39922f2fcd03625646f5d23a1d4 100644 --- a/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java +++ b/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java @@ -26,9 +26,7 @@ package sun.awt.windows; import java.awt.*; import java.awt.peer.*; -import java.lang.reflect.Field; -import sun.awt.SunToolkit; import sun.awt.AWTAccessor; public class WPopupMenuPeer extends WMenuPeer implements PopupMenuPeer { diff --git a/src/windows/classes/sun/awt/windows/WWindowPeer.java b/src/windows/classes/sun/awt/windows/WWindowPeer.java index 450535e7d723bfa085a1656de94d8300c492942e..07f0c1c08f901ec2db581ae47ffc9ab3a7c099a4 100644 --- a/src/windows/classes/sun/awt/windows/WWindowPeer.java +++ b/src/windows/classes/sun/awt/windows/WWindowPeer.java @@ -31,8 +31,6 @@ import java.awt.peer.*; import java.beans.*; -import java.lang.reflect.*; - import java.util.*; import java.util.List; import sun.util.logging.PlatformLogger; diff --git a/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java b/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java index bbd6621447e658fd3da813f2cf03c6808f2bfebd..b33d2e0cd4ee78800f16aee023f9b83e1f5237f8 100644 --- a/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java +++ b/test/com/sun/crypto/provider/Cipher/DES/PaddingTest.java @@ -195,7 +195,7 @@ public class PaddingTest { private static void diff(String fname1, String fname2) throws Exception { if (!Arrays.equals(Files.readAllBytes(Paths.get(fname1)), - Files.readAllBytes(Paths.get(fname1)))) { + Files.readAllBytes(Paths.get(fname2)))) { throw new Exception( "files " + fname1 + " and " + fname2 + " differ"); } diff --git a/test/com/sun/crypto/provider/KeyAgreement/TestExponentSize.java b/test/com/sun/crypto/provider/KeyAgreement/TestExponentSize.java index 78316efb7ee7b3b285876f4e77000634aed5fc4e..6226fe9191d83d544dbe13315240957b859d51c0 100644 --- a/test/com/sun/crypto/provider/KeyAgreement/TestExponentSize.java +++ b/test/com/sun/crypto/provider/KeyAgreement/TestExponentSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /** * @test - * @bug 6330287 6331386 + * @bug 6330287 6331386 7044060 * @summary verify that DHKeyPairGenerator returns keys of the expected size * (modulus and exponent) * -and- @@ -57,7 +57,8 @@ public class TestExponentSize { * Sizes and values for various lengths. */ private enum Sizes { - two56(256), three84(384), five12(512), seven68(768), ten24(1024); + two56(256), three84(384), five12(512), seven68(768), ten24(1024), + twenty48(2048); private final int intSize; private final BigInteger bigIntValue; @@ -82,7 +83,8 @@ public class TestExponentSize { KeyPair kp; KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", "SunJCE"); - // Sun's default uses a default psize of 1024/lsize of 512 + // Sun's default uses a default psize of 1024 and + // lsize of (pSize / 2) but at least 384 bits kp = kpg.generateKeyPair(); checkKeyPair(kp, Sizes.ten24, Sizes.five12); @@ -114,6 +116,20 @@ public class TestExponentSize { kp = kpg.generateKeyPair(); checkKeyPair(kp, Sizes.seven68, Sizes.three84); + // test w/ only pSize + kpg.initialize(Sizes.twenty48.getIntSize()); + kp = kpg.generateKeyPair(); + checkKeyPair(kp, Sizes.twenty48, Sizes.ten24); + + publicKey = (DHPublicKey)kp.getPublic(); + p = publicKey.getParams().getP(); + g = publicKey.getParams().getG(); + + // test w/ all values specified + kpg.initialize(new DHParameterSpec(p, g, Sizes.five12.getIntSize())); + kp = kpg.generateKeyPair(); + checkKeyPair(kp, Sizes.twenty48, Sizes.five12); + System.out.println("OK"); } diff --git a/test/javax/swing/JColorChooser/Test4380468.java b/test/java/awt/Frame/HugeFrame/HugeFrame.java similarity index 58% rename from test/javax/swing/JColorChooser/Test4380468.java rename to test/java/awt/Frame/HugeFrame/HugeFrame.java index 915794f22e85f641e9377b5168731689b252d683..8da7ce0df9a04c66eb824690e6746e48c6865449 100644 --- a/test/javax/swing/JColorChooser/Test4380468.java +++ b/test/java/awt/Frame/HugeFrame/HugeFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,19 +22,28 @@ */ /* - * @test - * @bug 4380468 - * @summary JColorChooser's HSB panel should display all RGB digits - * @author Andrey Pikalev - * @run applet/manual=yesno Test4380468.html - */ + @test + @bug 7160609 + @summary A window with huge dimensions shouldn't crash JVM + @author anthony.petrov@oracle.com: area=awt.toplevel + @run main HugeFrame +*/ + +import java.awt.*; + +public class HugeFrame { + public static void main(String[] args) throws Exception { + Frame f = new Frame("Huge"); + + // 8193+ should already produce a crash, but let's go extreme... + f.setBounds(10, 10, 30000, 500000); + f.setVisible(true); -import java.awt.Color; -import javax.swing.JApplet; -import javax.swing.JColorChooser; + // We would crash by now if the bug wasn't fixed + Thread.sleep(1000); + System.err.println(f.getBounds()); -public class Test4380468 extends JApplet { - public void init() { - add(new JColorChooser(Color.GREEN)); + // Cleanup + f.dispose(); } } diff --git a/test/java/beans/Introspector/4520754/Test4520754.java b/test/java/beans/Introspector/4520754/Test4520754.java index e94a1667d53d22d3c0f5e59d0d17c690b1dff4e7..affb71257dcf1f857338d31df2f452f0fc4bbfa5 100644 --- a/test/java/beans/Introspector/4520754/Test4520754.java +++ b/test/java/beans/Introspector/4520754/Test4520754.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ public class Test4520754 { public static void main(String[] args) { // ensure that 4168475 does not regress test4168475(Component.class); - // AWT classes (sun.beans.infos.ComponentBeanInfo) + // AWT classes (com.sun.beans.infos.ComponentBeanInfo) test(null, Button.class, Component.class, List.class, Menu.class, Panel.class); // Swing classes (dt.jar) test(null, JApplet.class, JButton.class, JCheckBox.class); diff --git a/test/java/beans/Introspector/Test7189112.java b/test/java/beans/Introspector/Test7189112.java new file mode 100644 index 0000000000000000000000000000000000000000..61042f9467eec18100d708c04cfee68de4c9d1a9 --- /dev/null +++ b/test/java/beans/Introspector/Test7189112.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7189112 + * @summary Tests overridden getter + * @author Sergey Malenkov + */ + +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; + +public class Test7189112 { + + public static void main(String[] args) throws IntrospectionException { + for (PropertyDescriptor pd : Introspector.getBeanInfo(MyBean.class).getPropertyDescriptors()) { + if (pd.getName().equals("value") && (null == pd.getWriteMethod())) { + throw new Error("The property setter is not found"); + } + } + } + + public static class BaseBean { + + private Object value; + + public Object getValue() { + return this.value; + } + + public void setValue(Object value) { + this.value = value; + } + } + + public static class MyBean extends BaseBean { + @Override + public String getValue() { + return (String) super.getValue(); + } + } +} diff --git a/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java b/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java index e07254a2d169163aff45f4226f58aefd575f9c35..ff9067d6ab268ac0168e515b03926f6658404346 100644 --- a/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java +++ b/test/java/beans/PropertyEditor/6380849/TestPropertyEditor.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,8 @@ * @bug 6380849 * @summary Tests PropertyEditor finder * @author Sergey Malenkov + * @compile -XDignore.symbol.file TestPropertyEditor.java + * @run main TestPropertyEditor */ import editors.SecondBeanEditor; @@ -36,17 +38,17 @@ import java.awt.Font; import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; -import sun.beans.editors.BooleanEditor; -import sun.beans.editors.ByteEditor; -import sun.beans.editors.ColorEditor; -import sun.beans.editors.DoubleEditor; -import sun.beans.editors.EnumEditor; -import sun.beans.editors.FloatEditor; -import sun.beans.editors.FontEditor; -import sun.beans.editors.IntegerEditor; -import sun.beans.editors.LongEditor; -import sun.beans.editors.ShortEditor; -import sun.beans.editors.StringEditor; +import com.sun.beans.editors.BooleanEditor; +import com.sun.beans.editors.ByteEditor; +import com.sun.beans.editors.ColorEditor; +import com.sun.beans.editors.DoubleEditor; +import com.sun.beans.editors.EnumEditor; +import com.sun.beans.editors.FloatEditor; +import com.sun.beans.editors.FontEditor; +import com.sun.beans.editors.IntegerEditor; +import com.sun.beans.editors.LongEditor; +import com.sun.beans.editors.ShortEditor; +import com.sun.beans.editors.StringEditor; public class TestPropertyEditor implements Runnable { diff --git a/test/java/beans/PropertyEditor/Test6963811.java b/test/java/beans/PropertyEditor/Test6963811.java index a3e6c89169a1dc23bf25439386616eb9f94e3cee..d864cc623bca208383a250415868e47fe40708c0 100644 --- a/test/java/beans/PropertyEditor/Test6963811.java +++ b/test/java/beans/PropertyEditor/Test6963811.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,10 +26,12 @@ * @bug 6963811 * @summary Tests deadlock in PropertyEditorManager * @author Sergey Malenkov + * @compile -XDignore.symbol.file Test6963811.java + * @run main Test6963811 */ import java.beans.PropertyEditorManager; -import sun.beans.editors.StringEditor; +import com.sun.beans.editors.StringEditor; public class Test6963811 implements Runnable { private final long time; diff --git a/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java b/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java index f8c77f7708edfae7ac7204e5e3124a5dcb43e120..b8bcd7e140ccf315b8b6a0d5b41eec49a21e1699 100644 --- a/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java +++ b/test/java/lang/management/MemoryMXBean/CollectionUsageThreshold.java @@ -48,7 +48,7 @@ public class CollectionUsageThreshold { private static Map result = new HashMap<>(); private static boolean trace = false; private static boolean testFailed = false; - private static final int EXPECTED_NUM_POOLS = 2; + private static int numMemoryPools = 1; private static final int NUM_GCS = 3; private static final int THRESHOLD = 10; private static Checker checker; @@ -129,14 +129,19 @@ public class CollectionUsageThreshold { for (MemoryPoolMXBean p : pools) { MemoryUsage u = p.getUsage(); if (p.isUsageThresholdSupported() && p.isCollectionUsageThresholdSupported()) { + if (p.getName().toLowerCase().contains("perm")) { + // if we have a "perm gen" pool increase the number of expected + // memory pools by one. + numMemoryPools++; + } PoolRecord pr = new PoolRecord(p); result.put(p.getName(), pr); - if (result.size() == EXPECTED_NUM_POOLS) { + if (result.size() == numMemoryPools) { break; } } } - if (result.size() != EXPECTED_NUM_POOLS) { + if (result.size() != numMemoryPools) { throw new RuntimeException("Unexpected number of selected pools"); } @@ -209,7 +214,7 @@ public class CollectionUsageThreshold { public void run() { while (true) { try { - signals.acquire(EXPECTED_NUM_POOLS); + signals.acquire(numMemoryPools); checkResult(); } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/test/java/lang/management/MemoryMXBean/MemoryTest.java b/test/java/lang/management/MemoryMXBean/MemoryTest.java index b2cf9e2f69c6d27ca74821681c0e301b7443a1df..ae84e832ad32f417c972d0266108ce4fc084ff3f 100644 --- a/test/java/lang/management/MemoryMXBean/MemoryTest.java +++ b/test/java/lang/management/MemoryMXBean/MemoryTest.java @@ -58,8 +58,11 @@ public class MemoryTest { // They are: Copy/Scavenger + MSC + CodeCache manager // (or equivalent for other collectors) // Number of GC memory managers = 2 - private static int[] expectedMinNumPools = {3, 2}; - private static int[] expectedMaxNumPools = {3, 4}; + + // Hotspot VM 1.8+ after perm gen removal is expected to have only + // one non-heap memory pool + private static int[] expectedMinNumPools = {3, 1}; + private static int[] expectedMaxNumPools = {3, 1}; private static int expectedNumGCMgrs = 2; private static int expectedNumMgrs = expectedNumGCMgrs + 1; private static String[] types = { "heap", "non-heap" }; @@ -80,6 +83,7 @@ public class MemoryTest { private static void checkMemoryPools() throws Exception { List pools = ManagementFactory.getMemoryPoolMXBeans(); + boolean hasPerm = false; int[] numPools = new int[NUM_TYPES]; for (ListIterator iter = pools.listIterator(); iter.hasNext();) { @@ -90,6 +94,16 @@ public class MemoryTest { if (pool.getType() == MemoryType.NON_HEAP) { numPools[NONHEAP]++; } + if (pool.getName().toLowerCase().contains("perm")) { + hasPerm = true; + } + } + + if (hasPerm) { + // If the VM has perm gen there will be between 2 and 4 non heap + // pools (4 if class data sharing is used) + expectedMinNumPools[NONHEAP] = 2; + expectedMaxNumPools[NONHEAP] = 4; } // Check the number of Memory pools diff --git a/test/java/net/Authenticator/B4678055.java b/test/java/net/Authenticator/B4678055.java index 60ef8c0976925816f02a7fe870a00026b6fa4f55..3618c2a9d662d8baad9680fa2c5fbf502cd95163 100644 --- a/test/java/net/Authenticator/B4678055.java +++ b/test/java/net/Authenticator/B4678055.java @@ -25,7 +25,7 @@ * @test * @bug 4678055 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main B4678055 * @summary Basic Authentication fails with multiple realms */ @@ -119,13 +119,13 @@ public class B4678055 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new B4678055(), 1, 10, 0); + server = new TestHttpServer (new B4678055(), 1, 10, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html"); client ("http://localhost:"+server.getLocalPort()+"/d2/foo.html"); diff --git a/test/java/net/Authenticator/B4722333.java b/test/java/net/Authenticator/B4722333.java index 214908f87ac3af1a723c144c7f604dcbda9501f8..5dad9c058b5a761fd541d03b4873f60881d103fb 100644 --- a/test/java/net/Authenticator/B4722333.java +++ b/test/java/net/Authenticator/B4722333.java @@ -25,7 +25,7 @@ * @test * @bug 4722333 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main B4722333 * @summary JRE Proxy Authentication Not Working with ISA2000 */ @@ -114,13 +114,13 @@ public class B4722333 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new B4722333(), 1, 10, 0); + server = new TestHttpServer (new B4722333(), 1, 10, 0); System.out.println ("Server started: listening on port: " + server.getLocalPort()); client ("http://localhost:"+server.getLocalPort()+"/d1/d2/d3/foo.html"); client ("http://localhost:"+server.getLocalPort()+"/ASD/d3/x.html"); diff --git a/test/java/net/Authenticator/B4759514.java b/test/java/net/Authenticator/B4759514.java index b21aff769c1732e6c5404715ae027d42922dfc9d..586ae0f55206f42cf2b80df672cd66a4fd20f811 100644 --- a/test/java/net/Authenticator/B4759514.java +++ b/test/java/net/Authenticator/B4759514.java @@ -25,7 +25,7 @@ * @test * @bug 4759514 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main B4759514 * @summary Digest Authentication is erroniously quoting the nc value, contrary to RFC 2617 */ @@ -91,13 +91,13 @@ public class B4759514 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new B4759514(), 1, 10, 0); + server = new TestHttpServer (new B4759514(), 1, 10, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html"); } catch (Exception e) { diff --git a/test/java/net/Authenticator/B4769350.java b/test/java/net/Authenticator/B4769350.java index 86bff121b3b5a530913dad34cd7851f427539cde..fc00cabce792a9001cd28e8a82cdc62b3c6c4e31 100644 --- a/test/java/net/Authenticator/B4769350.java +++ b/test/java/net/Authenticator/B4769350.java @@ -25,7 +25,7 @@ * @test * @bug 4769350 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction AbstractCallback + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction AbstractCallback * @run main/othervm B4769350 server * @run main/othervm B4769350 proxy * @summary proxy authentication username and password caching only works in serial case @@ -142,10 +142,10 @@ public class B4769350 { switch (count) { case 0: errorReply (req, "Basic realm=\"realm1\""); - HttpServer.rendezvous ("one", 2); + TestHttpServer.rendezvous ("one", 2); break; case 1: - HttpServer.waitForCondition ("cond2"); + TestHttpServer.waitForCondition ("cond2"); okReply (req); break; default: @@ -158,11 +158,11 @@ public class B4769350 { switch (count) { case 0: errorReply (req, "Basic realm=\"realm2\""); - HttpServer.rendezvous ("one", 2); - HttpServer.setCondition ("cond1"); + TestHttpServer.rendezvous ("one", 2); + TestHttpServer.setCondition ("cond1"); break; case 1: - HttpServer.waitForCondition ("cond2"); + TestHttpServer.waitForCondition ("cond2"); okReply (req); break; default: @@ -174,7 +174,7 @@ public class B4769350 { switch (count) { case 0: errorReply (req, "Basic realm=\"realm1\""); - HttpServer.rendezvous ("two", 2); + TestHttpServer.rendezvous ("two", 2); break; case 1: okReply (req); @@ -188,8 +188,8 @@ public class B4769350 { switch (count) { case 0: errorReply (req, "Basic realm=\"realm2\""); - HttpServer.rendezvous ("two", 2); - HttpServer.setCondition ("cond2"); + TestHttpServer.rendezvous ("two", 2); + TestHttpServer.setCondition ("cond2"); break; case 1: okReply (req); @@ -207,7 +207,7 @@ public class B4769350 { void doT2a (HttpTransaction req, int count) throws IOException { /* This will be called several times */ if (count == 1) { - HttpServer.setCondition ("T2cond1"); + TestHttpServer.setCondition ("T2cond1"); } errorReply (req, "Basic realm=\"realm3\""); } @@ -233,7 +233,7 @@ public class B4769350 { switch (count) { case 0: proxyReply (req, "Basic realm=\"proxy\""); - HttpServer.setCondition ("T3cond1"); + TestHttpServer.setCondition ("T3cond1"); break; case 1: errorReply (req, "Basic realm=\"realm4\""); @@ -260,7 +260,7 @@ public class B4769350 { } }; - static HttpServer server; + static TestHttpServer server; static MyAuthenticator auth = new MyAuthenticator (); static int redirects = 4; @@ -276,7 +276,7 @@ public class B4769350 { c4 = new Client (authority, "/test/realm2/t1d", false); c1.start(); c2.start(); - HttpServer.waitForCondition ("cond1"); + TestHttpServer.waitForCondition ("cond1"); c3.start(); c4.start(); c1.join(); c2.join(); c3.join(); c4.join(); @@ -294,7 +294,7 @@ public class B4769350 { c5 = new Client (authority, "/test/realm3/t2a", true); c6 = new Client (authority, "/test/realm3/t2b", false); c5.start (); - HttpServer.waitForCondition ("T2cond1"); + TestHttpServer.waitForCondition ("T2cond1"); c6.start (); c5.join(); c6.join(); @@ -313,7 +313,7 @@ public class B4769350 { c8 = new Client (authority, "/test/realm4/t3b", false); c9 = new Client (authority, "/test/realm4/t3c", false); c7.start (); - HttpServer.waitForCondition ("T3cond1"); + TestHttpServer.waitForCondition ("T3cond1"); c8.start (); c9.start (); c7.join(); c8.join(); c9.join(); @@ -333,7 +333,7 @@ public class B4769350 { Authenticator.setDefault (auth); boolean proxy = args[0].equals ("proxy"); try { - server = new HttpServer (new CallBack(), 10, 1, 0); + server = new TestHttpServer (new CallBack(), 10, 1, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); if (proxy) { System.setProperty ("http.proxyHost", "localhost"); diff --git a/test/java/net/Authenticator/B4921848.java b/test/java/net/Authenticator/B4921848.java index 810f4ab0653863296bf094c15409ef252c9e9df6..cc7a0b89d629c6effbcbe63d87842e46ba575f96 100644 --- a/test/java/net/Authenticator/B4921848.java +++ b/test/java/net/Authenticator/B4921848.java @@ -25,7 +25,7 @@ * @test * @bug 4921848 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main/othervm -Dhttp.auth.preference=basic B4921848 * @summary Allow user control over authentication schemes */ @@ -82,13 +82,13 @@ public class B4921848 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new B4921848(), 1, 10, 0); + server = new TestHttpServer (new B4921848(), 1, 10, 0); System.out.println ("Server started: listening on port: " + server.getLocalPort()); client ("http://localhost:"+server.getLocalPort()+"/d1/d2/d3/foo.html"); } catch (Exception e) { diff --git a/test/java/net/Authenticator/B4933582.java b/test/java/net/Authenticator/B4933582.java index 393ea00aed802477699f07cd35f6038354a74945..090b49d7f201575f2196b42a66faf49cf55ffa29 100644 --- a/test/java/net/Authenticator/B4933582.java +++ b/test/java/net/Authenticator/B4933582.java @@ -119,7 +119,7 @@ public class B4933582 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { firstTime = args[0].equals ("first"); @@ -128,11 +128,11 @@ public class B4933582 implements HttpCallback { CacheImpl cache; try { if (firstTime) { - server = new HttpServer (new B4933582(), 1, 10, 0); + server = new TestHttpServer (new B4933582(), 1, 10, 0); cache = new CacheImpl (server.getLocalPort()); } else { cache = new CacheImpl (); - server = new HttpServer(new B4933582(), 1, 10, cache.getPort()); + server = new TestHttpServer(new B4933582(), 1, 10, cache.getPort()); } AuthCacheValue.setAuthCache (cache); System.out.println ("Server: listening on port: " + server.getLocalPort()); diff --git a/test/java/net/Authenticator/B4962064.java b/test/java/net/Authenticator/B4962064.java index c6eb8e774fabf69666376fa234e62cc109e6ab9e..9f99e03ab37108ea6b760738cd29e5ca3980f836 100644 --- a/test/java/net/Authenticator/B4962064.java +++ b/test/java/net/Authenticator/B4962064.java @@ -25,7 +25,7 @@ * @test * @bug 4962064 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main/othervm B4962064 * @summary Extend Authenticator to provide access to request URI and server/proxy */ @@ -85,12 +85,12 @@ public class B4962064 implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; static URL urlsave; public static void main (String[] args) throws Exception { try { - server = new HttpServer (new B4962064(), 1, 10, 0); + server = new TestHttpServer (new B4962064(), 1, 10, 0); int port = server.getLocalPort(); System.setProperty ("http.proxyHost", "localhost"); System.setProperty ("http.proxyPort", Integer.toString (port)); diff --git a/test/java/net/CookieHandler/CookieManagerTest.java b/test/java/net/CookieHandler/CookieManagerTest.java index ebad3591b3ce2fa1588ae62b384e2570957290bd..7d61a458c3dc9929b3728c8278040e24f461fc04 100644 --- a/test/java/net/CookieHandler/CookieManagerTest.java +++ b/test/java/net/CookieHandler/CookieManagerTest.java @@ -26,7 +26,7 @@ * @summary Unit test for java.net.CookieManager * @bug 6244040 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main/othervm -ea CookieManagerTest * @author Edward Wang */ @@ -38,7 +38,7 @@ import sun.net.www.MessageHeader; public class CookieManagerTest { static CookieHttpTransaction httpTrans; - static HttpServer server; + static TestHttpServer server; public static void main(String[] args) throws Exception { startHttpServer(); @@ -52,7 +52,7 @@ public class CookieManagerTest { public static void startHttpServer() { try { httpTrans = new CookieHttpTransaction(); - server = new HttpServer(httpTrans, 1, 1, 0); + server = new TestHttpServer(httpTrans, 1, 1, 0); } catch (IOException e) { e.printStackTrace(); } diff --git a/test/java/net/InetAddress/GetLocalHostWithSM.java b/test/java/net/InetAddress/GetLocalHostWithSM.java index 2ffd13f616ef18488c3935af2ab51aec9d16e101..1afe502f437c4f22fa74275b57c2e2a68ae029fe 100644 --- a/test/java/net/InetAddress/GetLocalHostWithSM.java +++ b/test/java/net/InetAddress/GetLocalHostWithSM.java @@ -41,14 +41,13 @@ public class GetLocalHostWithSM { public static void main(String[] args) throws Exception { // try setting the local hostname - try { - System.setProperty("host.name", InetAddress. - getLocalHost(). - getHostName()); - } catch (UnknownHostException e) { - System.out.println("Cannot find the local hostname, " + - "no nameserver entry found"); + InetAddress localHost = InetAddress.getLocalHost(); + if (localHost.isLoopbackAddress()) { + System.err.println("Local host name is resolved into a loopback address. Quit now!"); + return; } + System.setProperty("host.name", localHost. + getHostName()); String policyFileName = System.getProperty("test.src", ".") + "/" + "policy.file"; System.setProperty("java.security.policy", policyFileName); @@ -66,6 +65,7 @@ public class GetLocalHostWithSM { new MyAction(), null); if (localHost1.equals(localHost2)) { + System.out.println("localHost1 = " + localHost1); throw new RuntimeException("InetAddress.getLocalHost() test " + " fails. localHost2 should be " + " the real address instead of " + diff --git a/test/java/net/ProxySelector/LoopbackAddresses.java b/test/java/net/ProxySelector/LoopbackAddresses.java index 2c1b6e71df621924698a95168a855471368c24f0..54c74ab1abe97368ed07b97fe9c0212167b09cec 100644 --- a/test/java/net/ProxySelector/LoopbackAddresses.java +++ b/test/java/net/ProxySelector/LoopbackAddresses.java @@ -25,7 +25,7 @@ * @bug 4924226 * @summary PIT: Can no launch jnlp application via 127.0.0.1 address on the web server * @library ../../../sun/net/www/httptest/ - * @build ClosedChannelList HttpServer HttpTransaction HttpCallback + * @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback * @compile LoopbackAddresses.java * @run main/othervm LoopbackAddresses */ @@ -39,7 +39,7 @@ import java.io.*; */ public class LoopbackAddresses implements HttpCallback { - static HttpServer server; + static TestHttpServer server; public void request (HttpTransaction req) { req.setResponseEntityBody ("Hello ."); @@ -52,7 +52,7 @@ public class LoopbackAddresses implements HttpCallback { public static void main(String[] args) { try { - server = new HttpServer (new LoopbackAddresses(), 1, 10, 0); + server = new TestHttpServer (new LoopbackAddresses(), 1, 10, 0); ProxyServer pserver = new ProxyServer(InetAddress.getByName("localhost"), server.getLocalPort()); // start proxy server new Thread(pserver).start(); diff --git a/test/java/net/ProxySelector/ProxyTest.java b/test/java/net/ProxySelector/ProxyTest.java index 634d146dac4fbab2ece3701285c206b52578732b..44a16fb02863ab2819473a1129cfc53899e6c53b 100644 --- a/test/java/net/ProxySelector/ProxyTest.java +++ b/test/java/net/ProxySelector/ProxyTest.java @@ -26,7 +26,7 @@ * @bug 4696512 * @summary HTTP client: Improve proxy server configuration and selection * @library ../../../sun/net/www/httptest/ - * @build ClosedChannelList HttpServer HttpTransaction HttpCallback + * @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback * @compile ProxyTest.java * @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 ProxyTest */ @@ -36,7 +36,7 @@ import java.io.*; import java.util.ArrayList; public class ProxyTest implements HttpCallback { - static HttpServer server; + static TestHttpServer server; public ProxyTest() { } @@ -74,7 +74,7 @@ public class ProxyTest implements HttpCallback { throw new RuntimeException("Default ProxySelector is null"); ProxySelector.setDefault(new MyProxySelector()); try { - server = new HttpServer (new ProxyTest(), 1, 10, 0); + server = new TestHttpServer (new ProxyTest(), 1, 10, 0); URL url = new URL("http://localhost:"+server.getLocalPort()); System.out.println ("client opening connection to: " + url); HttpURLConnection urlc = (HttpURLConnection)url.openConnection (); diff --git a/test/java/net/URL/PerConnectionProxy.java b/test/java/net/URL/PerConnectionProxy.java index 22cf82aed64814ec60dbb16c5cb49d0f2483395d..72e431d8d3f11bc32b527c0b35d03fae0b1fb14a 100644 --- a/test/java/net/URL/PerConnectionProxy.java +++ b/test/java/net/URL/PerConnectionProxy.java @@ -25,7 +25,7 @@ * @bug 4920526 * @summary Needs per connection proxy support for URLs * @library ../../../sun/net/www/httptest/ - * @build ClosedChannelList HttpServer HttpTransaction HttpCallback + * @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback * @compile PerConnectionProxy.java * @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 PerConnectionProxy */ @@ -35,7 +35,7 @@ import java.io.*; import sun.net.www.*; public class PerConnectionProxy implements HttpCallback { - static HttpServer server; + static TestHttpServer server; public void request (HttpTransaction req) { req.setResponseEntityBody ("Hello ."); @@ -48,7 +48,7 @@ public class PerConnectionProxy implements HttpCallback { public static void main(String[] args) { try { - server = new HttpServer (new PerConnectionProxy(), 1, 10, 0); + server = new TestHttpServer (new PerConnectionProxy(), 1, 10, 0); ProxyServer pserver = new ProxyServer(InetAddress.getByName("localhost"), server.getLocalPort()); // start proxy server new Thread(pserver).start(); diff --git a/test/java/net/URLConnection/B5052093.java b/test/java/net/URLConnection/B5052093.java index 2446fa5262737db00da6cafb69445e1cdef78470..48552eaef833017b02cab4306e11a4d09602dece 100644 --- a/test/java/net/URLConnection/B5052093.java +++ b/test/java/net/URLConnection/B5052093.java @@ -25,7 +25,7 @@ * @test * @bug 5052093 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main B5052093 * @summary URLConnection doesn't support large files */ @@ -34,7 +34,7 @@ import java.io.*; import sun.net.www.protocol.file.FileURLConnection; public class B5052093 implements HttpCallback { - private static HttpServer server; + private static TestHttpServer server; private static long testSize = ((long) (Integer.MAX_VALUE)) + 2; public static class LargeFile extends File { @@ -63,7 +63,7 @@ public class B5052093 implements HttpCallback { } public static void main(String[] args) throws Exception { - server = new HttpServer(new B5052093(), 1, 10, 0); + server = new TestHttpServer(new B5052093(), 1, 10, 0); try { URL url = new URL("http://localhost:"+server.getLocalPort()+"/foo"); URLConnection conn = url.openConnection(); diff --git a/test/java/util/Currency/PropertiesTest.java b/test/java/util/Currency/PropertiesTest.java index e59ec7bd39c2d7a88999c2287fd517d5639f6298..ab78ec08f3a4bcaff8ada0880059ba5a407d03cb 100644 --- a/test/java/util/Currency/PropertiesTest.java +++ b/test/java/util/Currency/PropertiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,11 +22,12 @@ */ import java.io.*; +import java.text.*; import java.util.*; import java.util.regex.*; public class PropertiesTest { - public static void main(String[] s) { + public static void main(String[] s) throws Exception { for (int i = 0; i < s.length; i ++) { if ("-d".equals(s[i])) { i++; @@ -76,7 +77,7 @@ public class PropertiesTest { pw.close(); } - private static void compare(String beforeFile, String afterFile) { + private static void compare(String beforeFile, String afterFile) throws Exception { // load file contents Properties before = new Properties(); Properties after = new Properties(); @@ -114,11 +115,23 @@ public class PropertiesTest { // test each replacements keys = p.stringPropertyNames(); Pattern propertiesPattern = - Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])"); + Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + + "([0-3])\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + + "\\d{2}:\\d{2})?"); for (String key: keys) { String val = p.getProperty(key); + try { + if (countOccurrences(val, ',') == 3 && !isPastCutoverDate(val)) { + System.out.println("Skipping since date is in future"); + continue; // skip since date in future (no effect) + } + } catch (ParseException pe) { + // swallow - currency class should not honour this value + continue; + } String afterVal = after.getProperty(key); System.out.printf("Testing key: %s, val: %s... ", key, val); + System.out.println("AfterVal is : " + afterVal); Matcher m = propertiesPattern.matcher(val.toUpperCase(Locale.ROOT)); if (!m.find()) { @@ -131,7 +144,6 @@ public class PropertiesTest { // ignore this continue; } - Matcher mAfter = propertiesPattern.matcher(afterVal); mAfter.find(); @@ -164,4 +176,29 @@ public class PropertiesTest { throw new RuntimeException(sb.toString()); } } + + private static boolean isPastCutoverDate(String s) + throws IndexOutOfBoundsException, NullPointerException, ParseException { + String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); + format.setTimeZone(TimeZone.getTimeZone("GMT")); + format.setLenient(false); + + long time = format.parse(dateString).getTime(); + if (System.currentTimeMillis() - time >= 0L) { + return true; + } else { + return false; + } + } + + private static int countOccurrences(String value, char match) { + int count = 0; + for (char c : value.toCharArray()) { + if (c == match) { + ++count; + } + } + return count; + } } diff --git a/test/java/util/Currency/PropertiesTest.sh b/test/java/util/Currency/PropertiesTest.sh index 304d102827a046da8a18bcdcab8a02a3717edf2f..f016eed3d812639feda4451f2e1b386f90bef420 100644 --- a/test/java/util/Currency/PropertiesTest.sh +++ b/test/java/util/Currency/PropertiesTest.sh @@ -1,7 +1,7 @@ #!/bin/sh # # @test -# @bug 6332666 +# @bug 6332666 7180362 # @summary tests the capability of replacing the currency data with user # specified currency properties file # @build PropertiesTest diff --git a/test/java/util/Currency/currency.properties b/test/java/util/Currency/currency.properties index f09e00fb22fa6e8b17473e9971c62d02c375c264..ce3c7bba79b3f25ec928f7c9d9533e63b1828b92 100644 --- a/test/java/util/Currency/currency.properties +++ b/test/java/util/Currency/currency.properties @@ -2,9 +2,19 @@ # Test data for replacing the currency data # JP=JPZ,123,2 -US=euR,978,2 +ES=ESD,877,2 +US=euR,978,2,2001-01-01T00:00:00 +CM=IED,111,2, 2004-01-01T00:70:00 +SB=EUR,111,2, 2099-01-01T00:00:00 ZZ = ZZZ , 999 , 3 +NO=EUR ,978 ,2, 2099-01-01T00:00:00 # invalid entries GB=123 FR=zzzzz.123 +DE=2009-01-01T00:00:00,EUR,111,2 +IE=euR,111,2,#testcomment +=euR,111,2, 2099-01-01-00-00-00 +FM=DED,194,2,eeee-01-01T00:00:00 +PE=EUR ,978 ,2, 20399-01-01T00:00:00 +MX=SSS,493,2,2001-01-01-00-00-00 diff --git a/test/javax/swing/JColorChooser/Test4380468.html b/test/javax/swing/JColorChooser/Test4380468.html deleted file mode 100644 index fbbba0d2e64d20d7674a88209c60a411a988b260..0000000000000000000000000000000000000000 --- a/test/javax/swing/JColorChooser/Test4380468.html +++ /dev/null @@ -1,17 +0,0 @@ - - -1. Click the HSB tab at the ColorChooser. -2. Click in the lower left corner of the gradient palette - in order to select a color such that all three RGB values - are single digit colors (such as 0, 0, 0 or 5, 3, 1). -3. Click another tab, then click back to the HSB tab. -4. Now click the lighter colors that should have - 2 and 3 digit RGB values (in the upper right corner). - -If all digits of each RGB value are shown then test passes. -If only the last digit of their values are shown then test fails. - - - - - diff --git a/test/javax/swing/JSplitPane/4201995/bug4201995.java b/test/javax/swing/JSplitPane/4201995/bug4201995.java new file mode 100644 index 0000000000000000000000000000000000000000..9d0f5971de2072e29e31f7064e908ca45c8bc347 --- /dev/null +++ b/test/javax/swing/JSplitPane/4201995/bug4201995.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4201995 + * @summary Tests that JSplitPane is opaque + * @author Scott Violet + */ + +import javax.swing.*; + +public class bug4201995 { + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + boolean expectedOpaqueValue = !"Nimbus".equals(UIManager.getLookAndFeel().getName()); + JSplitPane sp = new JSplitPane(); + + if (sp.isOpaque() != expectedOpaqueValue) { + throw new RuntimeException("JSplitPane has incorrect default opaque value"); + } + } + }); + } +} diff --git a/test/javax/swing/JTable/4235420/bug4235420.java b/test/javax/swing/JTable/4235420/bug4235420.java new file mode 100644 index 0000000000000000000000000000000000000000..388bb076060343ceb6254e74ca0f3c4109b10cb0 --- /dev/null +++ b/test/javax/swing/JTable/4235420/bug4235420.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 4235420 + @summary Tests that JTable delays creating Renderers and Editors + @author Peter Zhelezniakov +*/ + +import javax.swing.*; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class bug4235420 { + + public static void main(String[] argv) throws Exception { + if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) { + System.out.println("The test is skipped for Nimbus"); + + return; + } + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + Table table = new Table(); + + table.test(); + } + }); + } + + private static class Table extends JTable { + public void test() { + // Renderers + Class[] rendererClasses = {Object.class, Number.class, Date.class, ImageIcon.class, Boolean.class}; + + Map copy = new HashMap(defaultRenderersByColumnClass); + + for (Class rendererClass : rendererClasses) { + Object obj = copy.get(rendererClass); + + if (obj instanceof TableCellRenderer) { + throw new Error("Failed: TableCellRenderer created for " + + rendererClass.getClass().getName()); + } + } + + // Editors + Class[] editorClasses = {Object.class, Number.class, Boolean.class}; + + copy = new HashMap(defaultEditorsByColumnClass); + + for (Class editorClass : editorClasses) { + Object obj = copy.get(editorClass); + + if (obj instanceof TableCellEditor) { + throw new Error("Failed: TableCellEditor created for " + + editorClass.getClass().getName()); + } + } + } + } +} diff --git a/test/javax/swing/JTable/7188612/JTableAccessibleGetLocationOnScreen.java b/test/javax/swing/JTable/7188612/JTableAccessibleGetLocationOnScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..51ea97726e97abd842981c6be4d4c41100fa1775 --- /dev/null +++ b/test/javax/swing/JTable/7188612/JTableAccessibleGetLocationOnScreen.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + +/* @test + * @bug 7188612 + * @summary AccessibleTableHeader and AccessibleJTableCell should stick to + * AccessibleComponent.getLocationOnScreen api. + * @author Frank Ding + */ + +import javax.accessibility.AccessibleComponent; +import javax.accessibility.AccessibleTable; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JTable; +import javax.swing.SwingUtilities; + +public class JTableAccessibleGetLocationOnScreen { + private static JFrame frame; + private static JTable table; + + public static void main(String[] args) throws Exception { + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + constructInEDT(); + try { + assertGetLocation(); + } finally { + frame.dispose(); + } + } + }); + + } + + private static void constructInEDT() { + String[] columnNames = { "col1", "col2", }; + Object[][] data = { { "row1, col1", "row1, col2" }, + { "row2, col1", "row2, col2" }, }; + + frame = new JFrame( + "JTable AccessibleTableHeader and AccessibleJTableCell test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + table = new JTable(data, columnNames); + frame.add(table); + frame.pack(); + } + + private static void assertGetLocation() { + // the frame is now invisible + // test getLocationOnScreen() of + // JTable$AccessibleJTable$AccessibleJTableHeaderCell + // and JTable$AccessibleJTable$AccessibleJTableCell + AccessibleTable accessibleTable = (AccessibleTable) table + .getAccessibleContext(); + AccessibleTable header = accessibleTable.getAccessibleColumnHeader(); + AccessibleComponent accessibleComp1 = (AccessibleComponent) header + .getAccessibleAt(0, 0); + // getLocation() must be null according to its javadoc and no exception + // is thrown + if (null != accessibleComp1.getLocationOnScreen()) { + throw new RuntimeException( + "JTable$AccessibleJTable$AccessibleJTableHeaderCell." + + "getLocation() must be null"); + } + + JComponent.AccessibleJComponent accessibleJComponent = + (JComponent.AccessibleJComponent) table.getAccessibleContext(); + AccessibleComponent accessibleComp2 = (AccessibleComponent) + accessibleJComponent.getAccessibleChild(3); + // getLocation() must be null according to its javadoc and no exception + // is thrown + if (null != accessibleComp2.getLocationOnScreen()) { + throw new RuntimeException("JTable$AccessibleJTable$" + + "AccessibleJTableCell.getLocation() must be null"); + } + + } +} diff --git a/test/sun/net/www/AuthHeaderTest.java b/test/sun/net/www/AuthHeaderTest.java index fb05f60be304a14a0b0bd450fcc45b55dfdec139..9e646e0a49b2dad9fb7286ddc5b23795277287e6 100644 --- a/test/sun/net/www/AuthHeaderTest.java +++ b/test/sun/net/www/AuthHeaderTest.java @@ -25,7 +25,7 @@ * @test * @bug 4804309 * @library ../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main AuthHeaderTest * @summary AuthHeaderTest bug */ @@ -90,13 +90,13 @@ public class AuthHeaderTest implements HttpCallback { is.close(); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new AuthHeaderTest(), 1, 10, 0); + server = new TestHttpServer (new AuthHeaderTest(), 1, 10, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); client ("http://localhost:"+server.getLocalPort()+"/d1/foo.html"); } catch (Exception e) { diff --git a/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java b/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java index e1827a96fe654bc042694a13df0c4a30df6b940d..c5e92d5b6f652dc2c04f135e5e05acd20b5762f5 100644 --- a/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java +++ b/test/sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java @@ -24,8 +24,6 @@ /** * @test * @bug 4333920 4994372 - * @library ../../../../../sun/net/www/httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction * @run main ChunkedEncodingWithProgressMonitorTest * @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem */ diff --git a/test/sun/net/www/http/KeepAliveCache/B5045306.java b/test/sun/net/www/http/KeepAliveCache/B5045306.java index 0a13017f43b8726491a5cefa30b64baecf291084..c36d2cfc3d9b25dd6c4c6ab3fcf1255fe89228cb 100644 --- a/test/sun/net/www/http/KeepAliveCache/B5045306.java +++ b/test/sun/net/www/http/KeepAliveCache/B5045306.java @@ -25,7 +25,7 @@ * @test * @bug 5045306 6356004 6993490 * @library ../../httptest/ - * @build HttpCallback HttpServer HttpTransaction + * @build HttpCallback TestHttpServer HttpTransaction * @run main/othervm B5045306 * @summary Http keep-alive implementation is not efficient */ @@ -50,7 +50,7 @@ import java.lang.management.*; public class B5045306 { static SimpleHttpTransaction httpTrans; - static HttpServer server; + static TestHttpServer server; public static void main(String[] args) throws Exception { startHttpServer(); @@ -60,7 +60,7 @@ public class B5045306 public static void startHttpServer() { try { httpTrans = new SimpleHttpTransaction(); - server = new HttpServer(httpTrans, 1, 10, 0); + server = new TestHttpServer(httpTrans, 1, 10, 0); } catch (IOException e) { e.printStackTrace(); } diff --git a/test/sun/net/www/httptest/HttpTransaction.java b/test/sun/net/www/httptest/HttpTransaction.java index fa269f235bbf21368b5bbf2b9bad8459eb641358..6007070b8e30e63a818e9d7bb381c0e4c93ceaa4 100644 --- a/test/sun/net/www/httptest/HttpTransaction.java +++ b/test/sun/net/www/httptest/HttpTransaction.java @@ -37,7 +37,7 @@ public class HttpTransaction { String command; URI requesturi; - HttpServer.Server server; + TestHttpServer.Server server; MessageHeader reqheaders, reqtrailers; String reqbody; byte[] rspbody; @@ -46,7 +46,7 @@ public class HttpTransaction { int rspbodylen; boolean rspchunked; - HttpTransaction (HttpServer.Server server, String command, + HttpTransaction (TestHttpServer.Server server, String command, URI requesturi, MessageHeader headers, String body, MessageHeader trailers, SelectionKey key) { this.command = command; @@ -290,7 +290,7 @@ public class HttpTransaction { * @param rTag the response string to send with the response code */ public void sendResponse (int rCode, String rTag) throws IOException { - OutputStream os = new HttpServer.NioOutputStream(channel()); + OutputStream os = new TestHttpServer.NioOutputStream(channel()); PrintStream ps = new PrintStream (os); ps.print ("HTTP/1.1 " + rCode + " " + rTag + "\r\n"); if (rspheaders != null) { @@ -314,7 +314,7 @@ public class HttpTransaction { /* sends one byte less than intended */ public void sendPartialResponse (int rCode, String rTag)throws IOException { - OutputStream os = new HttpServer.NioOutputStream(channel()); + OutputStream os = new TestHttpServer.NioOutputStream(channel()); PrintStream ps = new PrintStream (os); ps.print ("HTTP/1.1 " + rCode + " " + rTag + "\r\n"); ps.flush(); diff --git a/test/sun/net/www/httptest/HttpServer.java b/test/sun/net/www/httptest/TestHttpServer.java similarity index 98% rename from test/sun/net/www/httptest/HttpServer.java rename to test/sun/net/www/httptest/TestHttpServer.java index 33541f6a52475a2ae50e0da1aa91356c402d521a..7f91461b7342b0cb4c404079c477e5161a1a620d 100644 --- a/test/sun/net/www/httptest/HttpServer.java +++ b/test/sun/net/www/httptest/TestHttpServer.java @@ -48,7 +48,7 @@ import java.util.*; * NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ -public class HttpServer { +public class TestHttpServer { ServerSocketChannel schan; int threads; @@ -57,19 +57,19 @@ public class HttpServer { Server[] servers; /** - * Create a HttpServer instance with the specified callback object + * Create a TestHttpServer instance with the specified callback object * for handling requests. One thread is created to handle requests, * and up to ten TCP connections will be handled simultaneously. * @param cb the callback object which is invoked to handle each * incoming request */ - public HttpServer (HttpCallback cb) throws IOException { + public TestHttpServer (HttpCallback cb) throws IOException { this (cb, 1, 10, 0); } /** - * Create a HttpServer instance with the specified number of + * Create a TestHttpServer instance with the specified number of * threads and maximum number of connections per thread. This functions * the same as the 4 arg constructor, where the port argument is set to zero. * @param cb the callback object which is invoked to handle each @@ -80,13 +80,13 @@ public class HttpServer { * handle per thread */ - public HttpServer (HttpCallback cb, int threads, int cperthread) + public TestHttpServer (HttpCallback cb, int threads, int cperthread) throws IOException { this (cb, threads, cperthread, 0); } /** - * Create a HttpServer instance with the specified number + * Create a TestHttpServer instance with the specified number * of threads and maximum number of connections per thread and running on * the specified port. The specified number of threads are created to * handle incoming requests, and each thread is allowed @@ -101,7 +101,7 @@ public class HttpServer { * means choose any free port. */ - public HttpServer (HttpCallback cb, int threads, int cperthread, int port) + public TestHttpServer (HttpCallback cb, int threads, int cperthread, int port) throws IOException { schan = ServerSocketChannel.open (); InetSocketAddress addr = new InetSocketAddress (port); diff --git a/test/sun/net/www/protocol/http/B6296310.java b/test/sun/net/www/protocol/http/B6296310.java index 7e545cd37afe1a100efbece29fe4e530599b735d..a932d9caece85a9ed9046d84e5d52a420810a418 100644 --- a/test/sun/net/www/protocol/http/B6296310.java +++ b/test/sun/net/www/protocol/http/B6296310.java @@ -25,7 +25,7 @@ * @test * @bug 6296310 * @library ../../httptest/ - * @build HttpCallback HttpServer HttpTransaction + * @build HttpCallback TestHttpServer HttpTransaction * @run main/othervm B6296310 * @summary REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases */ @@ -42,7 +42,7 @@ import java.util.*; public class B6296310 { static SimpleHttpTransaction httpTrans; - static HttpServer server; + static TestHttpServer server; public static void main(String[] args) { @@ -55,7 +55,7 @@ public class B6296310 public static void startHttpServer() { try { httpTrans = new SimpleHttpTransaction(); - server = new HttpServer(httpTrans, 1, 10, 0); + server = new TestHttpServer(httpTrans, 1, 10, 0); } catch (IOException e) { e.printStackTrace(); } diff --git a/test/sun/net/www/protocol/http/B6299712.java b/test/sun/net/www/protocol/http/B6299712.java index 2111a2e0bfa9e703a05a2980d57be1d09eae7401..727b62e5743d04eee870bf0802d44b3e5eee7d62 100644 --- a/test/sun/net/www/protocol/http/B6299712.java +++ b/test/sun/net/www/protocol/http/B6299712.java @@ -25,7 +25,7 @@ * @test * @bug 6299712 * @library ../../httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main/othervm B6299712 * @summary NullPointerException in sun.net.www.protocol.http.HttpURLConnection.followRedirect */ @@ -49,7 +49,7 @@ import java.util.*; */ public class B6299712 { static SimpleHttpTransaction httpTrans; - static HttpServer server; + static TestHttpServer server; public static void main(String[] args) throws Exception { ResponseCache.setDefault(new DeployCacheHandler()); @@ -61,7 +61,7 @@ public class B6299712 { public static void startHttpServer() { try { httpTrans = new SimpleHttpTransaction(); - server = new HttpServer(httpTrans, 1, 10, 0); + server = new TestHttpServer(httpTrans, 1, 10, 0); } catch (IOException e) { e.printStackTrace(); } diff --git a/test/sun/net/www/protocol/http/RelativeRedirect.java b/test/sun/net/www/protocol/http/RelativeRedirect.java index 651bcacc7889ba5e2df78ebf8e24d5a52350f858..861ee6a95d06861a116409068d7fd132f7648eea 100644 --- a/test/sun/net/www/protocol/http/RelativeRedirect.java +++ b/test/sun/net/www/protocol/http/RelativeRedirect.java @@ -25,7 +25,7 @@ * @test * @bug 4726087 * @library ../../httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main RelativeRedirect * @summary URLConnection cannot handle redirects */ @@ -35,7 +35,7 @@ import java.net.*; public class RelativeRedirect implements HttpCallback { static int count = 0; - static HttpServer server; + static TestHttpServer server; static class MyAuthenticator extends Authenticator { public MyAuthenticator () { @@ -89,7 +89,7 @@ public class RelativeRedirect implements HttpCallback { MyAuthenticator auth = new MyAuthenticator (); Authenticator.setDefault (auth); try { - server = new HttpServer (new RelativeRedirect(), 1, 10, 0); + server = new TestHttpServer (new RelativeRedirect(), 1, 10, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); URL url = new URL("http://localhost:"+server.getLocalPort()); System.out.println ("client opening connection to: " + url); diff --git a/test/sun/net/www/protocol/http/ResponseCacheStream.java b/test/sun/net/www/protocol/http/ResponseCacheStream.java index 4b8900e67f2ca8c3f038cee91095f0d94a185a0d..6b85d7f4c73ceab95b1c02a7bcb105547adbc580 100644 --- a/test/sun/net/www/protocol/http/ResponseCacheStream.java +++ b/test/sun/net/www/protocol/http/ResponseCacheStream.java @@ -25,7 +25,7 @@ * @test * @bug 6262486 * @library ../../httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + * @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main/othervm -Dhttp.keepAlive=false ResponseCacheStream * @summary COMPATIBILITY: jagex_com - Monkey Puzzle applet fails to load */ @@ -91,13 +91,13 @@ public class ResponseCacheStream implements HttpCallback { } } - static HttpServer server; + static TestHttpServer server; public static void main(String[] args) throws Exception { MyResponseCache cache = new MyResponseCache(); try { ResponseCache.setDefault(cache); - server = new HttpServer (new ResponseCacheStream()); + server = new TestHttpServer (new ResponseCacheStream()); System.out.println ("Server: listening on port: " + server.getLocalPort()); URL url = new URL ("http://127.0.0.1:"+server.getLocalPort()+"/"); System.out.println ("Client: connecting to " + url); diff --git a/test/sun/net/www/protocol/http/SetChunkedStreamingMode.java b/test/sun/net/www/protocol/http/SetChunkedStreamingMode.java index d14fb8693109c36c4baa799402c1bb7f0a3b6b64..e1d2fd9a8659962079cf71b0dad727e358cffe75 100644 --- a/test/sun/net/www/protocol/http/SetChunkedStreamingMode.java +++ b/test/sun/net/www/protocol/http/SetChunkedStreamingMode.java @@ -25,7 +25,7 @@ * @test * @bug 5049976 * @library ../../httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction + @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction * @run main SetChunkedStreamingMode * @summary Unspecified NPE is thrown when streaming output mode is enabled */ @@ -60,11 +60,11 @@ public class SetChunkedStreamingMode implements HttpCallback { System.out.println ("finished reading"); } - static HttpServer server; + static TestHttpServer server; public static void main (String[] args) throws Exception { try { - server = new HttpServer (new SetChunkedStreamingMode(), 1, 10, 0); + server = new TestHttpServer (new SetChunkedStreamingMode(), 1, 10, 0); System.out.println ("Server: listening on port: " + server.getLocalPort()); URL url = new URL ("http://127.0.0.1:"+server.getLocalPort()+"/"); System.out.println ("Client: connecting to " + url); diff --git a/test/sun/security/pkcs11/ec/TestECDH2.java b/test/sun/security/pkcs11/ec/TestECDH2.java new file mode 100644 index 0000000000000000000000000000000000000000..21d1490600e3cabc6fb17dd86088d3deb77507c1 --- /dev/null +++ b/test/sun/security/pkcs11/ec/TestECDH2.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 6405536 + * @summary basic test of ECDSA signatures for P-256 and P-384 from the + * example data in "Suite B Implementer's Guide to FIPS 186-3". + * @library .. + * @library ../../../../java/security/testlibrary + * @compile -XDignore.symbol.file TestECDH2.java + * @run main TestECDH2 + */ + +import java.io.*; +import java.util.*; +import java.math.BigInteger; + +import java.security.*; +import java.security.spec.*; +import java.security.interfaces.*; +import javax.crypto.*; + +import sun.security.ec.NamedCurve; + +public class TestECDH2 extends PKCS11Test { + + // values of the keys we use for the tests + + // keypair using NIST P-256 + private final static String privD256 = "70a12c2db16845ed56ff68cfc21a472b3f04d7d6851bf6349f2d7d5b3452b38a"; + private final static String pubX256 = "8101ece47464a6ead70cf69a6e2bd3d88691a3262d22cba4f7635eaff26680a8"; + private final static String pubY256 = "d8a12ba61d599235f67d9cb4d58f1783d3ca43e78f0a5abaa624079936c0c3a9"; + + // keypair using NIST P-384 + private final static String privD384 = "c838b85253ef8dc7394fa5808a5183981c7deef5a69ba8f4f2117ffea39cfcd90e95f6cbc854abacab701d50c1f3cf24"; + private final static String pubX384 = "1fbac8eebd0cbf35640b39efe0808dd774debff20a2a329e91713baf7d7f3c3e81546d883730bee7e48678f857b02ca0"; + private final static String pubY384 = "eb213103bd68ce343365a8a4c3d4555fa385f5330203bdd76ffad1f3affb95751c132007e1b240353cb0a4cf1693bdf9"; + + private KeyFactory kf = null; + private KeyPairGenerator kpg = null; + + private static void testKeyAgreement(KeyPair kpA, KeyPair kpB, Provider p) + throws Exception { + KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", p); + ka1.init(kpA.getPrivate()); + ka1.doPhase(kpB.getPublic(), true); + byte[] s1 = ka1.generateSecret(); + + KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", p); + ka2.init(kpB.getPrivate()); + ka2.doPhase(kpA.getPublic(), true); + byte[] s2 = ka2.generateSecret(); + if (Arrays.equals(s1, s2) == false) { + System.out.println("expected: " + toString(s1)); + System.out.println("actual: " + toString(s2)); + throw new Exception("Generated secrets do not match"); + } + } + + private KeyPair genECKeyPair(String curvName, String privD, String pubX, + String pubY) throws Exception { + ECParameterSpec ecParams = NamedCurve.getECParameterSpec(curvName); + ECPrivateKeySpec privKeySpec = + new ECPrivateKeySpec(new BigInteger(privD, 16), ecParams); + ECPublicKeySpec pubKeySpec = + new ECPublicKeySpec(new ECPoint(new BigInteger(pubX, 16), + new BigInteger(pubY, 16)), + ecParams); + PrivateKey privKey = kf.generatePrivate(privKeySpec); + PublicKey pubKey = kf.generatePublic(pubKeySpec); + return new KeyPair(pubKey, privKey); + } + private KeyPair genECKeyPair(String curvName) throws Exception { + ECGenParameterSpec genParams = new ECGenParameterSpec(curvName); + kpg.initialize(genParams, null); + return kpg.generateKeyPair(); + } + public static void main(String[] args) throws Exception { + main(new TestECDH2()); + } + + public void main(Provider provider) throws Exception { + if (provider.getService("KeyAgreement", "ECDH") == null) { + System.out.println("ECDH not supported, skipping"); + return; + } + + kf = KeyFactory.getInstance("EC", provider); + kpg = KeyPairGenerator.getInstance("EC", provider); + + System.out.println("Testing against NIST P-256"); + + long start = System.currentTimeMillis(); + KeyPair kp256A = genECKeyPair("secp256r1", privD256, pubX256, pubY256); + KeyPair kp256B = genECKeyPair("secp256r1"); + testKeyAgreement(kp256A, kp256B, provider); + + System.out.println("Testing against NIST P-384"); + KeyPair kp384A = genECKeyPair("secp384r1", privD384, pubX384, pubY384); + KeyPair kp384B = genECKeyPair("secp384r1"); + testKeyAgreement(kp384A, kp384B, provider); + + long stop = System.currentTimeMillis(); + System.out.println("All tests passed (" + (stop - start) + " ms)."); + } +} diff --git a/test/sun/security/pkcs11/ec/TestECDSA2.java b/test/sun/security/pkcs11/ec/TestECDSA2.java new file mode 100644 index 0000000000000000000000000000000000000000..98c7f031930041df242ab9a0cf3ff4f49fb46aa0 --- /dev/null +++ b/test/sun/security/pkcs11/ec/TestECDSA2.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 6405536 + * @summary basic test of ECDSA signatures for P-256 and P-384 from the + * example data in "Suite B Implementer's Guide to FIPS 186-3". + * @library .. + * @library ../../../../java/security/testlibrary + * @compile -XDignore.symbol.file TestECDSA2.java + * @run main TestECDSA2 + */ + +import java.io.*; +import java.util.*; +import java.math.BigInteger; + +import java.security.*; +import java.security.spec.*; +import java.security.interfaces.*; + +import sun.security.ec.NamedCurve; + +public class TestECDSA2 extends PKCS11Test { + + // values of the keys we use for the tests + + // keypair using NIST P-256 + private final static String privD256 = "70a12c2db16845ed56ff68cfc21a472b3f04d7d6851bf6349f2d7d5b3452b38a"; + private final static String pubX256 = "8101ece47464a6ead70cf69a6e2bd3d88691a3262d22cba4f7635eaff26680a8"; + private final static String pubY256 = "d8a12ba61d599235f67d9cb4d58f1783d3ca43e78f0a5abaa624079936c0c3a9"; + + // keypair using NIST P-384 + private final static String privD384 = "c838b85253ef8dc7394fa5808a5183981c7deef5a69ba8f4f2117ffea39cfcd90e95f6cbc854abacab701d50c1f3cf24"; + private final static String pubX384 = "1fbac8eebd0cbf35640b39efe0808dd774debff20a2a329e91713baf7d7f3c3e81546d883730bee7e48678f857b02ca0"; + private final static String pubY384 = "eb213103bd68ce343365a8a4c3d4555fa385f5330203bdd76ffad1f3affb95751c132007e1b240353cb0a4cf1693bdf9"; + + // data to be signed + private final static byte[] data = "This is only a test message. It is 48 bytes long".getBytes(); + + private KeyFactory kf = null; + + private static void testSignAndVerify(String alg, KeyPair kp, Provider p) throws Exception { + Signature s = Signature.getInstance(alg, p); + s.initSign(kp.getPrivate()); + s.update(data); + byte[] result = s.sign(); + + s.initVerify(kp.getPublic()); + s.update(data); + if (!s.verify(result)) { + throw new Exception("Error: Signature verification failed"); + } + System.out.println(p.getName() + ": " + alg + " Passed"); + } + + private KeyPair genECKeyPair(String curvName, String privD, String pubX, String pubY) throws Exception { + ECParameterSpec ecParams = NamedCurve.getECParameterSpec(curvName); + ECPrivateKeySpec privKeySpec = + new ECPrivateKeySpec(new BigInteger(privD, 16), ecParams); + ECPublicKeySpec pubKeySpec = + new ECPublicKeySpec(new ECPoint(new BigInteger(pubX, 16), new BigInteger(pubY, 16)), + ecParams); + PrivateKey privKey = kf.generatePrivate(privKeySpec); + PublicKey pubKey = kf.generatePublic(pubKeySpec); + return new KeyPair(pubKey, privKey); + } + + public static void main(String[] args) throws Exception { + main(new TestECDSA2()); + } + + public void main(Provider provider) throws Exception { + boolean testP256 = + (provider.getService("Signature", "SHA256withECDSA") != null); + + boolean testP384 = + (provider.getService("Signature", "SHA384withECDSA") != null); + + if (!testP256 && !testP384) { + System.out.println("ECDSA not supported, skipping"); + return; + } + + kf = KeyFactory.getInstance("EC", provider); + + long start = System.currentTimeMillis(); + if (testP256) { + // can use secp256r1, NIST P-256, X9.62 prime256v1, or 1.2.840.10045.3.1.7 + KeyPair kp = genECKeyPair("secp256r1", privD256, pubX256, pubY256); + testSignAndVerify("SHA256withECDSA", kp, provider); + } + if (testP384) { + // can use secp384r1, NIST P-384, 1.3.132.0.34 + KeyPair kp = genECKeyPair("secp384r1", privD384, pubX384, pubY384); + testSignAndVerify("SHA384withECDSA", kp, provider); + } + long stop = System.currentTimeMillis(); + System.out.println("All tests passed (" + (stop - start) + " ms)."); + } +} diff --git a/test/sun/security/provider/DSA/TestAlgParameterGenerator.java b/test/sun/security/provider/DSA/TestAlgParameterGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..c416c1d8423e921c8ee6e750572e2ccb1fd510c3 --- /dev/null +++ b/test/sun/security/provider/DSA/TestAlgParameterGenerator.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7044060 + * @summary verify that DSA parameter generation works + * @run main/othervm/timeout=300 TestAlgParameterGenerator + */ +import java.security.*; +import java.security.spec.*; +import java.security.interfaces.*; + +public class TestAlgParameterGenerator { + + private static void checkParamStrength(AlgorithmParameters param, + int strength) throws Exception { + String algo = param.getAlgorithm(); + if (!algo.equalsIgnoreCase("DSA")) { + throw new Exception("Unexpected type of parameters: " + algo); + } + DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class); + int valueL = spec.getP().bitLength(); + if (strength != valueL) { + System.out.println("Expected " + strength + " but actual " + valueL); + throw new Exception("Wrong P strength"); + } + } + private static void checkParamStrength(AlgorithmParameters param, + DSAGenParameterSpec genParam) + throws Exception { + String algo = param.getAlgorithm(); + if (!algo.equalsIgnoreCase("DSA")) { + throw new Exception("Unexpected type of parameters: " + algo); + } + DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class); + int valueL = spec.getP().bitLength(); + int strength = genParam.getPrimePLength(); + if (strength != valueL) { + System.out.println("P: Expected " + strength + " but actual " + valueL); + throw new Exception("Wrong P strength"); + } + int valueN = spec.getQ().bitLength(); + strength = genParam.getSubprimeQLength(); + if (strength != valueN) { + System.out.println("Q: Expected " + strength + " but actual " + valueN); + throw new Exception("Wrong Q strength"); + } + } + + public static void main(String[] args) throws Exception { + AlgorithmParameterGenerator apg = + AlgorithmParameterGenerator.getInstance("DSA", "SUN"); + + long start, stop; + // make sure no-init still works + start = System.currentTimeMillis(); + AlgorithmParameters param = apg.generateParameters(); + stop = System.currentTimeMillis(); + System.out.println("Time: " + (stop - start) + " ms."); + checkParamStrength(param, 1024); + + // make sure the old model works + int[] strengths = { 512, 768, 1024 }; + for (int i = 0; i < strengths.length; i++) { + int sizeP = strengths[i]; + System.out.println("Generating " + sizeP + "-bit DSA Parameters"); + start = System.currentTimeMillis(); + apg.init(sizeP); + param = apg.generateParameters(); + stop = System.currentTimeMillis(); + System.out.println("Time: " + (stop - start) + " ms."); + checkParamStrength(param, sizeP); + } + + // now the newer model + DSAGenParameterSpec spec1 = new DSAGenParameterSpec(1024, 160); + DSAGenParameterSpec spec2 = new DSAGenParameterSpec(2048, 224); + DSAGenParameterSpec spec3 = new DSAGenParameterSpec(2048, 256); + //DSAGenParameterSpec spec4 = new DSAGenParameterSpec(3072, 256); + DSAGenParameterSpec[] specSet = { + spec1, spec2, spec3//, spec4 + }; + for (int i = 0; i < specSet.length; i++) { + DSAGenParameterSpec genParam = specSet[i]; + System.out.println("Generating (" + genParam.getPrimePLength() + + ", " + genParam.getSubprimeQLength() + + ") DSA Parameters"); + start = System.currentTimeMillis(); + apg.init(genParam, null); + param = apg.generateParameters(); + stop = System.currentTimeMillis(); + System.out.println("Time: " + (stop - start) + " ms."); + checkParamStrength(param, genParam); + } + } +} diff --git a/test/sun/security/provider/DSA/TestDSA2.java b/test/sun/security/provider/DSA/TestDSA2.java new file mode 100644 index 0000000000000000000000000000000000000000..a478b8bc0a37c286ef6851f9a9825d06f18d9f71 --- /dev/null +++ b/test/sun/security/provider/DSA/TestDSA2.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 7044060 + * @run main/othervm/timeout=250 TestDSA2 + * @summary verify that DSA signature works using SHA and SHA-224 and SHA-256 digests. + */ + + +import java.security.*; +import java.security.spec.*; +import java.security.interfaces.*; + +public class TestDSA2 { + + // NOTE: need to explictly specify provider since the more + // preferred provider SunPKCS11 provider only supports up + // 1024 bits. + private static final String PROV = "SUN"; + + private static final String[] SIG_ALGOS = { + "SHA1withDSA", "SHA224withDSA", "SHA256withDSA" + }; + + private static final int[] KEYSIZES = { + 1024, 2048 + }; + + public static void main(String[] args) throws Exception { + boolean[] expectedToPass = { true, true, true }; + test(1024, expectedToPass); + boolean[] expectedToPass2 = { false, true, true }; + test(2048, expectedToPass2); + } + + private static void test(int keySize, boolean[] testStatus) + throws Exception { + byte[] data = "1234567890".getBytes(); + System.out.println("Test against key size: " + keySize); + + KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", PROV); + keyGen.initialize(keySize, new SecureRandom()); + KeyPair pair = keyGen.generateKeyPair(); + + if (testStatus.length != SIG_ALGOS.length) { + throw new RuntimeException("TestError: incorrect status array!"); + } + for (int i = 0; i < SIG_ALGOS.length; i++) { + Signature dsa = Signature.getInstance(SIG_ALGOS[i], PROV); + try { + dsa.initSign(pair.getPrivate()); + dsa.update(data); + byte[] sig = dsa.sign(); + dsa.initVerify(pair.getPublic()); + dsa.update(data); + boolean verifies = dsa.verify(sig); + if (verifies == testStatus[i]) { + System.out.println(SIG_ALGOS[i] + ": Passed"); + } else { + System.out.println(SIG_ALGOS[i] + ": should " + + (testStatus[i]? "pass":"fail")); + throw new RuntimeException(SIG_ALGOS[i] + ": Unexpected Test result!"); + + } + } catch (Exception ex) { + if (testStatus[i]) { + ex.printStackTrace(); + throw new RuntimeException(SIG_ALGOS[i] + ": Unexpected exception " + ex); + } else { + System.out.println(SIG_ALGOS[i] + ": Passed, expected " + ex); + } + } + } + } +} diff --git a/test/sun/security/provider/DSA/TestKeyPairGenerator.java b/test/sun/security/provider/DSA/TestKeyPairGenerator.java index 70f9dae9577a3ee18c908b069d5d5a6d5c66632b..f0c0fc37828911a8a82f985f57a17c69dbdbee03 100644 --- a/test/sun/security/provider/DSA/TestKeyPairGenerator.java +++ b/test/sun/security/provider/DSA/TestKeyPairGenerator.java @@ -24,7 +24,7 @@ /* * @test * @bug 4800108 - * @summary verify that precomputed DSA parameters are always used (512, 768, 1024 bit) + * @summary verify that precomputed DSA parameters are always used (512, 768, 1024, 2048 bit) * @run main/othervm/timeout=15 TestKeyPairGenerator */ @@ -78,6 +78,10 @@ public class TestKeyPairGenerator { kp = kpg.generateKeyPair(); checkKeyLength(kp, 512); + kpg.initialize(2048); + kp = kpg.generateKeyPair(); + checkKeyLength(kp, 2048); + long stop = System.currentTimeMillis(); System.out.println("Time: " + (stop - start) + " ms."); } diff --git a/test/sun/security/ssl/sun/net/www/http/ChunkedOutputStream/Test.java b/test/sun/security/ssl/sun/net/www/http/ChunkedOutputStream/Test.java index 9a6af1a7c3ddfd08f26153d9922e845557a24240..686411bf155afc4cca29a299bb5d44821a899b96 100644 --- a/test/sun/security/ssl/sun/net/www/http/ChunkedOutputStream/Test.java +++ b/test/sun/security/ssl/sun/net/www/http/ChunkedOutputStream/Test.java @@ -25,6 +25,7 @@ * @test * @bug 5026745 * @library ../../httpstest/ + * @build TestHttpsServer HttpCallback * @run main/othervm Test * * SunJSSE does not support dynamic system properties, no way to re-use @@ -275,7 +276,7 @@ public class Test implements HttpCallback { } } - static HttpServer server; + static TestHttpsServer server; public static void main (String[] args) throws Exception { // setup properties to do ssl @@ -296,7 +297,7 @@ public class Test implements HttpCallback { HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); try { - server = new HttpServer (new Test(), 1, 10, 0); + server = new TestHttpsServer (new Test(), 1, 10, 0); System.out.println ("Server started: listening on port: " + server.getLocalPort()); // the test server doesn't support keep-alive yet // test1("http://localhost:"+server.getLocalPort()+"/d0"); diff --git a/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java b/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java index 16d26aa60e8ce2aeaad980ced9a11d43cf9b3f14..5389d9f3fa30353f1ff246646b69cc5f203510f8 100644 --- a/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java +++ b/test/sun/security/ssl/sun/net/www/httpstest/HttpTransaction.java @@ -37,7 +37,7 @@ public class HttpTransaction { String command; URI requesturi; - HttpServer.ServerWorker server; + TestHttpsServer.ServerWorker server; MessageHeader reqheaders, reqtrailers; String reqbody; byte[] rspbody; @@ -46,7 +46,7 @@ public class HttpTransaction { int rspbodylen; boolean rspchunked; - HttpTransaction (HttpServer.ServerWorker server, String command, + HttpTransaction (TestHttpsServer.ServerWorker server, String command, URI requesturi, MessageHeader headers, String body, MessageHeader trailers, SocketChannel ch) { this.command = command; @@ -290,7 +290,7 @@ public class HttpTransaction { * @param rTag the response string to send with the response code */ public void sendResponse (int rCode, String rTag) throws IOException { - OutputStream os = new HttpServer.NioOutputStream(channel(), server.getSSLEngine(), server.outNetBB(), server.outAppBB()); + OutputStream os = new TestHttpsServer.NioOutputStream(channel(), server.getSSLEngine(), server.outNetBB(), server.outAppBB()); PrintStream ps = new PrintStream (os); ps.print ("HTTP/1.1 " + rCode + " " + rTag + "\r\n"); if (rspheaders != null) { @@ -314,7 +314,7 @@ public class HttpTransaction { /* sends one byte less than intended */ public void sendPartialResponse (int rCode, String rTag)throws IOException { - OutputStream os = new HttpServer.NioOutputStream(channel(), server.getSSLEngine(), server.outNetBB(), server.outAppBB()); + OutputStream os = new TestHttpsServer.NioOutputStream(channel(), server.getSSLEngine(), server.outNetBB(), server.outAppBB()); PrintStream ps = new PrintStream (os); ps.print ("HTTP/1.1 " + rCode + " " + rTag + "\r\n"); ps.flush(); diff --git a/test/sun/security/ssl/sun/net/www/httpstest/HttpServer.java b/test/sun/security/ssl/sun/net/www/httpstest/TestHttpsServer.java similarity index 98% rename from test/sun/security/ssl/sun/net/www/httpstest/HttpServer.java rename to test/sun/security/ssl/sun/net/www/httpstest/TestHttpsServer.java index 2d48847b2e6d6fb22f477fbb978923d6a353b7c5..21fc8ab29c219524fe36ef6819afc55b1b27f452 100644 --- a/test/sun/security/ssl/sun/net/www/httpstest/HttpServer.java +++ b/test/sun/security/ssl/sun/net/www/httpstest/TestHttpsServer.java @@ -51,7 +51,7 @@ import java.security.*; * NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ -public class HttpServer { +public class TestHttpsServer { ServerSocketChannel schan; int threads; @@ -63,19 +63,19 @@ public class HttpServer { static SSLContext sslCtx; /** - * Create a HttpServer instance with the specified callback object + * Create a TestHttpsServer instance with the specified callback object * for handling requests. One thread is created to handle requests, * and up to ten TCP connections will be handled simultaneously. * @param cb the callback object which is invoked to handle each * incoming request */ - public HttpServer (HttpCallback cb) throws IOException { + public TestHttpsServer (HttpCallback cb) throws IOException { this (cb, 1, 10, 0); } /** - * Create a HttpServer instance with the specified number of + * Create a TestHttpsServer instance with the specified number of * threads and maximum number of connections per thread. This functions * the same as the 4 arg constructor, where the port argument is set to zero. * @param cb the callback object which is invoked to handle each @@ -86,13 +86,13 @@ public class HttpServer { * handle per thread */ - public HttpServer (HttpCallback cb, int threads, int cperthread) + public TestHttpsServer (HttpCallback cb, int threads, int cperthread) throws IOException { this (cb, threads, cperthread, 0); } /** - * Create a HttpServer instance with the specified number + * Create a TestHttpsServer instance with the specified number * of threads and maximum number of connections per thread and running on * the specified port. The specified number of threads are created to * handle incoming requests, and each thread is allowed @@ -107,7 +107,7 @@ public class HttpServer { * means choose any free port. */ - public HttpServer (HttpCallback cb, int threads, int cperthread, int port) + public TestHttpsServer (HttpCallback cb, int threads, int cperthread, int port) throws IOException { schan = ServerSocketChannel.open (); InetSocketAddress addr = new InetSocketAddress (port); diff --git a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java index 85ac5cb5a73465555674002515abc745700b27fe..4df22a85c45e46e069ae24b5d7d134446f6e5139 100644 --- a/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java +++ b/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java @@ -25,7 +25,7 @@ * @test * @bug 6216082 * @library ../../../httpstest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction TunnelProxy + * @build HttpCallback TestHttpsServer ClosedChannelList HttpTransaction TunnelProxy * @summary Redirect problem with HttpsURLConnection using a proxy * SunJSSE does not support dynamic system properties, no way to re-use * system properties in samevm/agentvm mode. @@ -39,7 +39,7 @@ import java.util.*; public class B6216082 { static SimpleHttpTransaction httpTrans; - static HttpServer server; + static TestHttpsServer server; static TunnelProxy proxy; // it seems there's no proxy ever if a url points to 'localhost', @@ -133,7 +133,7 @@ public class B6216082 { // Both the https server and the proxy let the // system pick up an ephemeral port. httpTrans = new SimpleHttpTransaction(); - server = new HttpServer(httpTrans, 1, 10, 0); + server = new TestHttpsServer(httpTrans, 1, 10, 0); proxy = new TunnelProxy(1, 10, 0); } diff --git a/test/sun/tools/jstatd/jpsOutput1.awk b/test/sun/tools/jstatd/jpsOutput1.awk index 289d3407eeb49c932a9d241326e7e2ce898bfa0b..4c25392b08caea3badca03b7648310f2711e7178 100644 --- a/test/sun/tools/jstatd/jpsOutput1.awk +++ b/test/sun/tools/jstatd/jpsOutput1.awk @@ -7,7 +7,7 @@ BEGIN { matched++; } -/^[0-9]+ -- process information unavailable$/ { +/^[0-9]+ -- .*$/ { matched++; } diff --git a/test/tools/launcher/BigJar.java b/test/tools/launcher/BigJar.java new file mode 100644 index 0000000000000000000000000000000000000000..5c183f44e7e0f57f3cec6b16bf5eb2580deab9ce --- /dev/null +++ b/test/tools/launcher/BigJar.java @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7194005 + * @summary launcher handling of zip64 archives (Scenario A and B) + * @compile -XDignore.symbol.file BigJar.java + * @run main/timeout=600 BigJar + */ +/* + * This test consists of two scenarios: + * + * Scenario A: create a jar with entries exceeding 64K, add a main class and + * see if the launcher can handle it. + * + * Scenario A1: create a jar as in A, but add a zipfile comment as well. + * + * Scenario B: create a jar with a large enough file exceeding 4GB, and + * similarly test the launcher. This test can be run optionally by using the + * following jtreg option: + * "-javaoptions:-DBigJar_testScenarioB=true" + * or set + * "BigJar_testScenarioB" environment variable. + * + * Note this test will only run iff all the disk requirements are met at runtime. + */ +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.CRC32; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class BigJar extends TestHelper { + + private static final long GIGA = 1024 * 1024 * 1024; + private static final int BUFFER_LEN = Short.MAX_VALUE * 2; + + long getCount(long minlength) { + return (minlength / BUFFER_LEN) + 1; + } + + long computeCRC(long minlength) { + CRC32 crc = new CRC32(); + byte[] buffer = new byte[BUFFER_LEN]; + long count = getCount(minlength); + for (long i = 0; i < count; i++) { + crc.update(buffer); + } + return crc.getValue(); + } + + long computeCRC(File inFile) throws IOException { + byte[] buffer = new byte[8192]; + CRC32 crc = new CRC32(); + try (FileInputStream fis = new FileInputStream(inFile); + BufferedInputStream bis = new BufferedInputStream(fis)) { + int n = bis.read(buffer); + while (n > 0) { + crc.update(buffer, 0, n); + n = bis.read(buffer); + } + } + return crc.getValue(); + } + + void createLargeFile(OutputStream os, long minlength) throws IOException { + byte[] buffer = new byte[BUFFER_LEN]; + long count = getCount(minlength); + for (long i = 0; i < count; i++) { + os.write(buffer); + } + os.flush(); + } + + Manifest createMainClass(File javaFile) throws IOException { + javaFile.delete(); + List content = new ArrayList<>(); + content.add("public class " + baseName(javaFile) + "{"); + content.add("public static void main(String... args) {"); + content.add("System.out.println(\"Hello World\\n\");"); + content.add("System.exit(0);"); + content.add("}"); + content.add("}"); + createFile(javaFile, content); + compile(javaFile.getName()); + Manifest manifest = new Manifest(); + manifest.clear(); + manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); + manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile)); + System.out.println(manifest.getMainAttributes().keySet()); + System.out.println(manifest.getMainAttributes().values()); + return manifest; + } + + void createJarWithLargeFile(File jarFile, long minlength) throws IOException { + File javaFile = new File("Foo.java"); + Manifest manifest = createMainClass(javaFile); + File classFile = getClassFile(javaFile); + try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest); + BufferedOutputStream bos = new BufferedOutputStream(jos); + FileInputStream fis = new FileInputStream(classFile);) { + jos.setLevel(ZipOutputStream.STORED); + jos.setMethod(0); + + JarEntry je = new JarEntry("large.data"); + je.setCompressedSize(getCount(minlength) * BUFFER_LEN); + je.setSize(getCount(minlength) * BUFFER_LEN); + je.setCrc(computeCRC(minlength)); + je.setMethod(ZipEntry.STORED); + jos.putNextEntry(je); + createLargeFile(bos, minlength); + + je = new JarEntry(classFile.getName()); + je.setCompressedSize(classFile.length()); + je.setSize(classFile.length()); + je.setCrc(computeCRC(classFile)); + je.setMethod(ZipEntry.STORED); + jos.putNextEntry(je); + copyStream(fis, bos); + bos.flush(); + jos.closeEntry(); + } + } + + void createLargeJar(File jarFile, String comment) throws IOException { + final int MAX = Short.MAX_VALUE * 2 + 10; + JarEntry je = null; + File javaFile = new File("Foo.java"); + File classFile = getClassFile(javaFile); + Manifest manifest = createMainClass(javaFile); + try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest); + FileInputStream fis = new FileInputStream(classFile)) { + jos.setLevel(JarOutputStream.STORED); + jos.setMethod(JarOutputStream.STORED); + for (int i = 0; i < MAX; i++) { + je = new JarEntry("X" + i + ".txt"); + je.setSize(0); + je.setCompressedSize(0); + je.setCrc(0); + jos.putNextEntry(je); + } + + // add a class file + je = new JarEntry(classFile.getName()); + je.setCompressedSize(classFile.length()); + je.setSize(classFile.length()); + je.setCrc(computeCRC(classFile)); + jos.putNextEntry(je); + copyStream(fis, jos); + jos.closeEntry(); + if (comment != null) { + jos.setComment(comment); + } + } + } + + void testTheJar(File theJar) throws Exception { + try { + TestResult tr = doExec(javaCmd, "-jar", theJar.getName()); + tr.checkPositive(); + if (!tr.testStatus) { + System.out.println(tr); + throw new Exception("Failed"); + } + } finally { + theJar.delete(); + } + } + + // a jar with entries exceeding 64k + a class file for the existential test + @Test + void testScenarioA() throws Exception { + File largeJar = new File("large.jar"); + createLargeJar(largeJar, null); + testTheJar(largeJar); + } + + // a jar with entries exceeding 64k and zip comment + @Test + void testScenarioA1() throws Exception { + File largeJar = new File("largewithcomment.jar"); + createLargeJar(largeJar, "A really large jar with a comment"); + testTheJar(largeJar); + } + + // a jar with an enormous file + a class file for the existential test + @Test + void testScenarioB() throws Exception { + final String testString = "BigJar_testScenarioB"; + if (Boolean.getBoolean(testString) == false && + System.getenv(testString) == null) { + System.out.println("Warning: testScenarioB passes vacuously"); + return; + } + final File largeJar = new File("huge.jar"); + + final Path path = largeJar.getAbsoluteFile().getParentFile().toPath(); + final long available = Files.getFileStore(path).getUsableSpace(); + final long MAX_VALUE = 0xFFFF_FFFFL; + + final long absolute = MAX_VALUE + 1L; + final long required = (long) (absolute * 1.1); // pad for sundries + System.out.println("\tavailable: " + available / GIGA + " GB"); + System.out.println("\trequired: " + required / GIGA + " GB"); + + if (available > required) { + createJarWithLargeFile(largeJar, absolute); + testTheJar(largeJar); + } else { + System.out.println("Warning: testScenarioB passes vacuously," + + " requirements exceeds available space"); + } + } + + public static void main(String... args) throws Exception { + BigJar bj = new BigJar(); + bj.run(args); + if (testExitValue > 0) { + System.out.println("Total of " + testExitValue + " failed"); + System.exit(1); + } else { + System.out.println("All tests pass"); + } + } +} diff --git a/test/tools/launcher/RunpathTest.java b/test/tools/launcher/RunpathTest.java new file mode 100644 index 0000000000000000000000000000000000000000..631be16d9754293f826e852363c2463dbf42b530 --- /dev/null +++ b/test/tools/launcher/RunpathTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7190813 + * @summary Check for extended RPATHs on *nixes + * @compile -XDignore.symbol.file RunpathTest.java + * @run main RunpathTest + * @author ksrini + */ + +import java.io.File; + +public class RunpathTest extends TestHelper { + + final String elfreaderCmd; + RunpathTest() { + elfreaderCmd = findElfReader(); + } + + final String findElfReader() { + String[] paths = {"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/ccs/bin"}; + final String cmd = isSolaris ? "elfdump" : "readelf"; + for (String x : paths) { + File p = new File(x); + File e = new File(p, cmd); + if (e.canExecute()) { + return e.getAbsolutePath(); + } + } + System.err.println("Warning: no suitable elf reader!"); + return null; + } + + void elfCheck(String javacmd, String expectedRpath) { + final TestResult tr = doExec(elfreaderCmd, "-d", javacmd); + if (!tr.matches(expectedRpath)) { + System.out.println(tr); + throw new RuntimeException("FAILED: RPATH strings " + + expectedRpath + " not found in " + javaCmd); + } + System.out.println(javacmd + " contains expected RPATHS"); + } + + void testRpath() { + if (isDualMode && is64Bit) { + String expectedRpath = ".*RPATH.*\\$ORIGIN/../../lib/" + getJreArch() + + ":\\$ORIGIN/../../jre/lib/" + getJreArch() + ".*"; + elfCheck(java64Cmd, expectedRpath); + } else { + String expectedRpath = ".*RPATH.*\\$ORIGIN/../lib/" + getJreArch() + + ":\\$ORIGIN/../jre/lib/" + getJreArch() + ".*"; + elfCheck(javaCmd, expectedRpath); + } + } + + public static void main(String... args) throws Exception { + if (isSolaris || isLinux) { + RunpathTest rp = new RunpathTest(); + rp.testRpath(); + } + } +} diff --git a/test/tools/launcher/TestHelper.java b/test/tools/launcher/TestHelper.java index 893b90f2f06214680d1c4d415efff5636f228dfb..6738eba5e191cb5fd39a28ed65bb325e8b0e0f93 100644 --- a/test/tools/launcher/TestHelper.java +++ b/test/tools/launcher/TestHelper.java @@ -21,6 +21,8 @@ * questions. */ +import java.io.OutputStream; +import java.io.InputStream; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -243,6 +245,21 @@ public class TestHelper { return null; } + static File getClassFile(File javaFile) { + String s = javaFile.getAbsolutePath().replace(JAVA_FILE_EXT, CLASS_FILE_EXT); + return new File(s); + } + + static File getJavaFile(File classFile) { + String s = classFile.getAbsolutePath().replace(CLASS_FILE_EXT, JAVA_FILE_EXT); + return new File(s); + } + + static String baseName(File f) { + String s = f.getName(); + return s.substring(0, s.indexOf(".")); + } + /* * A convenience method to create a jar with jar file name and defs */ @@ -324,6 +341,15 @@ public class TestHelper { } } + static void copyStream(InputStream in, OutputStream out) throws IOException { + byte[] buf = new byte[8192]; + int n = in.read(buf); + while (n > 0) { + out.write(buf, 0, n); + n = in.read(buf); + } + } + static void copyFile(File src, File dst) throws IOException { Path parent = dst.toPath().getParent(); if (parent != null) {