Mercurial > hg > openjdk > bsd-port > jdk
changeset 6153:147401296df6 jdk7u10-b06
Merge
author | lana |
---|---|
date | Thu, 30 Aug 2012 21:02:16 -0700 |
parents | 2280922fadf9 (current diff) eaf58bd0f505 (diff) |
children | fd190f90dc17 |
files | |
diffstat | 140 files changed, 3104 insertions(+), 751 deletions(-) [+] |
line wrap: on
line diff
--- a/make/common/Program.gmk Wed Aug 29 23:05:55 2012 -0700 +++ b/make/common/Program.gmk Thu Aug 30 21:02:16 2012 -0700 @@ -153,7 +153,6 @@ ifndef LOCAL_RESOURCE_FILE @$(ECHO) $(OBJDIR)/$(PROGRAM).res >> $@ endif # LOCAL_RESOURCE_FILE - @$(ECHO) setargv.obj >> $@ @$(ECHO) Created $@ $(ACTUAL_PROGRAM):: $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
--- a/make/java/jli/Makefile Wed Aug 29 23:05:55 2012 -0700 +++ b/make/java/jli/Makefile Thu Aug 30 21:02:16 2012 -0700 @@ -90,7 +90,8 @@ # add platform specific files ifeq ($(PLATFORM), windows) - FILES_c += java_md.c + FILES_c += java_md.c \ + cmdtoargs.c else # NIXES FILES_c += java_md_common.c ifeq ($(PLATFORM), macosx) @@ -149,7 +150,11 @@ -export:JLI_ReportErrorMessage \ -export:JLI_ReportErrorMessageSys \ -export:JLI_ReportMessage \ - -export:JLI_ReportExceptionDescription + -export:JLI_ReportExceptionDescription \ + -export:JLI_MemAlloc \ + -export:JLI_CmdToArgs \ + -export:JLI_GetStdArgc \ + -export:JLI_GetStdArgs endif # PLATFORM OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)
--- a/make/java/jli/mapfile-vers Wed Aug 29 23:05:55 2012 -0700 +++ b/make/java/jli/mapfile-vers Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2005, 2008, 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 @@ -35,9 +35,8 @@ JLI_ReportErrorMessageSys; JLI_ReportMessage; JLI_ReportExceptionDescription; -# JNI_CreateJavaVM; -# JNI_GetCreatedJavaVMs; -# JNI_GetDefaultJavaVMInitArgs; + JLI_GetStdArgs; + JLI_GetStdArgc; local: *; };
--- a/src/macosx/classes/java/util/prefs/MacOSXPreferences.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/java/util/prefs/MacOSXPreferences.java Thu Aug 30 21:02:16 2012 -0700 @@ -33,16 +33,16 @@ private static final String defaultAppName = "com.apple.java.util.prefs"; // true if this node is a child of userRoot or is userRoot - private boolean isUser; + private final boolean isUser; // true if this node is userRoot or systemRoot - private boolean isRoot; + private final boolean isRoot; // CF's storage location for this node and its keys - private MacOSXPreferencesFile file; + private final MacOSXPreferencesFile file; // absolutePath() + "/" - private String path; + private final String path; // User root and system root nodes private static MacOSXPreferences userRoot = null; @@ -71,36 +71,40 @@ // Create a new root node. Called by getUserRoot() and getSystemRoot() // Synchronization is provided by the caller. - private MacOSXPreferences(boolean newIsUser) - { - super(null, ""); - isUser = newIsUser; - isRoot = true; - - initFields(); + private MacOSXPreferences(boolean newIsUser) { + this(null, "", false, true, newIsUser); } // Create a new non-root node with the given parent. // Called by childSpi(). - private MacOSXPreferences(MacOSXPreferences parent, String name) + private MacOSXPreferences(MacOSXPreferences parent, String name) { + this(parent, name, false, false, false); + } + + private MacOSXPreferences(MacOSXPreferences parent, String name, + boolean isNew) { - super(parent, name); - isUser = isUserNode(); - isRoot = false; - - initFields(); + this(parent, name, isNew, false, false); } - - private void initFields() + private MacOSXPreferences(MacOSXPreferences parent, String name, + boolean isNew, boolean isRoot, boolean isUser) { + super(parent, name); + this.isRoot = isRoot; + if (isRoot) + this.isUser = isUser; + else + this.isUser = isUserNode(); path = isRoot ? absolutePath() : absolutePath() + "/"; file = cfFileForNode(isUser); - newNode = file.addNode(path); + if (isNew) + newNode = isNew; + else + newNode = file.addNode(path); } - // Create and return the MacOSXPreferencesFile for this node. // Does not write anything to the file. private MacOSXPreferencesFile cfFileForNode(boolean isUser) @@ -194,8 +198,8 @@ // Add to parent's child list here and disallow sync // because parent and child might be in different files. synchronized(MacOSXPreferencesFile.class) { - file.addChildToNode(path, name); - return new MacOSXPreferences(this, name); + boolean isNew = file.addChildToNode(path, name); + return new MacOSXPreferences(this, name, isNew); } } @@ -206,9 +210,14 @@ // Flush should *not* check for removal, unlike sync, but should // prevent simultaneous removal. synchronized(lock) { - // fixme! overkill - if (!MacOSXPreferencesFile.flushWorld()) { - throw new BackingStoreException("Synchronization failed for node '" + path + "'"); + if (isUser) { + if (!MacOSXPreferencesFile.flushUser()) { + throw new BackingStoreException("Synchronization failed for node '" + path + "'"); + } + } else { + if (!MacOSXPreferencesFile.flushWorld()) { + throw new BackingStoreException("Synchronization failed for node '" + path + "'"); + } } } }
--- a/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java Thu Aug 30 21:02:16 2012 -0700 @@ -223,7 +223,23 @@ return ok; } - + //Flush only current user preferences + static synchronized boolean flushUser() { + boolean ok = true; + if (changedFiles != null && !changedFiles.isEmpty()) { + Iterator<MacOSXPreferencesFile> iterator = changedFiles.iterator(); + while(iterator.hasNext()) { + MacOSXPreferencesFile f = iterator.next(); + if (f.user == cfCurrentUser) { + if (!f.synchronize()) + ok = false; + else + iterator.remove(); + } + } + } + return ok; + } // Write all prefs changes to disk, but do not clear all cached prefs // values. Also kills any scheduled flush task. @@ -348,11 +364,11 @@ } } - void addChildToNode(String path, String child) + boolean addChildToNode(String path, String child) { synchronized(MacOSXPreferencesFile.class) { markChanged(); - addChildToNode(path, child+"/", appName, user, host); + return addChildToNode(path, child+"/", appName, user, host); } } @@ -421,7 +437,7 @@ addNode(String path, String name, long user, long host); private static final native void removeNode(String path, String name, long user, long host); - private static final native void + private static final native boolean addChildToNode(String path, String child, String name, long user, long host); private static final native void
--- a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java Thu Aug 30 21:02:16 2012 -0700 @@ -31,8 +31,12 @@ 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 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.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 @@ } finally { rq.unlock(); } + + updateTotalDisplayBounds(); } @Override @@ -478,4 +485,50 @@ 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()); + } }
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu Aug 30 21:02:16 2012 -0700 @@ -355,6 +355,18 @@ 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); @@ -426,14 +438,33 @@ @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; } - platformWindow.setMinimumSize(d.width, d.height); + + 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.setSizeConstraints(min.width, min.height, max.width, max.height); } @Override
--- a/src/macosx/classes/sun/lwawt/PlatformWindow.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/lwawt/PlatformWindow.java Thu Aug 30 21:02:16 2012 -0700 @@ -131,7 +131,10 @@ 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
--- a/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/lwawt/macosx/CFileDialog.java Thu Aug 30 21:02:16 2012 -0700 @@ -30,12 +30,14 @@ 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 @@ 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 @@ } 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
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java Thu Aug 30 21:02:16 2012 -0700 @@ -180,7 +180,7 @@ 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) {
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Aug 30 21:02:16 2012 -0700 @@ -672,20 +672,15 @@ // 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
--- a/src/macosx/native/java/util/MacOSXPreferencesFile.m Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/native/java/util/MacOSXPreferencesFile.m Thu Aug 30 21:02:16 2012 -0700 @@ -641,7 +641,7 @@ // child must end with '/' -JNIEXPORT void JNICALL +JNIEXPORT Boolean JNICALL Java_java_util_prefs_MacOSXPreferencesFile_addChildToNode (JNIEnv *env, jobject klass, jobject jpath, jobject jchild, jobject jname, jlong juser, jlong jhost) @@ -656,6 +656,7 @@ CFDictionaryRef node; CFStringRef topKey; CFMutableDictionaryRef topValue; + Boolean beforeAdd = false; if (!path || !child || !name) goto badparams; @@ -665,9 +666,12 @@ // copyMutableNode creates the node if necessary parent = copyMutableNode(path, name, user, host, &topKey, &topValue); throwIfNull(parent, "copyMutableNode failed"); - + beforeAdd = CFDictionaryContainsKey(parent, child); CFDictionaryAddValue(parent, child, node); - + if (!beforeAdd) + beforeAdd = CFDictionaryContainsKey(parent, child); + else + beforeAdd = false; CFPreferencesSetValue(topKey, topValue, name, user, host); CFRelease(parent); @@ -680,6 +684,7 @@ if (path) CFRelease(path); if (child) CFRelease(child); if (name) CFRelease(name); + return beforeAdd; }
--- a/src/macosx/native/sun/awt/CFileDialog.h Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/native/sun/awt/CFileDialog.h Thu Aug 30 21:02:16 2012 -0700 @@ -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
--- a/src/macosx/native/sun/awt/CFileDialog.m Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/native/sun/awt/CFileDialog.m Thu Aug 30 21:02:16 2012 -0700 @@ -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 @@ mode:mode multipleMode:multipleMode shouldNavigate:navigateApps + canChooseDirectories:chooseDirectories withEnv:env]; [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad)
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m Wed Aug 29 23:05:55 2012 -0700 +++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m Thu Aug 30 21:02:16 2012 -0700 @@ -445,3 +445,20 @@ 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; +} +
--- a/src/share/bin/java.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/java.c Thu Aug 30 21:02:16 2012 -0700 @@ -104,7 +104,6 @@ static jboolean InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn); static jstring NewPlatformString(JNIEnv *env, char *s); -static jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); static jclass LoadMainClass(JNIEnv *env, int mode, char *name); static void TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***pargv); @@ -160,7 +159,7 @@ * Running Java code in primordial thread caused many problems. We will * create a new thread to invoke JVM. See 6316197 for more information. */ -static jlong threadStackSize = 0; /* stack size of the new thread */ +static jlong threadStackSize = 0; /* stack size of the new thread */ static jlong maxHeapSize = 0; /* max heap size */ static jlong initialHeapSize = 0; /* inital heap size */ @@ -202,6 +201,14 @@ InitLauncher(javaw); DumpState(); + if (JLI_IsTraceLauncher()) { + int i; + printf("Command line args:\n"); + for (i = 0; i < argc ; i++) { + printf("argv[%d] = %s\n", i, argv[i]); + } + AddOption("-Dsun.java.launcher.diag=true", NULL); + } /* * Make sure the specified version of the JRE is running. @@ -222,15 +229,6 @@ */ SelectVersion(argc, argv, &main_class); - if (JLI_IsTraceLauncher()) { - int i; - printf("Command line args:\n"); - for (i = 0; i < argc ; i++) { - printf("argv[%d] = %s\n", i, argv[i]); - } - AddOption("-Dsun.java.launcher.diag=true", NULL); - } - CreateExecutionEnvironment(&argc, &argv, jrepath, sizeof(jrepath), jvmpath, sizeof(jvmpath), @@ -435,8 +433,8 @@ "([Ljava/lang/String;)V"); CHECK_EXCEPTION_NULL_LEAVE(mainID); - /* Build argument array */ - mainArgs = NewPlatformStringArray(env, argv, argc); + /* Build platform specific argument array */ + mainArgs = CreateApplicationArgs(env, argv, argc); CHECK_EXCEPTION_NULL_LEAVE(mainArgs); /* Invoke main method. */ @@ -695,6 +693,13 @@ char *def; const char *orig = s; static const char format[] = "-Djava.class.path=%s"; + /* + * usually we should not get a null pointer, but there are cases where + * we might just get one, in which case we simply ignore it, and let the + * caller deal with it + */ + if (s == NULL) + return; s = JLI_WildcardExpandClasspath(s); def = JLI_MemAlloc(sizeof(format) - 2 /* strlen("%s") */ @@ -1113,8 +1118,9 @@ static jclass helperClass = NULL; -static jclass -GetLauncherHelperClass(JNIEnv *env) { +jclass +GetLauncherHelperClass(JNIEnv *env) +{ if (helperClass == NULL) { NULL_CHECK0(helperClass = FindBootStrapClass(env, "sun/launcher/LauncherHelper")); @@ -1158,7 +1164,7 @@ * Returns a new array of Java string objects for the specified * array of platform strings. */ -static jobjectArray +jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc) { jarray cls; @@ -1203,7 +1209,7 @@ end = CounterGet(); printf("%ld micro seconds to load main class\n", (long)(jint)Counter2Micros(end-start)); - printf("----_JAVA_LAUNCHER_DEBUG----\n"); + printf("----%s----\n", JLDEBUG_ENV_ENTRY); } return (jclass)result;
--- a/src/share/bin/java.h Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/java.h Thu Aug 30 21:02:16 2012 -0700 @@ -219,6 +219,10 @@ const char *name)); jclass FindBootStrapClass(JNIEnv *env, const char *classname); +jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc); +jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); +jclass GetLauncherHelperClass(JNIEnv *env); + int JNICALL JavaMain(void * args); /* entry point */ enum LaunchMode { // cf. sun.launcher.LauncherHelper
--- a/src/share/bin/jli_util.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/jli_util.c Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, 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 @@ -102,9 +102,9 @@ void JLI_SetTraceLauncher() { - if (getenv("_JAVA_LAUNCHER_DEBUG") != 0) { + if (getenv(JLDEBUG_ENV_ENTRY) != 0) { _launcher_debug = JNI_TRUE; - JLI_TraceLauncher("----_JAVA_LAUNCHER_DEBUG----\n"); + JLI_TraceLauncher("----%s----\n", JLDEBUG_ENV_ENTRY); } }
--- a/src/share/bin/jli_util.h Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/jli_util.h Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, 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 @@ -27,7 +27,10 @@ #define _JLI_UTIL_H #include <stdlib.h> +#include <string.h> +#include <stdio.h> #include <jni.h> +#define JLDEBUG_ENV_ENTRY "_JAVA_LAUNCHER_DEBUG" void *JLI_MemAlloc(size_t size); void *JLI_MemRealloc(void *ptr, size_t size); @@ -35,6 +38,14 @@ void JLI_MemFree(void *ptr); int JLI_StrCCmp(const char *s1, const char* s2); +typedef struct { + char *arg; + jboolean has_wildcard; +} StdArg; + +StdArg *JLI_GetStdArgs(); +int JLI_GetStdArgc(); + #define JLI_StrLen(p1) strlen((p1)) #define JLI_StrChr(p1, p2) strchr((p1), (p2)) #define JLI_StrRChr(p1, p2) strrchr((p1), (p2)) @@ -56,8 +67,10 @@ #define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2)) #define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3)) #define JLI_Snprintf _snprintf +void JLI_CmdToArgs(char *cmdline); #else #include <unistd.h> +#include <strings.h> #define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2)) #define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3)) #define JLI_Snprintf snprintf
--- a/src/share/bin/main.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/main.c Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -87,22 +87,41 @@ const jboolean const_javaw = JNI_TRUE; __initenv = _environ; - margc = __argc; - margv = __argv; - #else /* JAVAW */ int -main(int argc, char ** argv) +main(int argc, char **argv) { int margc; char** margv; const jboolean const_javaw = JNI_FALSE; - +#endif /* JAVAW */ +#ifdef _WIN32 + { + int i = 0; + if (getenv(JLDEBUG_ENV_ENTRY) != NULL) { + printf("Windows original main args:\n"); + for (i = 0 ; i < __argc ; i++) { + printf("wwwd_args[%d] = %s\n", i, __argv[i]); + } + } + } + JLI_CmdToArgs(GetCommandLine()); + margc = JLI_GetStdArgc(); + // add one more to mark the end + margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *))); + { + int i = 0; + StdArg *stdargs = JLI_GetStdArgs(); + for (i = 0 ; i < margc ; i++) { + margv[i] = stdargs[i].arg; + } + margv[i] = NULL; + } +#else /* *NIXES */ margc = argc; margv = argv; -#endif /* JAVAW */ - +#endif /* WIN32 */ return JLI_Launch(margc, margv, sizeof(const_jargs) / sizeof(char *), const_jargs, sizeof(const_appclasspath) / sizeof(char *), const_appclasspath,
--- a/src/share/bin/wildcard.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/bin/wildcard.c Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, 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 @@ -129,11 +129,11 @@ HANDLE handle; char *firstFile; /* Stupid FindFirstFile...FindNextFile */ }; - +// since this is used repeatedly we keep it here. +static WIN32_FIND_DATA find_data; static WildcardIterator WildcardIterator_for(const char *wildcard) { - WIN32_FIND_DATA find_data; WildcardIterator it = NEW_(WildcardIterator); HANDLE handle = FindFirstFile(wildcard, &find_data); if (handle == INVALID_HANDLE_VALUE) @@ -146,7 +146,6 @@ static char * WildcardIterator_next(WildcardIterator it) { - WIN32_FIND_DATA find_data; if (it->firstFile != NULL) { char *firstFile = it->firstFile; it->firstFile = NULL; @@ -412,7 +411,7 @@ FileList_expandWildcards(fl); expanded = FileList_join(fl, PATH_SEPARATOR); FileList_free(fl); - if (getenv("_JAVA_LAUNCHER_DEBUG") != 0) + if (getenv(JLDEBUG_ENV_ENTRY) != 0) printf("Expanded wildcards:\n" " before: \"%s\"\n" " after : \"%s\"\n",
--- a/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/com/sun/security/auth/module/Krb5LoginModule.java Thu Aug 30 21:02:16 2012 -0700 @@ -454,6 +454,10 @@ useKeyTab = "true".equalsIgnoreCase((String)options.get("useKeyTab")); ticketCacheName = (String)options.get("ticketCache"); keyTabName = (String)options.get("keyTab"); + if (keyTabName != null) { + keyTabName = sun.security.krb5.internal.ktab.KeyTab.normalize( + keyTabName); + } princName = (String)options.get("principal"); refreshKrb5Config = "true".equalsIgnoreCase((String)options.get("refreshKrb5Config"));
--- a/src/share/classes/java/awt/EventDispatchThread.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/java/awt/EventDispatchThread.java Thu Aug 30 21:02:16 2012 -0700 @@ -67,8 +67,7 @@ private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread"); private EventQueue theQueue; - private boolean doDispatch = true; - private volatile boolean shutdown = false; + private volatile boolean doDispatch = true; private static final int ANY_EVENT = -1; @@ -86,11 +85,6 @@ doDispatch = false; } - public void interrupt() { - shutdown = true; - super.interrupt(); - } - public void run() { while (true) { try { @@ -100,7 +94,12 @@ } }); } finally { - if(getEventQueue().detachDispatchThread(this, shutdown)) { + // 7189350: doDispatch is reset from stopDispatching(), + // on InterruptedException, or ThreadDeath. Either way, + // this indicates that we must force shutting down. + if (getEventQueue().detachDispatchThread(this, + !doDispatch || isInterrupted())) + { break; } } @@ -158,8 +157,7 @@ void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { addEventFilter(filter); doDispatch = true; - shutdown |= isInterrupted(); - while (doDispatch && !shutdown && cond.evaluate()) { + while (doDispatch && !isInterrupted() && cond.evaluate()) { pumpOneEventForFilters(id); } removeEventFilter(filter); @@ -247,12 +245,12 @@ } } catch (ThreadDeath death) { - shutdown = true; + doDispatch = false; throw death; } catch (InterruptedException interruptedException) { - shutdown = true; // AppContext.dispose() interrupts all - // Threads in the AppContext + doDispatch = false; // AppContext.dispose() interrupts all + // Threads in the AppContext } catch (Throwable e) { processException(e);
--- a/src/share/classes/java/beans/PropertyDescriptor.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/java/beans/PropertyDescriptor.java Thu Aug 30 21:02:16 2012 -0700 @@ -660,7 +660,7 @@ 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];
--- a/src/share/classes/javax/swing/TimerQueue.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/javax/swing/TimerQueue.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2009, 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 @@ -187,6 +187,9 @@ addTimer(delayedTimer); } } + + // Allow run other threads on systems without kernel threads + timer.getLock().newCondition().awaitNanos(1); } catch (SecurityException ignore) { } finally { timer.getLock().unlock();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/sun/awt/TextureSizeConstraining.java Thu Aug 30 21:02:16 2012 -0700 @@ -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(); + +}
--- a/src/share/classes/sun/launcher/LauncherHelper.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/launcher/LauncherHelper.java Thu Aug 30 21:02:16 2012 -0700 @@ -48,6 +48,9 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.nio.charset.Charset; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ResourceBundle; import java.text.MessageFormat; import java.util.ArrayList; @@ -69,8 +72,6 @@ private static StringBuilder outBuf = new StringBuilder(); - private static ResourceBundle javarb = null; - private static final String INDENT = " "; private static final String VM_SETTINGS = "VM settings:"; private static final String PROP_SETTINGS = "Property settings:"; @@ -78,6 +79,7 @@ // sync with java.c and sun.misc.VM private static final String diagprop = "sun.java.launcher.diag"; + final static boolean trace = sun.misc.VM.getSavedProperty(diagprop) != null; private static final String defaultBundleName = "sun.launcher.resources.launcher"; @@ -428,11 +430,11 @@ if (msgKey != null) { ostream.println(getLocalizedMessage(msgKey, args)); } - if (sun.misc.VM.getSavedProperty(diagprop) != null) { + if (trace) { if (t != null) { t.printStackTrace(); } else { - Thread.currentThread().dumpStack(); + Thread.dumpStack(); } } System.exit(1); @@ -532,4 +534,82 @@ } return null; // keep the compiler happy } + + static String[] expandArgs(String[] argArray) { + List<StdArg> aList = new ArrayList<>(); + for (String x : argArray) { + aList.add(new StdArg(x)); + } + return expandArgs(aList); + } + + static String[] expandArgs(List<StdArg> argList) { + ArrayList<String> out = new ArrayList<>(); + if (trace) { + System.err.println("Incoming arguments:"); + } + for (StdArg a : argList) { + if (trace) { + System.err.println(a); + } + if (a.needsExpansion) { + File x = new File(a.arg); + File parent = x.getParentFile(); + String glob = x.getName(); + if (parent == null) { + parent = new File("."); + } + try (DirectoryStream<Path> dstream = + Files.newDirectoryStream(parent.toPath(), glob)) { + int entries = 0; + for (Path p : dstream) { + out.add(p.normalize().toString()); + entries++; + } + if (entries == 0) { + out.add(a.arg); + } + } catch (Exception e) { + out.add(a.arg); + if (trace) { + System.err.println("Warning: passing argument as-is " + a); + System.err.print(e); + } + } + } else { + out.add(a.arg); + } + } + String[] oarray = new String[out.size()]; + out.toArray(oarray); + + if (trace) { + System.err.println("Expanded arguments:"); + for (String x : oarray) { + System.err.println(x); + } + } + return oarray; + } + + /* duplicate of the native StdArg struct */ + private static class StdArg { + final String arg; + final boolean needsExpansion; + StdArg(String arg, boolean expand) { + this.arg = arg; + this.needsExpansion = expand; + } + // protocol: first char indicates whether expansion is required + // 'T' = true ; needs expansion + // 'F' = false; needs no expansion + StdArg(String in) { + this.arg = in.substring(1); + needsExpansion = in.charAt(0) == 'T'; + } + public String toString() { + return "StdArg{" + "arg=" + arg + ", needsExpansion=" + needsExpansion + '}'; + } + } } +
--- a/src/share/classes/sun/launcher/resources/launcher.properties Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/launcher/resources/launcher.properties Thu Aug 30 21:02:16 2012 -0700 @@ -43,7 +43,7 @@ \ and ZIP archives to search for class files.\n\ \ -D<name>=<value>\n\ \ set a system property\n\ -\ -verbose[:class|gc|jni]\n\ +\ -verbose:[class|gc|jni]\n\ \ enable verbose output\n\ \ -version print product version and exit\n\ \ -version:<value>\n\ @@ -136,3 +136,4 @@ Error: An unexpected error occurred while trying to open file {0} java.launcher.jar.error2=manifest not found in {0} java.launcher.jar.error3=no main manifest attribute, in {0} +java.launcher.init.error=initialization error
--- a/src/share/classes/sun/net/spi/DefaultProxySelector.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/net/spi/DefaultProxySelector.java Thu Aug 30 21:02:16 2012 -0700 @@ -346,5 +346,5 @@ } private native static boolean init(); - private native Proxy getSystemProxy(String protocol, String host); + private synchronized native Proxy getSystemProxy(String protocol, String host); }
--- a/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/rmi/transport/tcp/TCPTransport.java Thu Aug 30 21:02:16 2012 -0700 @@ -28,6 +28,7 @@ import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.UndeclaredThrowableException; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -462,8 +463,10 @@ return; } // continue loop + } else if (t instanceof Error) { + throw (Error) t; } else { - throw (Error) t; + throw new UndeclaredThrowableException(t); } } }
--- a/src/share/classes/sun/security/krb5/Config.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/security/krb5/Config.java Thu Aug 30 21:02:16 2012 -0700 @@ -116,7 +116,12 @@ private static boolean isMacosLionOrBetter() { // split the "10.x.y" version number - String osVersion = System.getProperty("os.version"); + String osname = getProperty("os.name"); + if (!osname.contains("OS X")) { + return false; + } + + String osVersion = getProperty("os.version"); String[] fragments = osVersion.split("\\."); // sanity check the "10." part of the version @@ -141,20 +146,14 @@ /* * If either one system property is specified, we throw exception. */ - String tmp = - java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction - ("java.security.krb5.kdc")); + String tmp = getProperty("java.security.krb5.kdc"); if (tmp != null) { // The user can specify a list of kdc hosts separated by ":" defaultKDC = tmp.replace(':', ' '); } else { defaultKDC = null; } - defaultRealm = - java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction - ("java.security.krb5.realm")); + defaultRealm = getProperty("java.security.krb5.realm"); if ((defaultKDC == null && defaultRealm != null) || (defaultRealm == null && defaultKDC != null)) { throw new KrbException @@ -166,11 +165,34 @@ // Always read the Kerberos configuration file try { Vector<String> configFile; - configFile = loadConfigFile(); - if (configFile == null && isMacosLionOrBetter()) { - stanzaTable = SCDynamicStoreConfig.getConfig(); + String fileName = getJavaFileName(); + if (fileName != null) { + configFile = loadConfigFile(fileName); + stanzaTable = parseStanzaTable(configFile); + if (DEBUG) { + System.out.println("Loaded from Java config"); + } } else { - stanzaTable = parseStanzaTable(configFile); + boolean found = false; + if (isMacosLionOrBetter()) { + try { + stanzaTable = SCDynamicStoreConfig.getConfig(); + if (DEBUG) { + System.out.println("Loaded from SCDynamicStoreConfig"); + } + found = true; + } catch (IOException ioe) { + // OK. Will go on with file + } + } + if (!found) { + fileName = getNativeFileName(); + configFile = loadConfigFile(fileName); + stanzaTable = parseStanzaTable(configFile); + if (DEBUG) { + System.out.println("Loaded from native config"); + } + } } } catch (IOException ioe) { // No krb5.conf, no problem. We'll use DNS or system property etc. @@ -538,10 +560,13 @@ * [domain_realm] * blue.sample.com = TEST.SAMPLE.COM * .backup.com = EXAMPLE.COM + * + * @params fileName the conf file, cannot be null + * @return the content, null if fileName is empty + * @throws IOException if there is an I/O or format error */ - private Vector<String> loadConfigFile() throws IOException { + private Vector<String> loadConfigFile(final String fileName) throws IOException { try { - final String fileName = getFileName(); if (!fileName.equals("")) { BufferedReader br = new BufferedReader(new InputStreamReader( java.security.AccessController.doPrivileged( @@ -660,97 +685,106 @@ } /** - * Gets the default configuration file name. This method will never - * return null. + * Gets the default Java configuration file name. * * If the system property "java.security.krb5.conf" is defined, we'll - * use its value, no matter if the file exists or not. Otherwise, - * the file will be searched in a list of possible loations in the - * following order: + * use its value, no matter if the file exists or not. Otherwise, we + * will look at $JAVA_HOME/lib/security directory with "krb5.conf" name, + * and return it if the file exists. * - * 1. at Java home lib\security directory with "krb5.conf" name, - * 2. at windows directory with the name of "krb5.ini" for Windows, - * /etc/krb5/krb5.conf for Solaris, /etc/krb5.conf otherwise. + * The method returns null if it cannot find a Java config file. + */ + private String getJavaFileName() { + String name = getProperty("java.security.krb5.conf"); + if (name == null) { + name = getProperty("java.home") + File.separator + + "lib" + File.separator + "security" + + File.separator + "krb5.conf"; + if (!fileExists(name)) { + name = null; + } + } + if (DEBUG) { + System.out.println("Java config name: " + name); + } + return name; + } + + /** + * Gets the default native configuration file name. + * + * Depending on the OS type, the method returns the default native + * kerberos config file name, which is at windows directory with + * the name of "krb5.ini" for Windows, /etc/krb5/krb5.conf for Solaris, + * /etc/krb5.conf otherwise. Mac OSX X has a different file name. * * Note: When the Terminal Service is started in Windows (from 2003), * there are two kinds of Windows directories: A system one (say, * C:\Windows), and a user-private one (say, C:\Users\Me\Windows). * We will first look for krb5.ini in the user-private one. If not * found, try the system one instead. + * + * This method will always return a non-null non-empty file name, + * even if that file does not exist. */ - private String getFileName() { - String name = - java.security.AccessController.doPrivileged( - new sun.security.action. - GetPropertyAction("java.security.krb5.conf")); - if (name == null) { - name = java.security.AccessController.doPrivileged( - new sun.security.action. - GetPropertyAction("java.home")) + File.separator + - "lib" + File.separator + "security" + - File.separator + "krb5.conf"; - if (!fileExists(name)) { - name = null; - String osname = - java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction("os.name")); - if (osname.startsWith("Windows")) { - try { - Credentials.ensureLoaded(); - } catch (Exception e) { - // ignore exceptions + private String getNativeFileName() { + String name = null; + String osname = getProperty("os.name"); + if (osname.startsWith("Windows")) { + try { + Credentials.ensureLoaded(); + } catch (Exception e) { + // ignore exceptions + } + if (Credentials.alreadyLoaded) { + String path = getWindowsDirectory(false); + if (path != null) { + if (path.endsWith("\\")) { + path = path + "krb5.ini"; + } else { + path = path + "\\krb5.ini"; } - if (Credentials.alreadyLoaded) { - String path = getWindowsDirectory(false); - if (path != null) { - if (path.endsWith("\\")) { - path = path + "krb5.ini"; - } else { - path = path + "\\krb5.ini"; - } - if (fileExists(path)) { - name = path; - } + if (fileExists(path)) { + name = path; + } + } + if (name == null) { + path = getWindowsDirectory(true); + if (path != null) { + if (path.endsWith("\\")) { + path = path + "krb5.ini"; + } else { + path = path + "\\krb5.ini"; } - if (name == null) { - path = getWindowsDirectory(true); - if (path != null) { - if (path.endsWith("\\")) { - path = path + "krb5.ini"; - } else { - path = path + "\\krb5.ini"; - } - name = path; - } - } + name = path; } - if (name == null) { - name = "c:\\winnt\\krb5.ini"; - } - } else if (osname.startsWith("SunOS")) { - name = "/etc/krb5/krb5.conf"; - } else if (osname.contains("OS X")) { - if (isMacosLionOrBetter()) return ""; - name = findMacosConfigFile(); - } else { - name = "/etc/krb5.conf"; } } + if (name == null) { + name = "c:\\winnt\\krb5.ini"; + } + } else if (osname.startsWith("SunOS")) { + name = "/etc/krb5/krb5.conf"; + } else if (osname.contains("OS X")) { + name = findMacosConfigFile(); + } else { + name = "/etc/krb5.conf"; } if (DEBUG) { - System.out.println("Config name: " + name); + System.out.println("Native config name: " + name); } return name; } - private String getProperty(String property) { - return (String)java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction(property)); + private static String getProperty(String property) { + return java.security.AccessController.doPrivileged( + new sun.security.action.GetPropertyAction(property)); } private String findMacosConfigFile() { String userHome = getProperty("user.home"); final String PREF_FILE = "/Library/Preferences/edu.mit.Kerberos"; - String userPrefs=userHome + PREF_FILE; + String userPrefs = userHome + PREF_FILE; if (fileExists(userPrefs)) { return userPrefs; @@ -760,11 +794,7 @@ return PREF_FILE; } - if (fileExists("/etc/krb5.conf")) { - return "/etc/krb5.conf"; - } - - return ""; + return "/etc/krb5.conf"; } private static String trimmed(String s) { @@ -1334,32 +1364,52 @@ } } + // Shows the content of the Config object for debug purpose. + // + // { + // libdefaults = { + // default_realm = R + // } + // realms = { + // R = { + // kdc = [k1,k2] + // } + // } + // } + @Override public String toString() { StringBuffer sb = new StringBuffer(); - toStringIndented("", stanzaTable, sb); + toStringInternal("", stanzaTable, sb); return sb.toString(); } - private static void toStringIndented(String prefix, Object obj, + private static void toStringInternal(String prefix, Object obj, StringBuffer sb) { if (obj instanceof String) { - sb.append(prefix); - sb.append(obj); - sb.append('\n'); + // A string value, just print it + sb.append(obj).append('\n'); } else if (obj instanceof Hashtable) { - Hashtable tab = (Hashtable)obj; + // A table, start a new sub-section... + Hashtable<?, ?> tab = (Hashtable<?, ?>)obj; + sb.append("{\n"); for (Object o: tab.keySet()) { - sb.append(prefix); + // ...indent, print "key = ", and + sb.append(prefix).append(" ").append(o).append(" = "); + // ...go recursively into value + toStringInternal(prefix + " ", tab.get(o), sb); + } + sb.append(prefix).append("}\n"); + } else if (obj instanceof Vector) { + // A vector of strings, print them inside [ and ] + Vector<?> v = (Vector<?>)obj; + sb.append("["); + boolean first = true; + for (Object o: v.toArray()) { + if (!first) sb.append(","); sb.append(o); - sb.append(" = {\n"); - toStringIndented(prefix + " ", tab.get(o), sb); - sb.append(prefix + "}\n"); + first = false; } - } else if (obj instanceof Vector) { - Vector v = (Vector)obj; - for (Object o: v.toArray()) { - toStringIndented(prefix + " ", o, sb); - } + sb.append("]\n"); } } }
--- a/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java Thu Aug 30 21:02:16 2012 -0700 @@ -141,7 +141,7 @@ if (s == null) { return getInstance(); } else { - return getInstance0(parse(s)); + return getInstance0(normalize(s)); } } @@ -191,7 +191,7 @@ if (keytab_names != null) { StringTokenizer st = new StringTokenizer(keytab_names, " "); while (st.hasMoreTokens()) { - kname = parse(st.nextToken()); + kname = normalize(st.nextToken()); if (new File(kname).exists()) { break; } @@ -220,11 +220,13 @@ } /** - * Parses some common keytab name formats + * Normalizes some common keytab name formats into the bare file name. + * For example, FILE:/etc/krb5.keytab to /etc/krb5.keytab * @param name never null * @return never null */ - private static String parse(String name) { + // This method is used in this class and Krb5LoginModule + public static String normalize(String name) { String kname; if ((name.length() >= 5) && (name.substring(0, 5).equalsIgnoreCase("FILE:"))) {
--- a/src/share/native/sun/awt/medialib/mlib_types.h Wed Aug 29 23:05:55 2012 -0700 +++ b/src/share/native/sun/awt/medialib/mlib_types.h Thu Aug 30 21:02:16 2012 -0700 @@ -59,8 +59,16 @@ #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__GNUC__) +#if defined(MACOSX) #include <stddef.h> /* for ptrdiff_t */ #include <stdint.h> /* for uintptr_t */ +#elif defined(__linux__) +#include <stdint.h> /* for uintptr_t */ +#include <malloc.h> /* for ptrdiff_t */ +#else +#include <link.h> /* for uintptr_t */ +#include <stddef.h> /* for ptrdiff_t */ +#endif /* __linux__ */ #if defined(MLIB_OS64BIT) || (defined(MACOSX) && defined(_LP64))
--- a/src/solaris/bin/java_md_common.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/solaris/bin/java_md_common.c Thu Aug 30 21:02:16 2012 -0700 @@ -502,3 +502,19 @@ return findBootClass(env, classname); } +StdArg +*JLI_GetStdArgs() +{ + return NULL; +} + +int +JLI_GetStdArgc() { + return 0; +} + +jobjectArray +CreateApplicationArgs(JNIEnv *env, char **strv, int argc) +{ + return NewPlatformStringArray(env, strv, argc); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/windows/bin/cmdtoargs.c Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,598 @@ +/* + * 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. + */ + + +/* + * Converts a single string command line to the traditional argc, argv. + * There are rules which govern the breaking of the the arguments, and + * these rules are embodied in the regression tests below, and duplicated + * in the jdk regression tests. + */ + +#ifndef IDE_STANDALONE +#include "java.h" +#include "jli_util.h" +#else /* IDE_STANDALONE */ +// The defines we need for stand alone testing +#include <stdio.h> +#include <stdlib.h> +#include <Windows.h> +#define JNI_TRUE TRUE +#define JNI_FALSE FALSE +#define JLI_MemRealloc realloc +#define JLI_StringDup _strdup +#define JLI_MemFree free +#define jboolean boolean +typedef struct { + char* arg; + boolean has_wildcard; +} StdArg ; +#endif +static StdArg *stdargs; +static int stdargc; + +static char* next_arg(char* cmdline, char* arg, jboolean* wildcard) { + + char* src = cmdline; + char* dest = arg; + jboolean separator = JNI_FALSE; + int quotes = 0; + int slashes = 0; + + char prev = 0; + char ch = 0; + int i; + jboolean done = JNI_FALSE; + + *wildcard = JNI_FALSE; + while ((ch = *src) != 0 && !done) { + switch (ch) { + case '"': + if (separator) { + done = JNI_TRUE; + break; + } + if (prev == '\\') { + for (i = 1; i < slashes; i += 2) { + *dest++ = prev; + } + if (slashes % 2 == 1) { + *dest++ = ch; + } else { + quotes++; + } + } else if (prev == '"' && quotes % 2 == 0) { + quotes++; + *dest++ = ch; // emit every other consecutive quote + } else if (quotes == 0) { + quotes++; // starting quote + } else { + quotes--; // matching quote + } + slashes = 0; + break; + + case '\\': + slashes++; + if (separator) { + done = JNI_TRUE; + separator = JNI_FALSE; + } + break; + + case ' ': + case '\t': + if (quotes % 2 == 1) { + *dest++ = ch; + } else { + separator = JNI_TRUE; + } + slashes = 0; + break; + + case '*': + case '?': + if (separator) { + done = JNI_TRUE; + separator = JNI_FALSE; + break; + } + if (quotes % 2 == 0) { + *wildcard = JNI_TRUE; + } + if (prev == '\\') { + *dest++ = prev; + } + *dest++ = ch; + break; + + default: + if (prev == '\\') { + for (i = 0 ; i < slashes ; i++) { + *dest++ = prev; + } + *dest++ = ch; + } else if (separator) { + done = JNI_TRUE; + } else { + *dest++ = ch; + } + slashes = 0; + } + + if (!done) { + prev = ch; + src++; + } + } + if (prev == '\\') { + for (i = 0; i < slashes; i++) { + *dest++ = prev; + } + } + *dest = 0; + return done ? src : NULL; +} + +int JLI_GetStdArgc() { + return stdargc; +} + +StdArg* JLI_GetStdArgs() { + return stdargs; +} + +void JLI_CmdToArgs(char* cmdline) { + int nargs = 0; + StdArg* argv = NULL; + jboolean wildcard = JNI_FALSE; + char* src = cmdline; + + // allocate arg buffer with sufficient space to receive the largest arg + char* arg = JLI_StringDup(cmdline); + + do { + src = next_arg(src, arg, &wildcard); + // resize to accommodate another Arg + argv = (StdArg*) JLI_MemRealloc(argv, (nargs+1) * sizeof(StdArg)); + argv[nargs].arg = JLI_StringDup(arg); + argv[nargs].has_wildcard = wildcard; + + nargs++; + } while (src != NULL); + + stdargc = nargs; + stdargs = argv; +} + +#ifdef IDE_STANDALONE +void doexit(int rv) { + printf("Hit any key to quit\n"); + int c = getchar(); + exit(rv); +} + +void doabort() { + doexit(1); +} + +class Vector { +public: + char* cmdline; + int argc; + char* argv[10]; + boolean wildcard[10]; + boolean enabled; + + Vector(){} + // Initialize our test vector with the program name, argv[0] + // and the single string command line. + Vector(char* pname, char* cline) { + argv[0] = pname; + wildcard[0] = FALSE; + cmdline = cline; + argc = 1; + enabled = TRUE; + } + + // add our expected strings, the program name has already been + // added so ignore that + void add(char* arg, boolean w) { + argv[argc] = arg; + wildcard[argc] = w; + argc++; + } + + void disable() { + enabled = FALSE; + } + + // validate the returned arguments with the expected arguments, using the + // new CmdToArgs method. + bool check() { + // "pgmname" rest of cmdline ie. pgmname + 2 double quotes + space + cmdline from windows + char* cptr = (char*) malloc(strlen(argv[0]) + sizeof(char) * 3 + strlen(cmdline) + 1); + _snprintf(cptr, MAX_PATH, "\"%s\" %s", argv[0], cmdline); + JLI_CmdToArgs(cptr); + free(cptr); + StdArg *kargv = JLI_GetStdArgs(); + int kargc = JLI_GetStdArgc(); + bool retval = true; + printf("\n===========================\n"); + printf("cmdline=%s\n", cmdline); + if (argc != kargc) { + printf("*** argument count does not match\n"); + printme(); + printtest(kargc, kargv); + doabort(); + } + for (int i = 0 ; i < argc && retval == true ; i++) { + if (strcmp(argv[i], kargv[i].arg) != 0) { + printf("*** argument at [%d] don't match\n got: %s\n exp: %s\n", + i, kargv[i].arg, argv[i]); + doabort(); + } + } + for (int i = 0 ; i < argc && retval == true ; i++) { + if (wildcard[i] != kargv[i].has_wildcard) { + printf("*** expansion flag at [%d] doesn't match\n got: %d\n exp: %d\n", + i, kargv[i].has_wildcard, wildcard[i]); + doabort(); + } + } + for (int i = 0 ; i < kargc ; i++) { + printf("k[%d]=%s\n", i, kargv[i].arg); + printf(" [%d]=%s\n", i, argv[i]); + } + return retval; + } + void printtest(int kargc, StdArg* kargv) { + for (int i = 0 ; i < kargc ; i++) { + printf("k[%d]=%s\n", i, kargv[i].arg); + } + } + void printme() { + for (int i = 0 ; i < argc ; i++) { + printf(" [%d]=%s\n", i, argv[i]); + } + } +}; + +void dotest(Vector** vectors) { + Vector* v = vectors[0]; + for (int i = 0 ; v != NULL;) { + if (v->enabled) { + v->check(); + } + v = vectors[++i]; + } +} + +#define MAXV 128 +int main(int argc, char* argv[]) { + + int n; + for (n=1; n < argc; n++) { + printf("%d %s\n", n, argv[n]); + } + if (n > 1) { + JLI_CmdToArgs(GetCommandLine()); + for (n = 0; n < stdargc; n++) { + printf(" [%d]=%s\n", n, stdargs[n].arg); + printf(" [%d]=%s\n", n, stdargs[n].has_wildcard ? "TRUE" : "FALSE"); + } + doexit(0); + } + + Vector *vectors[MAXV]; + + memset(vectors, 0, sizeof(vectors)); + int i = 0; + Vector* v = new Vector(argv[0], "abcd"); + v->add("abcd", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"a b c d\""); + v->add("a b c d", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a\"b c d\"e"); + v->add("ab c de", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "ab\\\"cd"); + v->add("ab\"cd", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"a b c d\\\\\""); + v->add("a b c d\\", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "ab\\\\\\\"cd"); + v->add("ab\\\"cd", FALSE); + // v->disable(); + vectors[i++] = v; + + + // Windows tests + v = new Vector(argv[0], "a\\\\\\c"); + v->add("a\\\\\\c", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"a\\\\\\d\""); + v->add("a\\\\\\d", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"a b c\" d e"); + v->add("a b c", FALSE); + v->add("d", FALSE); + v->add("e", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"ab\\\"c\" \"\\\\\" d"); + v->add("ab\"c", FALSE); + v->add("\\", FALSE); + v->add("d", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a\\\\\\c d\"e f\"g h"); + v->add("a\\\\\\c", FALSE); + v->add("de fg", FALSE); + v->add("h", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a\\\\\\\"b c d"); + v->add("a\\\"b", FALSE); // XXX "a\\\\\\\"b" + v->add("c", FALSE); + v->add("d", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a\\\\\\\\\"g c\" d e"); // XXX "a\\\\\\\\\"b c\" d e" + v->add("a\\\\\g c", FALSE); // XXX "a\\\\\\\\\"b c" + v->add("d", FALSE); + v->add("e", FALSE); + // v->disable(); + vectors[i++] = v; + + + // Additional tests + v = new Vector(argv[0], "\"a b c\"\""); + v->add("a b c\"", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"\"a b c\"\""); + v->add("a", FALSE); + v->add("b", FALSE); + v->add("c", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"\"\"a b c\"\"\""); + v->add("\"a b c\"", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"\"\"\"a b c\"\"\"\""); + v->add("\"a", FALSE); + v->add("b", FALSE); + v->add("c\"", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"\"\"\"\"a b c\"\"\"\"\""); + v->add("\"\"a b c\"\"", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"C:\\TEST A\\\\\""); + v->add("C:\\TEST A\\", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"\"C:\\TEST A\\\\\"\""); + v->add("C:\\TEST", FALSE); + v->add("A\\", FALSE); + // v->disable(); + vectors[i++] = v; + + + // test if a wildcard is present + v = new Vector(argv[0], "abc*def"); + v->add("abc*def", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"abc*def\""); + v->add("abc*def", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "*.abc"); + v->add("*.abc", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"*.abc\""); + v->add("*.abc", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "x.???"); + v->add("x.???", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\"x.???\""); + v->add("x.???", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "Debug\\*"); + v->add("Debug\\*", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "Debug\\f?a"); + v->add("Debug\\f?a", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "Debug\\?a.java"); + v->add("Debug\\?a.java", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "foo *.noexts"); + v->add("foo", FALSE); + v->add("*.noexts", TRUE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "X\\Y\\Z"); + v->add("X\\Y\\Z", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "\\X\\Y\\Z"); + v->add("\\X\\Y\\Z", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a b"); + v->add("a", FALSE); + v->add("b", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a\tb"); + v->add("a", FALSE); + v->add("b", FALSE); + // v->disable(); + vectors[i++] = v; + + + v = new Vector(argv[0], "a \t b"); + v->add("a", FALSE); + v->add("b", FALSE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "*\\"); + v->add("*\\", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "*/"); + v->add("*/", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], ".\\*"); + v->add(".\\*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "./*"); + v->add("./*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], ".\\*"); + v->add(".\\*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], ".//*"); + v->add(".//*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "..\\..\\*"); + v->add("..\\..\\*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "../../*"); + v->add("../../*", TRUE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "..\\..\\"); + v->add("..\\..\\", FALSE); + // v->disable(); + vectors[i++] = v; + + v = new Vector(argv[0], "../../"); + v->add("../../", FALSE); + // v->disable(); + vectors[i++] = v; + + dotest(vectors); + printf("All tests pass [%d]\n", i); + doexit(0); +} +#endif /* IDE_STANDALONE */
--- a/src/windows/bin/java_md.c Wed Aug 29 23:05:55 2012 -0700 +++ b/src/windows/bin/java_md.c Thu Aug 30 21:02:16 2012 -0700 @@ -1357,3 +1357,89 @@ { return JNI_FALSE; } + +/* + * At this point we have the arguments to the application, and we need to + * check with original stdargs in order to compare which of these truly + * needs expansion. cmdtoargs will specify this if it finds a bare + * (unquoted) argument containing a glob character(s) ie. * or ? + */ +jobjectArray +CreateApplicationArgs(JNIEnv *env, char **strv, int argc) +{ + int i, j, idx, tlen; + jobjectArray outArray, inArray; + char *ostart, *astart, **nargv; + jboolean needs_expansion = JNI_FALSE; + jmethodID mid; + int stdargc; + StdArg *stdargs; + jclass cls = GetLauncherHelperClass(env); + NULL_CHECK0(cls); + + if (argc == 0) { + return NewPlatformStringArray(env, strv, argc); + } + // the holy grail we need to compare with. + stdargs = JLI_GetStdArgs(); + stdargc = JLI_GetStdArgc(); + + // sanity check, this should never happen + if (argc > stdargc) { + JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc); + JLI_TraceLauncher("passing arguments as-is.\n"); + return NewPlatformStringArray(env, strv, argc); + } + + // sanity check, match the args we have, to the holy grail + idx = stdargc - argc; + ostart = stdargs[idx].arg; + astart = strv[0]; + // sanity check, ensure that the first argument of the arrays are the same + if (JLI_StrCmp(ostart, astart) != 0) { + // some thing is amiss the args don't match + JLI_TraceLauncher("Warning: app args parsing error\n"); + JLI_TraceLauncher("passing arguments as-is\n"); + return NewPlatformStringArray(env, strv, argc); + } + + // make a copy of the args which will be expanded in java if required. + nargv = (char **)JLI_MemAlloc(argc * sizeof(char*)); + for (i = 0, j = idx; i < argc; i++, j++) { + jboolean arg_expand = (JLI_StrCmp(stdargs[j].arg, strv[i]) == 0) + ? stdargs[j].has_wildcard + : JNI_FALSE; + if (needs_expansion == JNI_FALSE) + needs_expansion = arg_expand; + + // indicator char + String + NULL terminator, the java method will strip + // out the first character, the indicator character, so no matter what + // we add the indicator + tlen = 1 + JLI_StrLen(strv[i]) + 1; + nargv[i] = (char *) JLI_MemAlloc(tlen); + JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F', strv[i]); + JLI_TraceLauncher("%s\n", nargv[i]); + } + + if (!needs_expansion) { + // clean up any allocated memory and return back the old arguments + for (i = 0 ; i < argc ; i++) { + JLI_MemFree(nargv[i]); + } + JLI_MemFree(nargv); + return NewPlatformStringArray(env, strv, argc); + } + NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, + "expandArgs", + "([Ljava/lang/String;)[Ljava/lang/String;")); + + // expand the arguments that require expansion, the java method will strip + // out the indicator character. + inArray = NewPlatformStringArray(env, nargv, argc); + outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray); + for (i = 0; i < argc; i++) { + JLI_MemFree(nargv[i]); + } + JLI_MemFree(nargv); + return outArray; +}
--- a/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java Wed Aug 29 23:05:55 2012 -0700 +++ b/src/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java Thu Aug 30 21:02:16 2012 -0700 @@ -352,19 +352,34 @@ } } + /** + * Checks if the given file(or directory) exists and is readable. + */ + private void checkReadAccess(WindowsPath file) throws IOException { + try { + Set<OpenOption> opts = Collections.emptySet(); + FileChannel fc = WindowsChannelFactory + .newFileChannel(file.getPathForWin32Calls(), + file.getPathForPermissionCheck(), + opts, + 0L); + fc.close(); + } catch (WindowsException exc) { + // Windows errors are very inconsistent when the file is a directory + // (ERROR_PATH_NOT_FOUND returned for root directories for example) + // so we retry by attempting to open it as a directory. + try { + new WindowsDirectoryStream(file, null).close(); + } catch (IOException ioe) { + // translate and throw original exception + exc.rethrowAsIOException(file); + } + } + } + @Override public void checkAccess(Path obj, AccessMode... modes) throws IOException { WindowsPath file = WindowsPath.toWindowsPath(obj); - // if no access modes then simply file attributes - if (modes.length == 0) { - file.checkRead(); - try { - WindowsFileAttributes.get(file, true); - } catch (WindowsException exc) { - exc.rethrowAsIOException(file); - } - return; - } boolean r = false; boolean w = false; @@ -378,6 +393,13 @@ } } + // special-case read access to avoid needing to determine effective + // access to file; default if modes not specified + if (!w && !x) { + checkReadAccess(file); + return; + } + int mask = 0; if (r) { file.checkRead();
--- a/test/ProblemList.txt Wed Aug 29 23:05:55 2012 -0700 +++ b/test/ProblemList.txt Thu Aug 30 21:02:16 2012 -0700 @@ -309,7 +309,6 @@ # Need to be marked othervm, or changed to be samevm safe com/sun/jndi/ldap/ReadTimeoutTest.java generic-all -com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all # Need to be marked othervm, or changed to be samevm safe com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java generic-all @@ -517,7 +516,6 @@ java/rmi/activation/CommandEnvironment/SetChildEnv.java generic-all java/rmi/registry/classPathCodebase/ClassPathCodebase.java generic-all java/rmi/registry/reexport/Reexport.java generic-all -java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java generic-all java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java generic-all java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java generic-all java/rmi/server/useCustomRef/UseCustomRef.java generic-all
--- a/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java Thu Aug 30 21:02:16 2012 -0700 @@ -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 @@ -25,26 +25,21 @@ * @test * @bug 6676075 * @summary RegistryContext (com.sun.jndi.url.rmi.rmiURLContext) coding problem + * @library ../../../../../../java/rmi/testlibrary + * @build TestLibrary + * @run main ContextWithNullProperties */ -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; - -import com.sun.jndi.rmi.registry.*; +import com.sun.jndi.rmi.registry.RegistryContext; +import java.rmi.registry.Registry; public class ContextWithNullProperties { - public static void main(String[] args) throws Exception { - - // Create registry on port 1099 if one is not already running. - try { - LocateRegistry.createRegistry(1099); - } catch (RemoteException e) { - } - + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); System.out.println("Connecting to the default Registry..."); // Connect to the default Registry. // Pass null as the JNDI environment properties (see final argument) - RegistryContext ctx = new RegistryContext(null, -1, null); + RegistryContext ctx = new RegistryContext(null, registryPort, null); } }
--- a/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,26 +1,52 @@ +/* + * 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 + * 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 4278121 * @summary Ensure that calling unbind() on an unbound name returns * successfully. + * @library ../../../../../../java/rmi/testlibrary + * @build TestLibrary + * @run main UnbindIdempotent */ -import javax.naming.*; +import java.rmi.registry.Registry; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; public class UnbindIdempotent { public static void main(String[] args) throws Exception { + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + InitialContext ictx = new InitialContext(); + Context rctx; - // Create registry on port 1099 if one is not already running. try { - java.rmi.registry.LocateRegistry.createRegistry(1099); - } catch (java.rmi.RemoteException e) { - } - - Context ictx = new InitialContext(); - Context rctx; - try { - rctx = (Context)ictx.lookup("rmi://localhost:1099"); + rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort)); } catch (NamingException e) { // Unable to set up for test. return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Frame/HugeFrame/HugeFrame.java Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,49 @@ +/* + * 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 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); + + // We would crash by now if the bug wasn't fixed + Thread.sleep(1000); + System.err.println(f.getBounds()); + + // Cleanup + f.dispose(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/beans/Introspector/Test7189112.java Thu Aug 30 21:02:16 2012 -0700 @@ -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(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/net/ProxySelector/MultiThreadedSystemProxies.java Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,63 @@ +/* + * 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 7188755 + * @run main/othervm MultiThreadedSystemProxies + * @summary Crash due to missing synchronization on gconf_client in + * DefaultProxySelector.c + */ +import java.net.ProxySelector; +import java.net.URI; + +/* Racey test, not guaranteed to fail, but if it does we have a problem. */ + +public class MultiThreadedSystemProxies { + static final int NUM_THREADS = 100; + + public static void main(String[] args) throws Exception { + System.setProperty("java.net.useSystemProxies", "true"); + final ProxySelector ps = ProxySelector.getDefault(); + final URI uri = new URI("http://ubuntu.com"); + Thread[] threads = new Thread[NUM_THREADS]; + + for (int i = 0; i < NUM_THREADS; i++) { + threads[i] = new Thread(new Runnable() { + @Override + public void run() { + try { + ps.select(uri); + } catch (Exception x) { + throw new RuntimeException(x); + } + } + }); + } + for (int i = 0; i < NUM_THREADS; i++) { + threads[i].start(); + } + for (int i = 0; i < NUM_THREADS; i++) { + threads[i].join(); + } + } +}
--- a/test/java/rmi/Naming/LookupNameWithColon.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/Naming/LookupNameWithColon.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -25,10 +25,13 @@ * @bug 4387038 * @summary Ensure that java.rmi.Naming.lookup functions properly for names * containing embedded ':' characters. + * + * @library ../testlibrary + * @build TestLibrary + * @run main LookupNameWithColon */ import java.rmi.Naming; -import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; public class LookupNameWithColon { @@ -38,15 +41,12 @@ "multiple:colons:in:name" }; - Registry reg; - try { - reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); - } catch (Exception ex) { - reg = LocateRegistry.getRegistry(); - } + Registry reg = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(reg); + for (int i = 0; i < names.length; i++) { reg.rebind(names[i], reg); - Naming.lookup("rmi://localhost/" + names[i]); + Naming.lookup("rmi://localhost:" + port + "/" + names[i]); } } }
--- a/test/java/rmi/Naming/RmiIsNoScheme.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/Naming/RmiIsNoScheme.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 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 @@ -39,9 +39,6 @@ import java.rmi.registry.*; public class RmiIsNoScheme implements Remote, Serializable { - - private static final int REGISTRY_PORT = 2002; - private RmiIsNoScheme() {} public static void main(String[] args) { @@ -49,10 +46,11 @@ System.err.println("\nRegression test for bug 4626311\n"); try { - LocateRegistry.createRegistry(REGISTRY_PORT); - Naming.rebind("//:" + REGISTRY_PORT + "/RmiIsNoScheme", + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + Naming.rebind("//:" + registryPort + "/RmiIsNoScheme", new RmiIsNoScheme()); - String name = Naming.list("//:" + REGISTRY_PORT)[0]; + String name = Naming.list("//:" + registryPort)[0]; System.err.println("name = " + name); if (name.startsWith("rmi:", 0) == false) { System.err.println("TEST PASSED: rmi scheme not present");
--- a/test/java/rmi/Naming/UnderscoreHost.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/Naming/UnderscoreHost.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2005, 2006, 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. - */ + /* + * 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 + * 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 5083594 - * @summary Ensure that Naming.java correctly parses host names with '_' in - * them. - * @author Vinod Johnson - * - * @library ../testlibrary - * @build TestLibrary - * @build UnderscoreHost UnderscoreHost_Stub - * @run main/othervm UnderscoreHost + /* + * @test + * @bug 5083594 + * @summary Ensure that Naming.java correctly parses host names with '_' in + * them. + * @author Vinod Johnson + * + * @library ../testlibrary + * @build TestLibrary + * @build UnderscoreHost UnderscoreHost_Stub + * @run main/othervm UnderscoreHost */ import java.io.IOException; @@ -77,11 +77,12 @@ try { HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory(); RMISocketFactory.setSocketFactory(hvf); - Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); + Registry r = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(r); t = new UnderscoreHost(); r.rebind(NAME, t); Naming.lookup("rmi://" + HOSTNAME + - ":" + Registry.REGISTRY_PORT + "/" + NAME); + ":" + port + "/" + NAME); /* * This test is coded to pass whether java.net.URI obeys * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
--- a/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2004, 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 @@ -45,7 +45,9 @@ /** * Ensure that all legal forms of Naming URLs operate with the - * java.rmi.Naming interface + * java.rmi.Naming interface. This test requires using the default RMI Registry + * port as it tests all of the RMI naming URL's, including the ones which do not + * take a port (and therefore uses the default port). */ public class LegalRegistryNames extends UnicastRemoteObject implements Legal
--- a/test/java/rmi/activation/Activatable/checkActivateRef/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/checkActivateRef/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -29,11 +29,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/checkAnnotations/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/checkAnnotations/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -32,11 +32,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,17 +21,18 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting object with non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
--- a/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -31,11 +31,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
--- a/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -30,11 +30,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -17,11 +17,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
--- a/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/inactiveGroup/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/inactiveGroup/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,17 +21,18 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting object with non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
--- a/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -58,7 +58,7 @@ System.err.println("look up activation system"); Registry rmidRegistry = - LocateRegistry.getRegistry(ActivationSystem.SYSTEM_PORT); + LocateRegistry.getRegistry(rmid.getPort()); ActivationSystem system = (ActivationSystem) rmidRegistry.lookup(NAME);
--- a/test/java/rmi/activation/Activatable/nestedActivate/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/nestedActivate/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,17 +21,18 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting of non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
--- a/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/restartCrashedService/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/restartCrashedService/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/Activatable/restartLatecomer/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/restartLatecomer/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Used in remote impl of Activator.inactive; by the method // "restartThread.dispose()"when it calls thread.interrupt()
--- a/test/java/rmi/activation/Activatable/restartService/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/restartService/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Used in remote impl of Activator.inactive; by the method // "restartThread.dispose()"when it calls thread.interrupt()
--- a/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
--- a/test/java/rmi/activation/Activatable/unregisterInactive/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/Activatable/unregisterInactive/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -15,11 +15,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
--- a/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,11 +21,12 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, 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 @@ -61,7 +61,7 @@ extends Activatable implements Runnable, CanCreateStubs { public static boolean sameGroup = false; - + private static int registryPort = -1; private static CanCreateStubs canCreateStubs = null; private static Registry registry = null; @@ -76,8 +76,8 @@ try { TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); - registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); // must run with java.lang.SecurityManager or the test // result will be nullified if running with a build where @@ -192,7 +192,7 @@ // obtain reference to the test registry registry = java.rmi.registry.LocateRegistry. - getRegistry(TestLibrary.REGISTRY_PORT); + getRegistry(registryPort); } /**
--- a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,15 +21,22 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; + // required for test to get the registry port + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; + // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; };
--- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,36 +45,29 @@ import java.util.Properties; class Callback extends UnicastRemoteObject implements CallbackInterface { - - public static int num_deactivated = 0; + public int num_deactivated = 0; - public Callback() throws RemoteException { super(); } - - public void inc() throws RemoteException { - incNumDeactivated(); - } + public Callback() throws RemoteException { super(); } - public synchronized int getNumDeactivated() throws RemoteException { - return(num_deactivated); - } + public synchronized void inc() throws RemoteException { + num_deactivated++; + } - public synchronized void incNumDeactivated() { - num_deactivated++; - } - + public synchronized int getNumDeactivated() throws RemoteException { + return num_deactivated; + } } public class UnregisterGroup extends Activatable implements ActivateMe, Runnable { - private static Exception exception = null; private static String error = null; private static boolean done = false; private static ActivateMe lastResortExitObj = null; private static final int NUM_OBJECTS = 10; - private static int PORT = 2006; + private static int registryPort = -1; public UnregisterGroup(ActivationID id, MarshalledObject mobj) throws Exception @@ -104,36 +97,47 @@ } /** - * Thread to deactivate object. First attempts to make object - * inactive (via the inactive method). If that fails (the - * object may still have pending/executing calls), then - * unexport the object forcibly. + * Thread to deactivate object. Get the callback object from the registry, + * call inc() on it, and finally call deactivate(). The call to + * deactivate() causes this JVM to be destroyed, so anything following + * might not be executed. */ public void run() { + String regPortStr = System.getProperty("unregisterGroup.port"); + int regPort = -1; - ActivationLibrary.deactivate(this, getID()); - System.err.println("\tActivationLibrary.deactivate returned"); + if (regPortStr != null) { + regPort = Integer.parseInt(regPortStr); + } try { CallbackInterface cobj = - (CallbackInterface)Naming.lookup("//:" + PORT + "/Callback"); + (CallbackInterface)Naming.lookup("//:" + regPort + "/Callback"); cobj.inc(); + System.err.println("cobj.inc called and returned ok"); } catch (Exception e) { System.err.println("cobj.inc exception"); e.printStackTrace(); } + ActivationLibrary.deactivate(this, getID()); + System.err.println("\tActivationLibrary.deactivate returned"); } - public static void main(String[] args) { - - Registry registry; - + public static void main(String[] args) throws RemoteException { System.err.println("\nRegression test for bug 4134233\n"); - TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); RMID rmid = null; + // Create registry and export callback object so they're + // available to the objects that are activated below. + // TODO: see if we can use RMID's registry instead of + // creating one here. + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); + Callback robj = new Callback(); + registry.rebind("Callback", robj); + try { RMID.removeLog(); rmid = RMID.createRMID(); @@ -149,8 +153,7 @@ TestParams.defaultGroupPolicy); p.put("java.security.manager", TestParams.defaultSecurityManager); - - //final int NUM_OBJECTS = 10; + p.put("unregisterGroup.port", Integer.toString(registryPort)); Thread t = new Thread() { public void run () { @@ -219,8 +222,6 @@ } else { System.err.println("Test passed"); } - - } catch (Exception e) { TestLibrary.bomb("test failed", e); } finally { @@ -233,12 +234,6 @@ // Wait for the object deactivation to take place first try { - - // create reg and export callback object - registry = LocateRegistry.createRegistry(PORT); - Callback robj = new Callback(); - registry.bind("Callback", robj); - //get the callback object int maxwait=30; int nd = robj.getNumDeactivated();
--- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -7,4 +7,5 @@ // test needs to communicate with the activation system permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; + permission java.util.PropertyPermission "unregisterGroup.port", "read"; };
--- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -1,4 +1,5 @@ grant { permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default"; permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*"; + permission com.sun.rmi.rmid.ExecOptionPermission "-DunregisterGroup.port=*"; };
--- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -21,15 +21,22 @@ permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; + + // required for test to get the registry port + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; };
--- a/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -53,31 +53,37 @@ public static void main(String argv[]) throws Exception { + int runningPort = TestLibrary.getUnusedRandomPort(); + System.out.println("java.compiler=" + System.getProperty("java.compiler")); // don't embed spaces in any of the test args/props, because // they won't be parsed properly - runwith (new String[0], new String[0]); + runwith (new String[0], new String[0], runningPort); runwith ( new String[] { "-verbosegc" }, new String[] { "foo.bar=SetChildEnvTest", - "sun.rmi.server.doSomething=true" } + "sun.rmi.server.doSomething=true" }, + runningPort ); runwith ( new String[] { }, - new String[] { "parameter.count=zero" } + new String[] { "parameter.count=zero" }, + runningPort ); runwith ( new String[] { "-Xmx32m" }, - new String[] { } + new String[] { }, + runningPort ); } private static void runwith( String[] params, // extra args - String[] props // extra system properties + String[] props, // extra system properties + int port // port on which to communicate ) throws Exception { @@ -89,7 +95,8 @@ RMID.removeLog(); RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(), - true); // debugExec turned on + true, // debugExec turned on + true, port); rmid.start(); @@ -195,7 +202,7 @@ actsys.unregisterGroup(gid); Thread.sleep(5000); - rmid.destroy(); + ActivationLibrary.rmidCleanup(rmid); } public static class DebugExecWatcher @@ -243,7 +250,19 @@ System.err.println(line); } } catch (IOException e) { - e.printStackTrace(); + /* During termination of distant rmid, StreamPipes will be broken when + * distant vm terminates. A "Pipe broken" exception is expected because + * DebugExecWatcher points to the same streams as StreamPipes used by RMID. + * If we get this exception. We just terminate the thread. + */ + if (e.getMessage().equals("Pipe broken")) { + try { + str.close(); + } catch (IOException ioe) {} + } + else { + e.printStackTrace(); + } } } }
--- a/test/java/rmi/activation/CommandEnvironment/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/CommandEnvironment/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -27,6 +27,7 @@ permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -31,8 +31,7 @@ * @library ../../testlibrary * @build RMID ActivationLibrary * @build InheritedChannelNotServerSocket - * @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 - * InheritedChannelNotServerSocket + * @run main/othervm/timeout=240 InheritedChannelNotServerSocket */ import java.io.IOException; @@ -55,8 +54,6 @@ import java.rmi.server.UnicastRemoteObject; public class InheritedChannelNotServerSocket { - - private static final int PORT = 5398; private static final Object lock = new Object(); private static boolean notified = false; @@ -79,7 +76,8 @@ public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 6261402\n"); - + System.setProperty("java.rmi.activation.port", + Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT)); RMID rmid = null; Callback obj = null; try { @@ -91,7 +89,8 @@ Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0); Registry registry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry( + TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); registry.bind("Callback", proxy); /* @@ -99,7 +98,8 @@ */ System.err.println("start rmid with inherited channel"); RMID.removeLog(); - rmid = RMID.createRMID(System.out, System.err, true, true, PORT); + rmid = RMID.createRMID(System.out, System.err, true, true, + TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT); rmid.addOptions(new String[]{ "-Djava.nio.channels.spi.SelectorProvider=" + "InheritedChannelNotServerSocket$SP"}); @@ -122,7 +122,7 @@ if (obj != null) { UnicastRemoteObject.unexportObject(obj, true); } - ActivationLibrary.rmidCleanup(rmid, PORT); + ActivationLibrary.rmidCleanup(rmid); } } @@ -175,7 +175,7 @@ try { System.err.println("notify test..."); Registry registry = - LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); Callback obj = (Callback) registry.lookup("Callback"); obj.notifyTest(); } catch (NotBoundException nbe) {
--- a/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java Thu Aug 30 21:02:16 2012 -0700 @@ -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 @@ -29,7 +29,8 @@ * @library ../../testlibrary * @build RMID ActivationLibrary * @build RmidViaInheritedChannel - * @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 RmidViaInheritedChannel + * @build TestLibrary + * @run main/othervm/timeout=240 RmidViaInheritedChannel */ import java.io.IOException; @@ -48,8 +49,6 @@ import java.rmi.server.UnicastRemoteObject; public class RmidViaInheritedChannel implements Callback { - - private static final int PORT = 5398; private static final Object lock = new Object(); private static boolean notified = false; @@ -64,7 +63,8 @@ } public static void main(String[] args) throws Exception { - + System.setProperty("java.rmi.activation.port", + Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT)); RMID rmid = null; Callback obj = null; @@ -77,7 +77,8 @@ Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0); Registry registry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry( + TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT); registry.bind("Callback", proxy); /* @@ -85,7 +86,8 @@ */ System.err.println("start rmid with inherited channel"); RMID.removeLog(); - rmid = RMID.createRMID(System.out, System.err, true, false, PORT); + rmid = RMID.createRMID(System.out, System.err, true, false, + TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT); rmid.addOptions(new String[]{ "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"}); rmid.start(); @@ -108,7 +110,7 @@ if (obj != null) { UnicastRemoteObject.unexportObject(obj, true); } - ActivationLibrary.rmidCleanup(rmid, PORT); + ActivationLibrary.rmidCleanup(rmid); } } @@ -166,7 +168,8 @@ channel = ServerSocketChannel.open(); ServerSocket serverSocket = channel.socket(); serverSocket.bind( - new InetSocketAddress(InetAddress.getLocalHost(), PORT)); + new InetSocketAddress(InetAddress.getLocalHost(), + TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT)); System.err.println("serverSocket = " + serverSocket); /* @@ -175,7 +178,7 @@ try { System.err.println("notify test..."); Registry registry = - LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT); Callback obj = (Callback) registry.lookup("Callback"); obj.notifyTest(); } catch (NotBoundException nbe) {
--- a/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -2,4 +2,5 @@ permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; permission java.net.SocketPermission "*", "connect,accept"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; };
--- a/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, 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 @@ -27,7 +27,7 @@ * @author Laird Dornin * * @library ../../testlibrary - * @build StreamPipe TestParams TestLibrary JavaVM + * @build StreamPipe TestParams TestLibrary JavaVM RMID * @build AltSecurityManager TestSecurityManager * @run main/othervm AltSecurityManager */ @@ -41,23 +41,41 @@ * if registry and rmid take too long to exit. */ public class AltSecurityManager implements Runnable { - + private final int regPort; // variable to hold registry and rmid children static JavaVM vm = null; // names of utilities static String utilityToStart = null; - static String registry = "sun.rmi.registry.RegistryImpl"; - static String rmid = "sun.rmi.server.Activation"; + static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl"; + static final String ACTIVATION = "sun.rmi.server.Activation"; // children should exit in at least this time. static long TIME_OUT = 15000; + public AltSecurityManager(int port) { + if (port <= 0) { + TestLibrary.bomb("Port must be greater then 0."); + } + + this.regPort = port; + } + public void run() { try { - vm = new JavaVM(utilityToStart, - " -Djava.security.manager=TestSecurityManager", - ""); + if (utilityToStart.equals(REGISTRY_IMPL)) { + vm = new JavaVM(utilityToStart, + " -Djava.security.manager=TestSecurityManager", + Integer.toString(regPort)); + } else if (utilityToStart.contains(ACTIVATION)) { + vm = new JavaVM(utilityToStart, + " -Djava.security.manager=TestSecurityManager", + "-port " + Integer.toString(regPort)); + } else { + TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL + + " or " + ACTIVATION); + } + System.err.println("starting " + utilityToStart); vm.start(); vm.getVM().waitFor(); @@ -75,7 +93,8 @@ utilityToStart = utility; try { - Thread thread = new Thread(new AltSecurityManager()); + int port = TestLibrary.getUnusedRandomPort(); + Thread thread = new Thread(new AltSecurityManager(port)); System.err.println("expecting RuntimeException for " + "checkListen in child process"); long start = System.currentTimeMillis(); @@ -90,8 +109,8 @@ // dont pollute other tests; increase the likelihood // that rmid will go away if it did not exit already. - if (utility.equals(rmid)) { - RMID.shutdown(); + if (utility.equals(ACTIVATION)) { + RMID.shutdown(port); } TestLibrary.bomb(utilityToStart + @@ -111,10 +130,10 @@ System.err.println("\nRegression test for bug 4183202\n"); // make sure the registry exits early. - ensureExit(registry); + ensureExit(REGISTRY_IMPL); // make sure rmid exits early - ensureExit(rmid); + ensureExit(ACTIVATION); System.err.println("test passed");
--- a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, 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 @@ -30,7 +30,7 @@ * @author Peter Jones * * @library ../../testlibrary - * @build ClassPathCodebase Dummy + * @build ClassPathCodebase Dummy TestLibrary * @run main/othervm/policy=security.policy ClassPathCodebase */ @@ -83,11 +83,12 @@ System.getProperty("java.home") + File.separator + "bin" + File.separator + "rmiregistry"; + int port = TestLibrary.getUnusedRandomPort(); String cmdarray[] = new String[] { rmiregistryCommand, "-J-Denv.class.path=.", "-J-Djava.rmi.server.codebase=" + exportCodebaseURL, - Integer.toString(TestLibrary.REGISTRY_PORT) }; + Integer.toString(port) }; System.err.println("\nCommand used to spawn rmiregistry process:"); System.err.println("\t" + Arrays.asList(cmdarray).toString()); @@ -118,7 +119,7 @@ * dummy object to it. */ Registry registry = LocateRegistry.getRegistry( - "localhost", TestLibrary.REGISTRY_PORT); + "localhost", port); try { registry.bind(dummyBinding, dummyObject); @@ -133,7 +134,7 @@ { System.err.println( "Error: another registry running on port " + - TestLibrary.REGISTRY_PORT + "?"); + port + "?"); } throw e; }
--- a/test/java/rmi/registry/emptyName/EmptyName.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/emptyName/EmptyName.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, 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 @@ -24,6 +24,8 @@ /* @test * @bug 4399304 * @summary check that registry allows empty names + * @library ../../testlibrary + * @build TestLibrary * @run main/othervm EmptyName */ import java.rmi.registry.LocateRegistry; @@ -32,7 +34,7 @@ public class EmptyName { public static void main(String[] args) throws Exception { - Registry impl = LocateRegistry.createRegistry(0); + Registry impl = TestLibrary.createRegistryOnUnusedPort(); Registry stub = (Registry) RemoteObject.toStub(impl); stub.bind("", stub); stub.lookup("");
--- a/test/java/rmi/registry/interfaceHash/InterfaceHash.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/interfaceHash/InterfaceHash.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -35,8 +35,10 @@ * "interface hash": 4905912898345647071L. * * @author Peter Jones + * @library ../../testlibrary * @build InterfaceHash * @build ReferenceRegistryStub + * @build TestLibrary * @run main/othervm InterfaceHash */ @@ -58,7 +60,7 @@ public class InterfaceHash { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final String NAME = "WMM"; public static void main(String[] args) throws Exception {
--- a/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, 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,8 @@ * @summary Can't run multiple registries in the same VM * @author Ann Wollrath * + * @library ../../testlibrary + * @build TestLibrary * @build MultipleRegistries * @run main/othervm/timeout=240 MultipleRegistries */ @@ -58,12 +60,13 @@ System.err.println("proxy = " + proxy); System.err.println("export registries"); - Registry registryImpl1 = LocateRegistry.createRegistry(2030); - Registry registryImpl2 = LocateRegistry.createRegistry(2040); - + Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort(); + int port1 = TestLibrary.getRegistryPort(registryImpl1); + Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort(); + int port2 = TestLibrary.getRegistryPort(registryImpl2); System.err.println("bind remote object in registries"); - Registry registry1 = LocateRegistry.getRegistry(2030); - Registry registry2 = LocateRegistry.getRegistry(2040); + Registry registry1 = LocateRegistry.getRegistry(port1); + Registry registry2 = LocateRegistry.getRegistry(port2); registry1.bind(NAME, proxy); registry2.bind(NAME, proxy);
--- a/test/java/rmi/registry/readTest/readTest.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/readTest/readTest.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -30,18 +30,19 @@ public class readTest { public static void main(String args[]) throws Exception { - int port = 7491; try { testPkg.Server obj = new testPkg.Server(); testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0); // Bind the remote object's stub in the registry - Registry registry = LocateRegistry.getRegistry(port); + Registry registry = + LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT); registry.bind("Hello", stub); System.err.println("Server ready"); // now, let's test client - testPkg.Client client = new testPkg.Client(port); + testPkg.Client client = + new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT); String testStubReturn = client.testStub(); if(!testStubReturn.equals(obj.hello)) { throw new RuntimeException("Test Fails : unexpected string from stub call");
--- a/test/java/rmi/registry/readTest/readTest.sh Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/readTest/readTest.sh Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 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,6 +23,8 @@ # @test # @bug 7102369 7094468 7100592 +# @library ../../testlibrary +# @build TestLibrary # @summary remove java.rmi.server.codebase property parsing from registyimpl # @run shell readTest.sh @@ -44,22 +46,24 @@ ;; esac +TEST_CLASSPATH=.:$TESTCLASSES cp -r ${TESTSRC}${FS}* . ${TESTJAVA}${FS}bin${FS}javac testPkg${FS}*java -${TESTJAVA}${FS}bin${FS}javac readTest.java +${TESTJAVA}${FS}bin${FS}javac -cp $TEST_CLASSPATH readTest.java mkdir rmi_tmp RMIREG_OUT=rmi.out #start rmiregistry without any local classes on classpath cd rmi_tmp -${TESTJAVA}${FS}bin${FS}rmiregistry 7491 > ..${FS}${RMIREG_OUT} 2>&1 & +# NOTE: This RMI Registry port must match TestLibrary.READTEST_REGISTRY_PORT +${TESTJAVA}${FS}bin${FS}rmiregistry 64005 > ..${FS}${RMIREG_OUT} 2>&1 & RMIREG_PID=$! # allow some time to start sleep 3 cd .. # trailing / after code base is important for rmi codebase property. -${TESTJAVA}${FS}bin${FS}java -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 & +${TESTJAVA}${FS}bin${FS}java -cp $TEST_CLASSPATH -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 & TEST_PID=$! #bulk of testcase - let it run for a while sleep 5
--- a/test/java/rmi/registry/reexport/Reexport.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/registry/reexport/Reexport.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, 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 @@ -49,22 +49,21 @@ import java.rmi.server.*; public class Reexport { - static public final int regport = TestLibrary.REGISTRY_PORT; - static public void main(String[] argv) { Registry reg = null; + int regPort = TestLibrary.getUnusedRandomPort(); try { System.err.println("\nregression test for 4120329\n"); // establish the registry (we hope) - System.err.println("Starting registry on port " + regport); - Reexport.makeRegistry(regport); + System.err.println("Starting registry on port " + regPort); + Reexport.makeRegistry(regPort); // Get a handle to the registry System.err.println("Creating duplicate registry, this should fail..."); - reg = createReg(true); + reg = createReg(true, regPort); if (reg != null) { TestLibrary.bomb("failed was able to duplicate the registry?!?"); @@ -73,7 +72,7 @@ // Kill the first registry. System.err.println("Bringing down the first registry"); try { - Reexport.killRegistry(); + Reexport.killRegistry(regPort); } catch (Exception foo) { } @@ -81,7 +80,7 @@ System.err.println("Trying again to start our own " + "registry... this should work"); - reg = createReg(false); + reg = createReg(false, regPort); if (reg == null) { TestLibrary.bomb("Could not create registry on second try"); @@ -93,17 +92,17 @@ TestLibrary.bomb(e); } finally { // dont leave the registry around to affect other tests. - killRegistry(); + killRegistry(regPort); reg = null; } } - static Registry createReg(boolean remoteOk) { + static Registry createReg(boolean remoteOk, int port) { Registry reg = null; try { - reg = LocateRegistry.createRegistry(regport); + reg = LocateRegistry.createRegistry(port); } catch (Throwable e) { if (remoteOk) { System.err.println("EXPECTING PORT IN USE EXCEPTION:"); @@ -140,10 +139,10 @@ } private static Process subreg = null; - public static void killRegistry() { + public static void killRegistry(int port) { if (Reexport.subreg != null) { - RegistryRunner.requestExit(); + RegistryRunner.requestExit(port); try { Reexport.subreg.waitFor();
--- a/test/java/rmi/reliability/juicer/AppleUserImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/reliability/juicer/AppleUserImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, 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 @@ -59,19 +59,21 @@ * @build Apple AppleEvent AppleImpl AppleUserImpl * @build Orange OrangeEcho OrangeEchoImpl OrangeImpl * @build ApplicationServer + * @build TestLibrary * * @run main/othervm/policy=security.policy AppleUserImpl -seconds 30 * * @author Peter Jones, Nigel Daley */ +import java.rmi.NoSuchObjectException; import java.rmi.RemoteException; -import java.rmi.NoSuchObjectException; -import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; import java.util.Random; +import java.util.logging.Level; import java.util.logging.Logger; -import java.util.logging.Level; /** * The AppleUserImpl class implements the behavior of the remote @@ -80,7 +82,7 @@ * AppleUserThread is created for each apple. */ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { - + private static int registryPort = -1; private static final Logger logger = Logger.getLogger("reliability.appleuser"); private static int threadNum = 0; @@ -308,8 +310,10 @@ synchronized (user) { // create new registry and bind new AppleUserImpl in registry - LocateRegistry.createRegistry(2006); - LocateRegistry.getRegistry(2006).rebind("AppleUser",user); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); + LocateRegistry.getRegistry(registryPort).rebind("AppleUser", + user); // start the other server if applicable if (othervm) { @@ -318,7 +322,9 @@ "started in separate process"); } else { Class app = Class.forName("ApplicationServer"); - server = new Thread((Runnable) app.newInstance()); + java.lang.reflect.Constructor appConstructor = + app.getDeclaredConstructor(new Class[] {Integer.TYPE}); + server = new Thread((Runnable) appConstructor.newInstance(registryPort)); logger.log(Level.INFO, "Starting application server " + "in same process"); server.start();
--- a/test/java/rmi/reliability/juicer/ApplicationServer.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/reliability/juicer/ApplicationServer.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, 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 @@ -38,18 +38,21 @@ private static final int LOOKUP_ATTEMPTS = 5; private static final int DEFAULT_NUMAPPLES = 10; private static final String DEFAULT_REGISTRYHOST = "localhost"; + private static final int DEFAULT_REGISTRYPORT = -1; private final int numApples; private final String registryHost; + private final int registryPort; private final Apple[] apples; private AppleUser user; - ApplicationServer() { - this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST); + ApplicationServer(int registryPort) { + this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST, registryPort); } - ApplicationServer(int numApples, String registryHost) { + ApplicationServer(int numApples, String registryHost, int registryPort) { this.numApples = numApples; this.registryHost = registryHost; + this.registryPort = registryPort; apples = new Apple[numApples]; } @@ -71,7 +74,7 @@ for (i = 0; i < LOOKUP_ATTEMPTS; i++) { try { Registry registry = LocateRegistry.getRegistry( - registryHost, 2006); + registryHost, registryPort); user = (AppleUser) registry.lookup("AppleUser"); user.startTest(); break; //successfully obtained AppleUser @@ -120,16 +123,20 @@ private static void usage() { System.err.println("Usage: ApplicationServer [-numApples <numApples>]"); System.err.println(" [-registryHost <host>]"); + System.err.println(" -registryPort <port>"); System.err.println(" numApples The number of apples (threads) to use."); System.err.println(" The default is 10 apples."); System.err.println(" host The host running rmiregistry " + "which contains AppleUser."); System.err.println(" The default is \"localhost\"."); + System.err.println(" port The port the rmiregistry is running" + + "on."); System.err.println(); } public static void main(String[] args) { int num = DEFAULT_NUMAPPLES; + int port = -1; String host = DEFAULT_REGISTRYHOST; // parse command line args @@ -142,17 +149,25 @@ } else if (arg.equals("-registryHost")) { i++; host = args[i]; + } else if (arg.equals("-registryPort")) { + i++; + port = Integer.parseInt(args[i]); } else { usage(); } } + + if (port == -1) { + usage(); + throw new RuntimeException("Port must be specified."); + } } catch (Throwable t) { usage(); throw new RuntimeException("TEST FAILED: Bad argument"); } // start the client server - Thread server = new Thread(new ApplicationServer(num,host)); + Thread server = new Thread(new ApplicationServer(num,host,port)); server.start(); // main should exit once all exported remote objects are gc'd }
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -128,8 +128,9 @@ ActivationGroup.createGroup(groupID, groupDesc, 0); EchoImpl impl = new EchoImpl(protocol); - System.out.println("EchoServer: binding in registry"); - Naming.rebind("//:" + UseCustomSocketFactory.REGISTRY_PORT + + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); + System.out.println("EchoServer: binding in registry on port:" + registryPort); + Naming.rebind("//:" + registryPort + "/EchoServer", impl); System.out.println("EchoServer ready."); } catch (Exception e) {
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,6 +32,7 @@ * @build EchoImpl * @build EchoImpl_Stub * @build UseCustomSocketFactory + * @build TestLibrary * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory */ @@ -42,8 +43,8 @@ import java.rmi.registry.*; public class UseCustomSocketFactory { + static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); - final static int REGISTRY_PORT = 2006; static String[] protocol = new String[] { "", "compress", "xor" }; public static void main(String[] args) { @@ -68,7 +69,7 @@ " -C-Djava.security.manager=java.rmi.RMISecurityManager "}); rmid.start(); - Echo[] echo = spawnAndTest(); + Echo[] echo = spawnAndTest(rmid.getPort()); reactivateAndTest(echo); } catch (IOException e) { TestLibrary.bomb("creating rmid", e); @@ -78,17 +79,20 @@ } } - private static Echo[] spawnAndTest() { + private static Echo[] spawnAndTest(int rmidPort) { System.err.println("\nCreate Test-->"); Echo[] echo = new Echo[protocol.length]; for (int i = 0; i < protocol.length; i++) { - JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + REGISTRY_PORT + + " -Djava.rmi.activation.port=" + + rmidPort, protocol[i]); System.err.println("\nusing protocol: " +
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -30,6 +30,9 @@ permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; + // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory";
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -65,8 +65,9 @@ if (args.length >= 1) protocol = args[0]; + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); registry = java.rmi.registry.LocateRegistry. - getRegistry("localhost", TestLibrary.REGISTRY_PORT, + getRegistry("localhost", registryPort, new Compress.CompressRMIClientSocketFactory()); UseCustomSocketFactory.checkStub(registry, "RMIClientSocket"); hello = (Hello) registry.lookup("/HelloServer");
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,6 +32,7 @@ * @build Hello * @build HelloImpl * @build HelloImpl_Stub + * @build TestLibrary * @build UseCustomSocketFactory * @build Compress * @run main/othervm/policy=security.policy/timeout=240 UseCustomSocketFactory @@ -58,6 +59,7 @@ System.out.println("\nRegression test for bug 4148850\n"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); + int registryPort = TestLibrary.getUnusedRandomPort(); try { impl = new HelloImpl(); @@ -67,7 +69,7 @@ * allow the rmiregistry to be secure. */ registry = LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT, + createRegistry(registryPort, new Compress.CompressRMIClientSocketFactory(), new Compress.CompressRMIServerSocketFactory()); registry.rebind("/HelloServer", impl); @@ -77,8 +79,12 @@ TestLibrary.bomb("creating registry", e); } - JavaVM serverVM = new JavaVM("HelloImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, ""); + JavaVM serverVM = new JavaVM("HelloImpl", + "-Djava.security.policy=" + + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, + ""); try {
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -22,6 +22,8 @@ permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -64,8 +64,9 @@ System.out.println("EchoServer: creating remote object"); EchoImpl impl = new EchoImpl(protocol); + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); System.out.println("EchoServer: binding in registry"); - Naming.rebind("//:" + TestLibrary.REGISTRY_PORT + + Naming.rebind("//:" + registryPort + "/EchoServer", impl); System.out.println("EchoServer ready."); } catch (Exception e) {
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -46,6 +46,8 @@ public static void main(String[] args) { + int registryPort = -1; + String[] protocol = new String[] { "", "compress", "xor" }; System.out.println("\nRegression test for bug 4127826\n"); @@ -53,7 +55,8 @@ TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); try { - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); } catch (Exception e) { TestLibrary.bomb("creating registry", e); } @@ -65,7 +68,9 @@ JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, protocol[i]); System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i])); @@ -79,7 +84,7 @@ Echo obj = null; do { try { - obj = (Echo) Naming.lookup("//:" + TestLibrary.REGISTRY_PORT + + obj = (Echo) Naming.lookup("//:" + registryPort + "/EchoServer"); break; } catch (NotBoundException e) { @@ -109,7 +114,7 @@ } finally { serverVM.destroy(); try { - Naming.unbind("//:" + TestLibrary.REGISTRY_PORT + + Naming.unbind("//:" + registryPort + "/EchoServer"); } catch (Exception e) { TestLibrary.bomb("unbinding EchoServer", e);
--- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -22,9 +22,18 @@ permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; + // used by TestLibrary to get the RMI Registry port + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; + // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; };
--- a/test/java/rmi/server/RemoteServer/AddrInUse.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/RemoteServer/AddrInUse.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ * @summary retryServerSocket should not retry on BindException * @author Ann Wollrath * + * @library ../../testlibrary * @build AddrInUse * @run main/othervm AddrInUse */ @@ -36,7 +37,7 @@ public class AddrInUse implements Runnable { - private static final int PORT = 9999; + private static int port = -1; private static final long TIMEOUT = 10000; private boolean exportSucceeded = false; @@ -49,7 +50,7 @@ * has already been bound, and record the result. */ try { - LocateRegistry.createRegistry(PORT); + LocateRegistry.createRegistry(port); synchronized (this) { exportSucceeded = true; notifyAll(); @@ -68,8 +69,9 @@ /* * Bind a server socket to a port. */ - System.err.println("create a ServerSocket on port " + PORT + "..."); - ServerSocket server = new ServerSocket(PORT); + ServerSocket server = new ServerSocket(0); + port = server.getLocalPort(); + System.err.println("Created a ServerSocket on port " + port + "..."); /* * Start a thread that creates a registry on the same port,
--- a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -82,15 +82,17 @@ UnicastRemoteObject.exportObject(obj); System.err.println("exported shutdown monitor"); - Registry localRegistry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry localRegistry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(localRegistry); System.err.println("created local registry"); localRegistry.bind(BINDING, obj); System.err.println("bound shutdown monitor in local registry"); System.err.println("starting remote ShutdownImpl VM..."); - (new JavaVM("ShutdownImpl")).start(); + (new JavaVM("ShutdownImpl", + "-Drmi.registry.port=" + + registryPort, "")).start(); Shutdown s; synchronized (obj.lock) {
--- a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -68,8 +68,9 @@ public static void main(String[] args) { try { + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = - LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry("", registryPort); ShutdownMonitor monitor = (ShutdownMonitor) registry.lookup(KeepAliveDuringCall.BINDING); System.err.println("(ShutdownImpl) retrieved shutdown monitor");
--- a/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, 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 @@ -28,8 +28,10 @@ * * @author Ann Wollrath * + * @library ../../../testlibrary * @build UnexportLeak * @build UnexportLeak_Stub + * @build TestLibrary * @build Ping * @run main/othervm UnexportLeak */ @@ -40,20 +42,18 @@ import java.rmi.registry.*; public class UnexportLeak implements Ping { - - private static int PORT = 2006; - public void ping() { } public static void main(String[] args) { try { System.err.println("\nRegression test for bug 4331349\n"); - LocateRegistry.createRegistry(PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); Remote obj = new UnexportLeak(); WeakReference wr = new WeakReference(obj); UnicastRemoteObject.exportObject(obj); - LocateRegistry.getRegistry(PORT).rebind("UnexportLeak", obj); + LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj); UnicastRemoteObject.unexportObject(obj, true); obj = null; flushRefs();
--- a/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,7 @@ * @library ../../../testlibrary * @build FiniteGCLatency * @build FiniteGCLatency_Stub + * @build TestLibrary * @run main/othervm/timeout=120 FiniteGCLatency */ @@ -78,11 +79,11 @@ try { UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); - - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry1 = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry1); System.err.println("created registry"); - Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + Registry registry = LocateRegistry.getRegistry("", port); registry.bind(BINDING, obj); System.err.println("bound remote object in registry");
--- a/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -87,8 +87,9 @@ UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); + int registryPort = TestLibrary.getUnusedRandomPort(); Registry localRegistry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry(registryPort); System.err.println("created local registry"); localRegistry.bind(BINDING, obj); @@ -96,7 +97,8 @@ synchronized (obj.lock) { System.err.println("starting remote client VM..."); - (new JavaVM("SelfTerminator")).start(); + (new JavaVM("SelfTerminator", "-Drmi.registry.port=" + + registryPort, "")).start(); System.err.println("waiting for unreferenced() callback..."); obj.lock.wait(TIMEOUT);
--- a/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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,8 +33,10 @@ public static void main(String[] args) { try { + int registryPort = + Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = - LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry("", registryPort); Remote stub = registry.lookup(LeaseCheckInterval.BINDING); Runtime.getRuntime().halt(0); } catch (Exception e) {
--- a/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -41,6 +41,7 @@ * @library ../../../testlibrary * @build UnreferencedContext * @build UnreferencedContext_Stub + * @build TestLibrary * @run main/othervm/timeout=120 UnreferencedContext */ @@ -119,10 +120,11 @@ UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry1 = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry1); System.err.println("created registry"); - Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + Registry registry = LocateRegistry.getRegistry("", port); registry.bind(BINDING, obj); System.err.println("bound remote object in registry");
--- a/test/java/rmi/server/useCustomRef/UseCustomRef.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/useCustomRef/UseCustomRef.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -35,6 +35,7 @@ * @build Ping * @build UseCustomRef_Stub * @build UseCustomRef_Skel + * @build TestLibrary * @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef * * This test was failing to run because the synthetic access @@ -84,8 +85,9 @@ TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); System.err.println("creating Registry..."); - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry); /* * create object with custom ref and bind in registry */ @@ -97,7 +99,7 @@ "instanceof CustomServerRef"); } - String name = "//:" + TestLibrary.REGISTRY_PORT + "/UseCustomRef"; + String name = "//:" + port + "/UseCustomRef"; // String name = "UseCustomRef"; System.err.println("binding object in registry..."); Naming.rebind(name, cr);
--- a/test/java/rmi/server/useCustomRef/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/server/useCustomRef/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -8,8 +8,11 @@ grant { // the test uses a class in the package sun.rmi.server + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; permission java.util.PropertyPermission "package.restrict.access.sun", "read"; permission java.util.PropertyPermission "package.restrict.access.sun.rmi", "read";
--- a/test/java/rmi/testlibrary/ActivationLibrary.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/testlibrary/ActivationLibrary.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -134,37 +134,10 @@ return false; } - /** - * Check to see if an arry of Strings contains a given string. - */ - private static boolean - containsString(String[] strings, String contained) - { - if (strings == null) { - if (contained == null) { - return true; - } - return false; - } - - for (int i = 0 ; i < strings.length ; i ++ ) { - if ((strings[i] != null) && - (strings[i].indexOf(contained) >= 0)) - { - return true; - } - } - return false; - } - /** cleanup after rmid */ public static void rmidCleanup(RMID rmid) { - rmidCleanup(rmid, TestLibrary.RMID_PORT); - } - - public static void rmidCleanup(RMID rmid, int port) { if (rmid != null) { - if (!ActivationLibrary.safeDestroy(rmid, port, SAFE_WAIT_TIME)) { + if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) { TestLibrary.bomb("rmid not destroyed in: " + SAFE_WAIT_TIME + " milliseconds"); @@ -180,8 +153,8 @@ * @return whether or not shutdown completed succesfully in the * timeAllowed */ - private static boolean safeDestroy(RMID rmid, int port, long timeAllowed) { - DestroyThread destroyThread = new DestroyThread(rmid, port); + private static boolean safeDestroy(RMID rmid, long timeAllowed) { + DestroyThread destroyThread = new DestroyThread(rmid); destroyThread.start(); try { @@ -201,9 +174,9 @@ private final int port; private boolean succeeded = false; - DestroyThread(RMID rmid, int port) { + DestroyThread(RMID rmid) { this.rmid = rmid; - this.port = port; + this.port = rmid.getPort(); this.setDaemon(true); }
--- a/test/java/rmi/testlibrary/RMID.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/testlibrary/RMID.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,7 +28,6 @@ import java.io.*; import java.rmi.*; import java.rmi.activation.*; -import java.util.Properties; /** * Utility class that creates an instance of rmid with a policy @@ -133,7 +132,7 @@ boolean debugExec) { return createRMID(out, err, debugExec, true, - TestLibrary.RMID_PORT); + TestLibrary.getUnusedRandomPort()); } public static RMID createRMID(OutputStream out, OutputStream err, @@ -208,7 +207,7 @@ // if rmid is already running, then the test will fail with // a well recognized exception (port already in use...). - mesg("starting rmid..."); + mesg("starting rmid on port #" + port + "..."); super.start(); int slopFactor = 1; @@ -229,6 +228,14 @@ // is rmid present? if (ActivationLibrary.rmidRunning(port)) { + /** + * We need to set the java.rmi.activation.port value as the + * activation system will use the property to determine the + * port #. The activation system will use this value if set. + * If it isn't set, the activation system will set it to an + * incorrect value. + */ + System.setProperty("java.rmi.activation.port", Integer.toString(port)); mesg("finished starting rmid."); return; } @@ -249,10 +256,6 @@ * Shutdown does not nullify possible references to the rmid * process object (destroy does though). */ - public static void shutdown() { - shutdown(TestLibrary.RMID_PORT); - } - public static void shutdown(int port) { try { @@ -294,9 +297,7 @@ * if rmid is a child process of the current VM. */ public void destroy() { - - // attempt graceful shutdown of the activation system on - // TestLibrary.RMID_PORT + // attempt graceful shutdown of the activation system shutdown(port); if (vm != null) { @@ -321,4 +322,6 @@ vm = null; } } + + public int getPort() {return port;} }
--- a/test/java/rmi/testlibrary/RegistryRunner.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/testlibrary/RegistryRunner.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 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 @@ -56,12 +56,13 @@ * Request that the registry process exit and handle * related exceptions. */ - public static void requestExit() { + public static void requestExit(int port) { + try { RemoteExiter exiter = (RemoteExiter) Naming.lookup("rmi://localhost:" + - TestLibrary.REGISTRY_PORT + + port + "/RemoteExiter"); try { exiter.exit(); @@ -84,7 +85,7 @@ System.err.println("Usage: <port>"); System.exit(0); } - int port = TestLibrary.REGISTRY_PORT; + int port = -1; try { port = Integer.parseInt(args[0]); } catch (NumberFormatException nfe) {
--- a/test/java/rmi/testlibrary/StreamPipe.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/testlibrary/StreamPipe.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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
--- a/test/java/rmi/testlibrary/TestLibrary.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/testlibrary/TestLibrary.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,37 +36,62 @@ * not make use of packages. */ +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintStream; -import java.net.URL; import java.net.MalformedURLException; -import java.rmi.activation.Activatable; -import java.rmi.activation.ActivationID; +import java.net.ServerSocket; +import java.net.URL; import java.rmi.NoSuchObjectException; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; -import java.rmi.Remote; +import java.rmi.server.RemoteRef; import java.rmi.server.UnicastRemoteObject; import java.util.Enumeration; -import java.util.Hashtable; import java.util.Properties; -import java.io.ByteArrayOutputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; +import sun.rmi.registry.RegistryImpl; +import sun.rmi.server.UnicastServerRef; +import sun.rmi.transport.Endpoint; +import sun.rmi.transport.LiveRef; +import sun.rmi.transport.tcp.TCPEndpoint; /** * Class of utility/library methods (i.e. procedures) that assist with * the writing and maintainance of rmi regression tests. */ public class TestLibrary { - - /** standard test port number for registry */ - public final static int REGISTRY_PORT = 2006; - /** port for rmid necessary: not used to actually start rmid */ - public final static int RMID_PORT = 1098; + /** + * IMPORTANT! + * + * RMI tests are run concurrently and port conflicts result when a single + * port number is used by multiple tests. When needing a port, use + * getUnusedRandomPort() wherever possible. If getUnusedRandomPort() cannot + * be used, reserve and specify a port to use for your test here. This + * will ensure there are no port conflicts amongst the RMI tests. The + * port numbers specified here may also be specified in the respective + * tests. Do not change the reserved port numbers here without also + * changing the port numbers in the respective tests. + * + * When needing an instance of the RMIRegistry, use + * createRegistryOnUnusedPort wherever possible to prevent port conflicts. + * + * Reserved port range: FIXED_PORT_MIN to FIXED_PORT_MAX (inclusive) for + * tests which cannot use a random port. If new fixed ports are added below + * FIXED_PORT_MIN or above FIXED_PORT_MAX, then adjust + * FIXED_PORT_MIN/MAX appropriately. + */ + public final static int FIXED_PORT_MIN = 64001; + public final static int FIXED_PORT_MAX = 64010; + public final static int RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT = 64001; + public final static int RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT = 64002; + public final static int INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT = 64003; + public final static int INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT = 64004; + public final static int READTEST_REGISTRY_PORT = 64005; static void mesg(Object mesg) { System.err.println("TEST_LIBRARY: " + mesg.toString()); @@ -340,6 +365,83 @@ } /** + * Creates an RMI {@link Registry} on a random, un-reserved port. + * + * @returns an RMI Registry, using a random port. + * @throws RemoteException if there was a problem creating a Registry. + */ + public static Registry createRegistryOnUnusedPort() throws RemoteException { + return LocateRegistry.createRegistry(getUnusedRandomPort()); + } + + /** + * Returns the port number the RMI {@link Registry} is running on. + * + * @param registry the registry to find the port of. + * @return the port number the registry is using. + * @throws RuntimeException if there was a problem getting the port number. + */ + public static int getRegistryPort(Registry registry) { + int port = -1; + + try { + RemoteRef remoteRef = ((RegistryImpl)registry).getRef(); + LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef(); + Endpoint endpoint = liveRef.getChannel().getEndpoint(); + TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint; + port = tcpEndpoint.getPort(); + } catch (Exception ex) { + throw new RuntimeException("Error getting registry port.", ex); + } + + return port; + } + + /** + * Returns an unused random port number which is not a reserved port. Will + * try up to 10 times to get a random port before giving up and throwing a + * RuntimeException. + * + * @return an unused random port number. + * @throws RuntimeException if there was a problem getting a port. + */ + public static int getUnusedRandomPort() { + int numTries = 0; + int unusedRandomPort = FIXED_PORT_MIN; + Exception ex = null; + + while (numTries++ < 10) { + ex = null; //reset + + try (ServerSocket ss = new ServerSocket(0)) { + unusedRandomPort = ss.getLocalPort(); + } catch (Exception e) { + ex = e; + } + + if (!isReservedPort(unusedRandomPort)) { + return unusedRandomPort; + } + } + + // If we're here, then either an exception was thrown or the port is + // a reserved port. + throw new RuntimeException("Error getting unused random port.", ex); + } + + /** + * Determines if a port is one of the reserved port numbers. + * + * @param port the port to test. + * @return {@code true} if the port is a reserved port, otherwise + * {@code false}. + */ + public static boolean isReservedPort(int port) { + return ((port >= FIXED_PORT_MIN) && (port <= FIXED_PORT_MAX) || + (port == 1099)); + } + + /** * Method to capture the stack trace of an exception and return it * as a string. */
--- a/test/java/rmi/transport/checkFQDN/CheckFQDN.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/checkFQDN/CheckFQDN.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,7 @@ * * @library ../../testlibrary * @build CheckFQDN CheckFQDNClient CheckFQDN_Stub TellServerName + * @build TestLibrary * @run main/othervm/timeout=120 CheckFQDN */ @@ -63,7 +64,7 @@ */ public class CheckFQDN extends UnicastRemoteObject implements TellServerName { - + public static int REGISTRY_PORT =-1; static String propertyBeingTested = null; static String propertyBeingTestedValue = null; @@ -77,8 +78,8 @@ System.err.println ("\nRegression test for bug/rfe 4115683\n"); - Registry registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + REGISTRY_PORT = TestLibrary.getRegistryPort(registry); registry.bind("CheckFQDN", checkFQDN); /* test the host name scheme in different environments.*/ @@ -117,7 +118,9 @@ JavaVM jvm = new JavaVM("CheckFQDNClient", propOption + property + equal + - propertyValue + extraProp, + propertyValue + extraProp + + " -Drmi.registry.port=" + + REGISTRY_PORT, ""); propertyBeingTested=property;
--- a/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,8 +58,9 @@ System.err.println("Client host name: " + hostname); + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); tell = (TellServerName) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + registryPort + "/CheckFQDN"); tell.tellServerName(hostname); System.err.println("client has exited");
--- a/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,7 @@ * * @library ../../testlibrary * @build CheckLeaseLeak CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak + * @build TestLibrary * @run main/othervm/timeout=240 CheckLeaseLeak * */ @@ -57,7 +58,6 @@ import java.rmi.registry.*; public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { - public CheckLeaseLeak() throws RemoteException { } public void ping () throws RemoteException { } @@ -87,8 +87,8 @@ try { Registry registry = - java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); leakServer = new CheckLeaseLeak(); registry.rebind("/LeaseLeak", leakServer); @@ -99,7 +99,10 @@ JavaVM jvm = new JavaVM("LeaseLeakClient", " -Djava.security.policy=" + - TestParams.defaultPolicy, ""); + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, + ""); jvm.start(); if (jvm.getVM().waitFor() == 1 ) {
--- a/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,11 +31,11 @@ try { LeaseLeak leaseLeak = null; + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); // put a reference on a remote object. Registry registry = - java.rmi.registry.LocateRegistry.getRegistry( - TestLibrary.REGISTRY_PORT); + java.rmi.registry.LocateRegistry.getRegistry(registryPort); leaseLeak = (LeaseLeak) registry.lookup("/LeaseLeak"); leaseLeak.ping();
--- a/test/java/rmi/transport/checkLeaseInfoLeak/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/checkLeaseInfoLeak/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -19,6 +19,7 @@ permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read";
--- a/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, 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 @@ -30,7 +30,8 @@ * the local port is released). * @author Peter Jones * - * @build CloseServerSocket + * @library ../../testlibrary + * @build CloseServerSocket TestLibrary * @run main/othervm CloseServerSocket */ @@ -44,8 +45,7 @@ import java.rmi.server.UnicastRemoteObject; public class CloseServerSocket implements Remote { - - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private CloseServerSocket() { } @@ -88,7 +88,7 @@ } private static void verifyPortFree(int port) throws IOException { - ServerSocket ss = new ServerSocket(PORT); + ServerSocket ss = new ServerSocket(port); ss.close(); System.err.println("- port " + port + " is free"); }
--- a/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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,6 +32,7 @@ * @build Test * @build TestImpl * @build TestImpl_Stub + * @build TestLibrary * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock */ @@ -53,7 +54,7 @@ import java.io.*; public class DGCDeadLock implements Runnable { - + private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); final static public int HOLD_TARGET_TIME = 25000; public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; public static boolean finished = false; @@ -75,7 +76,9 @@ TestParams.defaultPolicy + " -Djava.rmi.dgc.leaseValue=500000" + " -Dsun.rmi.dgc.checkInterval=" + - (HOLD_TARGET_TIME - 5000) + ""; + (HOLD_TARGET_TIME - 5000) + + " -Drmi.registry.port=" + REGISTRY_PORT + + "" ; testImplVM = new JavaVM("TestImpl", options, ""); testImplVM.start(); @@ -112,7 +115,7 @@ // create a test client Test foo = (Test) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + + REGISTRY_PORT + "/Foo"); echo = foo.echo("Hello world"); System.err.println("Test object created."); @@ -131,7 +134,7 @@ //import "Bar" Test bar = (Test) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + + REGISTRY_PORT + "/Bar"); /* infinite loop to show the liveness of Client,
--- a/test/java/rmi/transport/dgcDeadLock/TestImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/dgcDeadLock/TestImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,7 +36,6 @@ public class TestImpl extends UnicastRemoteObject implements Test { - static Thread locker = null; static TestImpl foo = null; static TestImpl bar = null; @@ -57,20 +56,21 @@ Registry registry = null; try { + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + createRegistry(registryPort); //export "Foo" foo = new TestImpl(); Naming.rebind("rmi://:" + - TestLibrary.REGISTRY_PORT + registryPort + "/Foo", foo); try { //export "Bar" after leases have been expired. bar = new TestImpl(); Naming.rebind("rmi://localhost:" + - TestLibrary.REGISTRY_PORT + registryPort + "/Bar", bar); } catch (Exception e) { throw new RemoteException(e.getMessage());
--- a/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -30,7 +30,8 @@ * java.rmi.ConnectException or ConnectIOException, not a MarshalException. * @author Peter Jones * - * @build HandshakeFailure + * @library ../../testlibrary + * @build HandshakeFailure TestLibrary * @run main/othervm HandshakeFailure */ @@ -44,7 +45,7 @@ public class HandshakeFailure { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int TIMEOUT = 10000; public static void main(String[] args) throws Exception {
--- a/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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,7 +33,8 @@ * this point (because no data for the invocation has yet been written). * @author Peter Jones * - * @build HandshakeTimeout + * @library ../../testlibrary + * @build HandshakeTimeout TestLibrary * @run main/othervm HandshakeTimeout */ @@ -46,7 +47,7 @@ public class HandshakeTimeout { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int TIMEOUT = 10000; public static void main(String[] args) throws Exception {
--- a/test/java/rmi/transport/httpSocket/HttpSocketTest.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/httpSocket/HttpSocketTest.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, 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 @@ -27,7 +27,7 @@ * @author Dana Burns * * @library ../../testlibrary - * @build HttpSocketTest HttpSocketTest_Stub + * @build HttpSocketTest HttpSocketTest_Stub TestLibrary * @run main/othervm/policy=security.policy HttpSocketTest */ @@ -56,10 +56,7 @@ public class HttpSocketTest extends UnicastRemoteObject implements MyRemoteInterface { - private static final String NAME = "HttpSocketTest"; - private static final String REGNAME = - "//:" + TestLibrary.REGISTRY_PORT + "/" + NAME; public HttpSocketTest() throws RemoteException{} @@ -76,21 +73,20 @@ // Set the socket factory. System.err.println("installing socket factory"); RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory()); + int registryPort = -1; try { - System.err.println("Starting registry"); - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); - + registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); } catch (Exception e) { TestLibrary.bomb(e); } try { - registry.rebind( NAME, new HttpSocketTest() ); MyRemoteInterface httpTest = - (MyRemoteInterface)Naming.lookup( REGNAME ); + (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME); httpTest.setRemoteObject( new HttpSocketTest() ); Remote r = httpTest.getRemoteObject();
--- a/test/java/rmi/transport/httpSocket/security.policy Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/httpSocket/security.policy Thu Aug 30 21:02:16 2012 -0700 @@ -4,6 +4,10 @@ grant { permission java.net.SocketPermission "*:1024-", "accept,connect,listen"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; permission java.lang.RuntimePermission "setFactory"; };
--- a/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, 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 @@ -31,6 +31,8 @@ * should become unreachable too (through the RMI implementation). * @author Peter Jones * + * @library ../../testlibrary + * @build TestLibrary * @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000 * PinClientSocketFactory */ @@ -56,7 +58,7 @@ public class PinClientSocketFactory { - private static final int PORT = 2345; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int SESSIONS = 50; public interface Factory extends Remote {
--- a/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, 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 @@ -31,7 +31,8 @@ * procedure (which sleeps 10 seconds after 10 rapid failures). * @author Peter Jones * - * @build RapidExportUnexport + * @library ../../testlibrary + * @build TestLibrary RapidExportUnexport * @run main/othervm RapidExportUnexport */ @@ -39,9 +40,7 @@ import java.rmi.server.UnicastRemoteObject; public class RapidExportUnexport { - - private static final int PORT = 2055; - + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int REPS = 100; private static final long TIMEOUT = 60000;
--- a/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, 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 @@ -33,7 +33,8 @@ * continue to work because existing applications might depend on it. * @author Peter Jones * - * @build ReuseDefaultPort + * @library ../../testlibrary + * @build ReuseDefaultPort TestLibrary * @run main/othervm ReuseDefaultPort */ @@ -48,7 +49,7 @@ public class ReuseDefaultPort implements Remote { - private static final int PORT = 2223; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private ReuseDefaultPort() { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/util/prefs/AddNodeChangeListener.java Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,94 @@ +/* + * 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. + */ + + /* @test + * @bug 7160252 + * @summary Checks if events are delivered to a listener + * when a child node is added or removed + */ + +import java.util.prefs.*; + + public class AddNodeChangeListener { + + private static boolean failed = false; + private static Preferences userRoot, N2; + private static NodeChangeListenerAdd ncla; + + public static void main(String[] args) + throws BackingStoreException, InterruptedException + { + userRoot = Preferences.userRoot(); + ncla = new NodeChangeListenerAdd(); + userRoot.addNodeChangeListener(ncla); + //Should initiate a node added event + addNode(); + // Should not initiate a node added event + addNode(); + //Should initate a child removed event + removeNode(); + + if (failed) + throw new RuntimeException("Failed"); + } + + private static void addNode() + throws BackingStoreException, InterruptedException + { + N2 = userRoot.node("N2"); + userRoot.flush(); + Thread.sleep(3000); + if (ncla.getAddNumber() != 1) + failed = true; + } + + private static void removeNode() + throws BackingStoreException, InterruptedException + { + N2.removeNode(); + userRoot.flush(); + Thread.sleep(3000); + if (ncla.getAddNumber() != 0) + failed = true; + } + + private static class NodeChangeListenerAdd implements NodeChangeListener { + private int totalNode = 0; + + @Override + public void childAdded(NodeChangeEvent evt) { + totalNode++; + } + + @Override + public void childRemoved(NodeChangeEvent evt) { + totalNode--; + } + + public int getAddNumber(){ + return totalNode; + } + } + }
--- a/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java Thu Aug 30 21:02:16 2012 -0700 @@ -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 @@ -25,6 +25,7 @@ import java.rmi.Naming; import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; import java.util.Random; import java.util.ArrayList; import java.util.Date; @@ -249,11 +250,12 @@ } synchronized (user) { + int port = -1; // create new registry and bind new AppleUserImpl in registry try { - LocateRegistry.createRegistry(1099); //TestLibrary.REGISTRY_PORT); - Naming.rebind("rmi://localhost:1099/AppleUser",user); - //TestLibrary.REGISTRY_PORT + "/AppleUser", user); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + port = TestLibrary.getRegistryPort(registry); + Naming.rebind("rmi://localhost:" + port + "/AppleUser",user); } catch (RemoteException e) { //TestLibrary.bomb("Failed to bind AppleUser", e); } catch (java.net.MalformedURLException e) { @@ -263,10 +265,9 @@ // start the other server if available try { Class app = Class.forName("ApplicationServer"); - server = new Thread((Runnable) app.newInstance()); - logger.log(Level.INFO, "Starting application server " + - "in same process"); - server.start(); + java.lang.reflect.Constructor appConstructor = + app.getDeclaredConstructor(new Class[] {Integer.TYPE}); + server = new Thread((Runnable) appConstructor.newInstance(port)); } catch (ClassNotFoundException e) { // assume the other server is running in a separate process logger.log(Level.INFO, "Application server must be " +
--- a/test/sun/rmi/rmic/newrmic/equivalence/run.sh Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/rmic/newrmic/equivalence/run.sh Thu Aug 30 21:02:16 2012 -0700 @@ -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,8 @@ # @summary This test verifies that the new implementation of rmic # generates equivalent classes as the old implementation, for a set # of sample input classes. +# @library ../../../../../java/rmi/testlibrary +# @build TestLibrary # @author Peter Jones # # @build AgentServerImpl
--- a/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java Thu Aug 30 21:02:16 2012 -0700 @@ -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 @@ -87,7 +87,6 @@ } public static class DoRMIStuff { - private static final int PORT = 2020; private interface Foo extends Remote { Object echo(Object obj) throws RemoteException; } @@ -96,8 +95,9 @@ public Object echo(Object obj) { return obj; } } public static void main(String[] args) throws Exception { - LocateRegistry.createRegistry(PORT); - Registry reg = LocateRegistry.getRegistry("", PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + Registry reg = LocateRegistry.getRegistry("", registryPort); FooImpl fooimpl = new FooImpl(); UnicastRemoteObject.exportObject(fooimpl, 0); reg.rebind("foo", fooimpl);
--- a/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -77,8 +77,9 @@ * logger output is non-null. */ public class CheckLogging { - private static final String LOCATION = - "rmi://localhost:" + TestLibrary.REGISTRY_PORT + "/"; + private static int REGISTRY_PORT = -1; + private static String LOCATION; + private static final ByteArrayOutputStream clientCallOut = new ByteArrayOutputStream(); @@ -100,7 +101,9 @@ private static Registry registry; static { try { - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + REGISTRY_PORT = TestLibrary.getRegistryPort(registry); + LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/"; } catch (Exception e) { TestLibrary.bomb("could not create registry"); }
--- a/test/sun/rmi/transport/proxy/EagerHttpFallback.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/transport/proxy/EagerHttpFallback.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 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 @@ -25,6 +25,8 @@ * @bug 4290727 * @summary Verify that ConnectException will trigger HTTP fallback if * sun.rmi.transport.proxy.eagerHttpFallback system property is set. + * @library ../../../../java/rmi/testlibrary + * @build TestLibrary * @run main/othervm EagerHttpFallback */ @@ -33,8 +35,8 @@ public class EagerHttpFallback { - static final int INITIAL_PORT = 7070; - static final int FALLBACK_PORT = 7071; + static final int INITIAL_PORT = TestLibrary.getUnusedRandomPort(); + static final int FALLBACK_PORT = TestLibrary.getUnusedRandomPort(); public static void main(String[] args) throws Exception { System.setProperty("http.proxyHost", "127.0.0.1");
--- a/test/sun/rmi/transport/tcp/DeadCachedConnection.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/rmi/transport/tcp/DeadCachedConnection.java Thu Aug 30 21:02:16 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ import java.rmi.server.*; public class DeadCachedConnection { - static public final int regport = 17340; + static public final int regport = TestLibrary.getUnusedRandomPort(); static public void main(String[] argv) throws Exception {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/security/krb5/auto/FileKeyTab.java Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,55 @@ +/* + * 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 7152121 + * @summary Krb5LoginModule no longer handles keyTabNames with "file:" prefix + * @compile -XDignore.symbol.file FileKeyTab.java + * @run main/othervm FileKeyTab + */ + +import java.io.File; +import java.io.FileOutputStream; +import sun.security.jgss.GSSUtil; + +// The basic krb5 test skeleton you can copy from +public class FileKeyTab { + + public static void main(String[] args) throws Exception { + new OneKDC(null).writeJAASConf(); + String ktab = new File(OneKDC.KTAB).getAbsolutePath().replace('\\', '/'); + File f = new File(OneKDC.JAAS_CONF); + try (FileOutputStream fos = new FileOutputStream(f)) { + fos.write(( + "server {\n" + + " com.sun.security.auth.module.Krb5LoginModule required\n" + + " principal=\"" + OneKDC.SERVER + "\"\n" + + " useKeyTab=true\n" + + " keyTab=\"file:" + ktab + "\"\n" + + " storeKey=true;\n};\n" + ).getBytes()); + } + Context.fromJAAS("server"); + } +}
--- a/test/sun/tools/jcmd/help_help.out Wed Aug 29 23:05:55 2012 -0700 +++ b/test/sun/tools/jcmd/help_help.out Thu Aug 30 21:02:16 2012 -0700 @@ -1,7 +1,7 @@ help For more information about a specific command use 'help <command>'. With no argument this will show a list of available commands. 'help all' will show help for all commands. -Impact: Low: +Impact: Low Syntax : help [options] [<command name>]
--- a/test/tools/launcher/Arrrghs.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/tools/launcher/Arrrghs.java Thu Aug 30 21:02:16 2012 -0700 @@ -24,7 +24,7 @@ /** * @test * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938 - * 6894719 6968053 + * 6894719 6968053 7151434 7146424 * @summary Argument parsing validation. * @compile -XDignore.symbol.file Arrrghs.java * @run main Arrrghs @@ -36,7 +36,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Arrrghs extends TestHelper { private Arrrghs(){} @@ -75,7 +81,7 @@ /* * This method detects the cookie in the output stream of the process. */ - private static boolean detectCookie(InputStream istream, + private boolean detectCookie(InputStream istream, String expectedArguments) throws IOException { BufferedReader rd = new BufferedReader(new InputStreamReader(istream)); boolean retval = false; @@ -105,7 +111,7 @@ return retval; } - private static boolean doTest0(ProcessBuilder pb, String expectedArguments) { + private boolean doReExecTest0(ProcessBuilder pb, String expectedArguments) { boolean retval = false; try { pb.redirectErrorStream(true); @@ -121,26 +127,27 @@ } /** - * This method return true if the expected and detected arguments are the same. + * This method returns true if the expected and detected arguments are the same. * Quoting could cause dissimilar testArguments and expected arguments. */ - static int doTest(String testArguments, String expectedPattern) { + int doReExecTest(String testArguments, String expectedPattern) { ProcessBuilder pb = new ProcessBuilder(javaCmd, VersionStr, testArguments); Map<String, String> env = pb.environment(); - env.put("_JAVA_LAUNCHER_DEBUG", "true"); - return doTest0(pb, testArguments) ? 0 : 1; + env.put(JLDEBUG_KEY, "true"); + return doReExecTest0(pb, testArguments) ? 0 : 1; } /** * A convenience method for identical test pattern and expected arguments */ - static int doTest(String testPattern) { - return doTest(testPattern, testPattern); + int doReExecTest(String testPattern) { + return doReExecTest(testPattern, testPattern); } - static void quoteParsingTests() { + @Test + void testQuoteParsingThroughReExec() { /* * Tests for 6214916 * These tests require that a JVM (any JVM) be installed in the system registry. @@ -155,96 +162,433 @@ // Basic test - testExitValue += doTest("-a -b -c -d"); + testExitValue += doReExecTest("-a -b -c -d"); // Basic test with many spaces - testExitValue += doTest("-a -b -c -d"); + testExitValue += doReExecTest("-a -b -c -d"); // Quoted whitespace does matter ? - testExitValue += doTest("-a \"\"-b -c\"\" -d"); + testExitValue += doReExecTest("-a \"\"-b -c\"\" -d"); // Escaped quotes outside of quotes as literals - testExitValue += doTest("-a \\\"-b -c\\\" -d"); + testExitValue += doReExecTest("-a \\\"-b -c\\\" -d"); // Check for escaped quotes inside of quotes as literal - testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d"); + testExitValue += doReExecTest("-a \"-b \\\"stuff\\\"\" -c -d"); // A quote preceeded by an odd number of slashes is a literal quote - testExitValue += doTest("-a -b\\\\\\\" -c -d"); + testExitValue += doReExecTest("-a -b\\\\\\\" -c -d"); // A quote preceeded by an even number of slashes is a literal quote // see 6214916. - testExitValue += doTest("-a -b\\\\\\\\\" -c -d"); + testExitValue += doReExecTest("-a -b\\\\\\\\\" -c -d"); // Make sure that whitespace doesn't interfere with the removal of the // appropriate tokens. (space-tab-space preceeds -jre-restict-search). - testExitValue += doTest("-a -b \t -jre-restrict-search -c -d","-a -b -c -d"); + testExitValue += doReExecTest("-a -b \t -jre-restrict-search -c -d", "-a -b -c -d"); // Make sure that the mJRE tokens being stripped, aren't stripped if // they happen to appear as arguments to the main class. - testExitValue += doTest("foo -version:1.1+"); + testExitValue += doReExecTest("foo -version:1.1+"); + + System.out.println("Completed arguments quoting tests with " + + testExitValue + " errors"); + } + // the pattern we hope to see in the output + static final Pattern ArgPattern = Pattern.compile("\\s*argv\\[[0-9]*\\].*=.*"); + + void checkArgumentParsing(String inArgs, String... expArgs) throws IOException { + List<String> scratchpad = new ArrayList<>(); + scratchpad.add("set " + JLDEBUG_KEY + "=true"); + // GAK, -version needs to be added so that windows can flush its stderr + // exiting the process prematurely can terminate the stderr. + scratchpad.add(javaCmd + " -version " + inArgs); + File batFile = new File("atest.bat"); + java.nio.file.Files.deleteIfExists(batFile.toPath()); + createFile(batFile, scratchpad); + + TestResult tr = doExec(batFile.getName()); + + ArrayList<String> expList = new ArrayList<>(); + expList.add(javaCmd); + expList.add("-version"); + expList.addAll(Arrays.asList(expArgs)); + + List<String> gotList = new ArrayList<>(); + for (String x : tr.testOutput) { + Matcher m = ArgPattern.matcher(x); + if (m.matches()) { + String a[] = x.split("="); + gotList.add(a[a.length - 1].trim()); + } + } + if (!gotList.equals(expList)) { + System.out.println(tr); + System.out.println("Expected args:"); + System.out.println(expList); + System.out.println("Obtained args:"); + System.out.println(gotList); + throw new RuntimeException("Error: args do not match"); + } + System.out.println("\'" + inArgs + "\'" + " - Test passed"); + } + + /* + * This tests general quoting and are specific to Windows, *nixes + * need not worry about this, these have been tested with Windows + * implementation and those that are known to work are used against + * the java implementation. Note that the ProcessBuilder gets in the + * way when testing some of these arguments, therefore we need to + * create and execute a .bat file containing the arguments. + */ + @Test + void testArgumentParsing() throws IOException { + if (!isWindows) + return; + // no quotes + checkArgumentParsing("a b c d", "a", "b", "c", "d"); + + // single quotes + checkArgumentParsing("\"a b c d\"", "a b c d"); + + //double quotes + checkArgumentParsing("\"\"a b c d\"\"", "a", "b", "c", "d"); + + // triple quotes + checkArgumentParsing("\"\"\"a b c d\"\"\"", "\"a b c d\""); + + // a literal within single quotes + checkArgumentParsing("\"a\"b c d\"e\"", "ab", "c", "de"); + + // a literal within double quotes + checkArgumentParsing("\"\"a\"b c d\"e\"\"", "ab c de"); + + // a literal quote + checkArgumentParsing("a\\\"b", "a\"b"); + + // double back-slash + checkArgumentParsing("\"a b c d\\\\\"", "a b c d\\"); + + // triple back-slash + checkArgumentParsing("a\\\\\\\"b", "a\\\"b"); + + // dangling quote + checkArgumentParsing("\"a b c\"\"", "a b c\""); + + // expansions of white space separators + checkArgumentParsing("a b", "a", "b"); + checkArgumentParsing("a\tb", "a", "b"); + checkArgumentParsing("a \t b", "a", "b"); + + checkArgumentParsing("\"C:\\TEST A\\\\\"", "C:\\TEST A\\"); + checkArgumentParsing("\"\"C:\\TEST A\\\\\"\"", "C:\\TEST", "A\\"); + + // MS Windows tests + // triple back-slash + checkArgumentParsing("a\\\\\\d", "a\\\\\\d"); + + // triple back-slash in quotes + checkArgumentParsing("\"a\\\\\\d\"", "a\\\\\\d"); + + // slashes separating characters + checkArgumentParsing("X\\Y\\Z", "X\\Y\\Z"); + checkArgumentParsing("\\X\\Y\\Z", "\\X\\Y\\Z"); + + // literals within dangling quotes, etc. + checkArgumentParsing("\"a b c\" d e", "a b c", "d", "e"); + checkArgumentParsing("\"ab\\\"c\" \"\\\\\" d", "ab\"c", "\\", "d"); + checkArgumentParsing("a\\\\\\c d\"e f\"g h", "a\\\\\\c", "de fg", "h"); + checkArgumentParsing("a\\\\\\\"b c d", "a\\\"b", "c", "d"); + checkArgumentParsing("a\\\\\\\\\"g c\" d e", "a\\\\g c", "d", "e"); + + // treatment of back-slashes + checkArgumentParsing("*\\", "*\\"); + checkArgumentParsing("*/", "*/"); + checkArgumentParsing(".\\*", ".\\*"); + checkArgumentParsing("./*", "./*"); + checkArgumentParsing("..\\..\\*", "..\\..\\*"); + checkArgumentParsing("../../*", "../../*"); + checkArgumentParsing("..\\..\\", "..\\..\\"); + checkArgumentParsing("../../", "../../"); + } + + private void initEmptyDir(File emptyDir) throws IOException { + if (emptyDir.exists()) { + recursiveDelete(emptyDir); + } + emptyDir.mkdir(); + } + + private void initDirWithJavaFiles(File libDir) throws IOException { + + if (libDir.exists()) { + recursiveDelete(libDir); + } + libDir.mkdirs(); + ArrayList<String> scratchpad = new ArrayList<>(); + scratchpad.add("package lib;"); + scratchpad.add("public class Fbo {"); + scratchpad.add("public static void main(String... args){Foo.f();}"); + scratchpad.add("public static void f(){}"); + scratchpad.add("}"); + createFile(new File(libDir, "Fbo.java"), scratchpad); + + scratchpad.clear(); + scratchpad.add("package lib;"); + scratchpad.add("public class Foo {"); + scratchpad.add("public static void main(String... args){"); + scratchpad.add("for (String x : args) {"); + scratchpad.add("System.out.println(x);"); + scratchpad.add("}"); + scratchpad.add("Fbo.f();"); + scratchpad.add("}"); + scratchpad.add("public static void f(){}"); + scratchpad.add("}"); + createFile(new File(libDir, "Foo.java"), scratchpad); + } + + void checkArgumentWildcard(String inArgs, String... expArgs) throws IOException { + String[] in = {inArgs}; + checkArgumentWildcard(in, expArgs); - System.out.println("Completed arguments quoting tests with " + - testExitValue + " errors"); + // now add arbitrary arguments before and after + String[] outInArgs = { "-Q", inArgs, "-R"}; + + String[] outExpArgs = new String[expArgs.length + 2]; + outExpArgs[0] = "-Q"; + System.arraycopy(expArgs, 0, outExpArgs, 1, expArgs.length); + outExpArgs[expArgs.length + 1] = "-R"; + checkArgumentWildcard(outInArgs, outExpArgs); + } + + void checkArgumentWildcard(String[] inArgs, String[] expArgs) throws IOException { + ArrayList<String> argList = new ArrayList<>(); + argList.add(javaCmd); + argList.add("-cp"); + argList.add("lib" + File.separator + "*"); + argList.add("lib.Foo"); + argList.addAll(Arrays.asList(inArgs)); + String[] cmds = new String[argList.size()]; + argList.toArray(cmds); + TestResult tr = doExec(cmds); + if (!tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: classpath single entry wildcard entry"); + } + + ArrayList<String> expList = new ArrayList<>(); + expList.addAll(Arrays.asList(expArgs)); + + List<String> gotList = new ArrayList<>(); + for (String x : tr.testOutput) { + gotList.add(x.trim()); + } + if (!gotList.equals(expList)) { + System.out.println(tr); + System.out.println("Expected args:"); + System.out.println(expList); + System.out.println("Obtained args:"); + System.out.println(gotList); + throw new RuntimeException("Error: args do not match"); + } + System.out.print("\'"); + for (String x : inArgs) { + System.out.print(x + " "); + } + System.out.println("\'" + " - Test passed"); } /* + * These tests are not expected to work on *nixes, and are ignored. + */ + @Test + void testWildCardArgumentProcessing() throws IOException { + if (!isWindows) + return; + File cwd = new File("."); + File libDir = new File(cwd, "lib"); + initDirWithJavaFiles(libDir); + initEmptyDir(new File(cwd, "empty")); + + // test if javac (the command) can compile *.java + TestResult tr = doExec(javacCmd, libDir.getName() + File.separator + "*.java"); + if (!tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: compiling java wildcards"); + } + + // use the jar cmd to create jars using the ? wildcard + File jarFoo = new File(libDir, "Foo.jar"); + tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class"); + if (!tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: creating jar with wildcards"); + } + + // now the litmus test!, this should work + checkArgumentWildcard("a", "a"); + + // test for basic expansion + checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java"); + + // basic expansion in quotes + checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java"); + + checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java", + "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java"); + + checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java", + "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java"); + + checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java", + "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java"); + + checkArgumentWildcard("lib\\?", "lib\\?"); + + // test for basic expansion + checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java"); + + // basic expansion in quotes + checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java"); + + // suffix expansion + checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class"); + + // suffix expansion in quotes + checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class"); + + // check for ? expansion now + checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java"); + + // check ? in quotes + checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java"); + + // check ? as suffixes + checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java"); + + // check ? in a leading role + checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java"); + checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java"); + + // check ? prefixed with - + checkArgumentWildcard("-?", "-?"); + + // check * prefixed with - + checkArgumentWildcard("-*", "-*"); + + // check on empty directory + checkArgumentWildcard("empty\\*", "empty\\*"); + checkArgumentWildcard("empty\\**", "empty\\**"); + checkArgumentWildcard("empty\\?", "empty\\?"); + checkArgumentWildcard("empty\\??", "empty\\??"); + checkArgumentWildcard("empty\\*?", "empty\\*?"); + checkArgumentWildcard("empty\\?*", "empty\\?*"); + + } + + void doArgumentCheck(String inArgs, String... expArgs) { + Map<String, String> env = new HashMap<>(); + env.put(JLDEBUG_KEY, "true"); + TestResult tr = doExec(env, javaCmd, inArgs); + System.out.println(tr); + int sindex = tr.testOutput.indexOf("Command line args:"); + if (sindex < 0) { + System.out.println(tr); + throw new RuntimeException("Error: no output"); + } + sindex++; // skip over the tag + List<String> gotList = new ArrayList<>(); + for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) { + String a[] = x.split("="); + gotList.add(a[a.length - 1].trim()); + } + List<String> expList = Arrays.asList(expArgs); + if (!gotList.equals(expList)) { + System.out.println(tr); + System.out.println("Expected args:"); + System.out.println(expList); + System.out.println("Obtained args:"); + System.out.println(gotList); + throw new RuntimeException("Error: args do not match"); + } + } + + + /* * These tests are usually run on non-existent targets to check error results */ - static void runBasicErrorMessageTests() { + @Test + void testBasicErrorMessages() { // Tests for 5030233 TestResult tr = doExec(javaCmd, "-cp"); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); tr = doExec(javaCmd, "-classpath"); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); tr = doExec(javaCmd, "-jar"); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); tr = doExec(javacCmd, "-cp"); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // Test for 6356475 "REGRESSION:"java -X" from cmdline fails" tr = doExec(javaCmd, "-X"); tr.checkPositive(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); tr = doExec(javaCmd, "-help"); tr.checkPositive(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // 6753938, test for non-negative exit value for an incorrectly formed // command line, '% java' tr = doExec(javaCmd); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // 6753938, test for non-negative exit value for an incorrectly formed // command line, '% java -Xcomp' tr = doExec(javaCmd, "-Xcomp"); tr.checkNegative(); tr.isNotZeroOutput(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); + + // 7151434, test for non-negative exit value for an incorrectly formed + // command line, '% java -jar -W', note the bogus -W + tr = doExec(javaCmd, "-jar", "-W"); + tr.checkNegative(); + tr.contains("Unrecognized option: -W"); + if (!tr.testStatus) + System.out.println(tr); } /* * Tests various dispositions of the main method, these tests are limited * to English locales as they check for error messages that are localized. */ - static void runMainMethodTests() throws FileNotFoundException { + @Test + void testMainMethod() throws FileNotFoundException { if (!isEnglishLocale()) { return; } @@ -256,55 +600,65 @@ (String[])null); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("Error: Could not find or load main class MIA"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "MIA"); tr.contains("Error: Could not find or load main class MIA"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // incorrect method access createJar(new File("some.jar"), new File("Foo"), "private static void main(String[] args){}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("Error: Main method not found in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "Foo"); tr.contains("Error: Main method not found in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // incorrect return type createJar(new File("some.jar"), new File("Foo"), "public static int main(String[] args){return 1;}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("Error: Main method must return a value of type void in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "Foo"); tr.contains("Error: Main method must return a value of type void in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // incorrect parameter type createJar(new File("some.jar"), new File("Foo"), "public static void main(Object[] args){}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("Error: Main method not found in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "Foo"); tr.contains("Error: Main method not found in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // incorrect method type - non-static createJar(new File("some.jar"), new File("Foo"), "public void main(String[] args){}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("Error: Main method is not static in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "Foo"); tr.contains("Error: Main method is not static in class Foo"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // amongst a potpourri of kindred main methods, is the right one chosen ? createJar(new File("some.jar"), new File("Foo"), @@ -316,25 +670,29 @@ "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.contains("THE_CHOSEN_ONE"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-cp", "some.jar", "Foo"); tr.contains("THE_CHOSEN_ONE"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // test for extraneous whitespace in the Main-Class attribute createJar(" Foo ", new File("some.jar"), new File("Foo"), "public static void main(String... args){}"); tr = doExec(javaCmd, "-jar", "some.jar"); tr.checkPositive(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); } /* * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if * the suppressed stack traces are exposed, ignore these tests for localized * locales, limiting to English only. */ - static void runDiagOptionTests() throws FileNotFoundException { + @Test + void testDiagOptions() throws FileNotFoundException { if (!isEnglishLocale()) { // only english version return; } @@ -345,48 +703,51 @@ tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar"); tr.contains("Error: Could not find or load main class MIA"); tr.contains("java.lang.ClassNotFoundException: MIA"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // use classpath to check tr = doExec(javaCmd, "-Xdiag", "-cp", "some.jar", "MIA"); tr.contains("Error: Could not find or load main class MIA"); tr.contains("java.lang.ClassNotFoundException: MIA"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); // a missing class on the classpath tr = doExec(javaCmd, "-Xdiag", "NonExistentClass"); tr.contains("Error: Could not find or load main class NonExistentClass"); tr.contains("java.lang.ClassNotFoundException: NonExistentClass"); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); } - static void test6894719() { + @Test + static void testJreRestrictSearchFlag() { // test both arguments to ensure they exist TestResult tr = null; tr = doExec(javaCmd, "-no-jre-restrict-search", "-version"); tr.checkPositive(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); tr = doExec(javaCmd, "-jre-restrict-search", "-version"); tr.checkPositive(); - System.out.println(tr); + if (!tr.testStatus) + System.out.println(tr); } /** * @param args the command line arguments * @throws java.io.FileNotFoundException */ - public static void main(String[] args) throws FileNotFoundException { + public static void main(String[] args) throws Exception { if (debug) { System.out.println("Starting Arrrghs tests"); } - quoteParsingTests(); - runBasicErrorMessageTests(); - runMainMethodTests(); - test6894719(); - runDiagOptionTests(); + Arrrghs a = new Arrrghs(); + a.run(args); if (testExitValue > 0) { System.out.println("Total of " + testExitValue + " failed"); System.exit(1);
--- a/test/tools/launcher/TestHelper.java Wed Aug 29 23:05:55 2012 -0700 +++ b/test/tools/launcher/TestHelper.java Thu Aug 30 21:02:16 2012 -0700 @@ -21,6 +21,14 @@ * questions. */ +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.util.regex.Pattern; +import java.io.StringWriter; +import java.io.PrintWriter; import java.util.Set; import java.io.BufferedReader; import java.io.File; @@ -55,11 +63,14 @@ static final File TEST_SOURCES_DIR; static final String JAVAHOME = System.getProperty("java.home"); + static final String JAVA_BIN; static final boolean isSDK = JAVAHOME.endsWith("jre"); static final String javaCmd; static final String javawCmd; static final String java64Cmd; static final String javacCmd; + static final String jarCmd; + static final JavaCompiler compiler; static final boolean debug = Boolean.getBoolean("TestHelper.Debug"); @@ -84,8 +95,10 @@ static final String JAVA_FILE_EXT = ".java"; static final String CLASS_FILE_EXT = ".class"; static final String JAR_FILE_EXT = ".jar"; + static final String EXE_FILE_EXT = ".exe"; static final String JLDEBUG_KEY = "_JAVA_LAUNCHER_DEBUG"; static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC"; + static final String TEST_PREFIX = "###TestError###: "; static int testExitValue = 0; @@ -111,6 +124,7 @@ compiler = ToolProvider.getSystemJavaCompiler(); File binDir = (isSDK) ? new File((new File(JAVAHOME)).getParentFile(), "bin") : new File(JAVAHOME, "bin"); + JAVA_BIN = binDir.getAbsolutePath(); File javaCmdFile = (isWindows) ? new File(binDir, "java.exe") : new File(binDir, "java"); @@ -125,6 +139,15 @@ : new File(binDir, "javac"); javacCmd = javacCmdFile.getAbsolutePath(); + File jarCmdFile = (isWindows) + ? new File(binDir, "jar.exe") + : new File(binDir, "jar"); + jarCmd = jarCmdFile.getAbsolutePath(); + if (!jarCmdFile.canExecute()) { + throw new RuntimeException("java <" + TestHelper.jarCmd + + "> must exist and should be executable"); + } + if (isWindows) { File javawCmdFile = new File(binDir, "javaw.exe"); javawCmd = javawCmdFile.getAbsolutePath(); @@ -152,6 +175,37 @@ java64Cmd = null; } } + void run(String[] args) throws Exception { + int passed = 0, failed = 0; + final Pattern p = (args != null && args.length > 0) + ? Pattern.compile(args[0]) + : null; + for (Method m : this.getClass().getDeclaredMethods()) { + boolean selected = (p == null) + ? m.isAnnotationPresent(Test.class) + : p.matcher(m.getName()).matches(); + if (selected) { + try { + m.invoke(this, (Object[]) null); + System.out.println(m.getName() + ": OK"); + passed++; + System.out.printf("Passed: %d, Failed: %d, ExitValue: %d%n", + passed, failed, testExitValue); + } catch (Throwable ex) { + System.out.printf("Test %s failed: %s %n", m, ex.getCause()); + failed++; + } + } + } + System.out.printf("Total: Passed: %d, Failed %d%n", passed, failed); + if (failed > 0) { + throw new RuntimeException("Tests failed: " + failed); + } + if (passed == 0 && failed == 0) { + throw new AssertionError("No test(s) selected: passed = " + + passed + ", failed = " + failed + " ??????????"); + } + } /* * is a dual mode available in the test jdk @@ -383,36 +437,45 @@ * of use methods to check the test results. */ static class TestResult { - StringBuilder status; + PrintWriter status; + StringWriter sw; int exitValue; List<String> testOutput; Map<String, String> env; Throwable t; + boolean testStatus; public TestResult(String str, int rv, List<String> oList, Map<String, String> env, Throwable t) { - status = new StringBuilder("Executed command: " + str + "\n"); + sw = new StringWriter(); + status = new PrintWriter(sw); + status.println("Executed command: " + str + "\n"); exitValue = rv; testOutput = oList; this.env = env; this.t = t; + testStatus = true; } - void appendStatus(String x) { - status = status.append(" " + x + "\n"); + void appendError(String x) { + testStatus = false; + testExitValue++; + status.println(TEST_PREFIX + x); + } + + void indentStatus(String x) { + status.println(" " + x); } void checkNegative() { if (exitValue == 0) { - appendStatus("Error: test must not return 0 exit value"); - testExitValue++; + appendError("test must not return 0 exit value"); } } void checkPositive() { if (exitValue != 0) { - appendStatus("Error: test did not return 0 exit value"); - testExitValue++; + appendError("test did not return 0 exit value"); } } @@ -422,8 +485,7 @@ boolean isZeroOutput() { if (!testOutput.isEmpty()) { - appendStatus("Error: No message from cmd please"); - testExitValue++; + appendError("No message from cmd please"); return false; } return true; @@ -431,8 +493,7 @@ boolean isNotZeroOutput() { if (testOutput.isEmpty()) { - appendStatus("Error: Missing message"); - testExitValue++; + appendError("Missing message"); return false; } return true; @@ -440,22 +501,26 @@ @Override public String toString() { - status.append("++++Begin Test Info++++\n"); - status.append("++++Test Environment++++\n"); + status.println("++++Begin Test Info++++"); + status.println("Test Status: " + (testStatus ? "PASS" : "FAIL")); + status.println("++++Test Environment++++"); for (String x : env.keySet()) { - status.append(x).append("=").append(env.get(x)).append("\n"); + indentStatus(x + "=" + env.get(x)); } - status.append("++++Test Output++++\n"); + status.println("++++Test Output++++"); for (String x : testOutput) { - appendStatus(x); + indentStatus(x); } - status.append("++++Test Stack Trace++++\n"); - status.append(t.toString()); + status.println("++++Test Stack Trace++++"); + status.println(t.toString()); for (StackTraceElement e : t.getStackTrace()) { - status.append(e.toString()); + indentStatus(e.toString()); } - status.append("++++End of Test Info++++\n"); - return status.toString(); + status.println("++++End of Test Info++++"); + status.flush(); + String out = sw.toString(); + status.close(); + return out; } boolean contains(String str) { @@ -464,8 +529,7 @@ return true; } } - appendStatus("Error: string <" + str + "> not found"); - testExitValue++; + appendError("string <" + str + "> not found"); return false; } @@ -475,9 +539,14 @@ return true; } } - appendStatus("Error: string <" + stringToMatch + "> not found"); - testExitValue++; + appendError("string <" + stringToMatch + "> not found"); return false; } } + /** + * Indicates that the annotated method is a test method. + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface Test {} }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/launcher/ToolsOpts.java Thu Aug 30 21:02:16 2012 -0700 @@ -0,0 +1,217 @@ +/* + * 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 + * @summary Test options patterns for javac,javah,javap and javadoc using + * javac as a test launcher. Create a dummy javac and intercept options to check + * reception of options as passed through the launcher without having to launch + * javac. Only -J and -cp ./* options should be consumed by the launcher. + * @run main ToolsOpts + * @author ssides + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ToolsOpts extends TestHelper { + static final String JBCP_PREPEND = "-J-Xbootclasspath/p:"; + private static File testJar = null; + static String[][] optionPatterns = { + {"-J-Xmx128m"}, + {"-J-version"}, + {"-J-XshowSettings:vm"}, + {"-J-Xdiag"}, + {"-J-showversion"}, + {"-J-version", "-option"}, + {"-option"}, + {"-option:sub"}, + {"-option:sub-"}, + {"-option:sub1,sub2"}, // -option:list + {"-option:{sub1,sub2,sub3}"}, // -option:{list} + {"-option:{{sub1,sub2,sub3}}"},// -option:{{list}} + {"-option/c:/export/date/tmp"}, + {"-option=value"}, + {"-Dpk1.pk2.pk3"}, // dot in option + {"-Dpk1.pk2=value"}, // dot in option followed by =value + {"@<filename>"}, + {"-option", "http://site.com", "http://site.org"}, + {"-option", "name", "p1:p2.."}, + {"-All these non-options show launchers pass options as is to tool."}, + {"-option"}, + {"-option:sub"}, + {"-option:sub-"}, + {"-option", "<path>"}, + {"-option", "<file>"}, + {"-option", "<dir>"}, + {"-option", "http://a/b/c/g;x?y#s"}, + {"-option", "<html code>"}, + {"-option", "name1:name2"}, + {"-option", "3"}, + {"option1", "-J-version", "option2"}, + {"option1", "-J-version", "-J-XshowSettings:vm", "option2"},}; + + static void init() throws IOException { + if (testJar != null) { + return; + } + + // A tool which simulates com.sun.tools.javac.Main argument processing, + // intercepts options passed via the javac launcher. + final String mainJava = "Main" + JAVA_FILE_EXT; + testJar = new File("test" + JAR_FILE_EXT); + List<String> contents = new ArrayList<>(); + contents.add("package com.sun.tools.javac;"); + contents.add("public class Main {"); + contents.add(" public static void main(String... args) {\n"); + contents.add(" for (String x : args) {\n"); + contents.add(" if(x.compareTo(\" \")!=0)\n"); + contents.add(" System.out.println(x);\n"); + contents.add(" }\n"); + contents.add(" }\n"); + contents.add("}\n"); + createFile(new File(mainJava), contents); + + // compile and jar Main.java into test.jar + compile("-d", ".", mainJava); + createJar("cvf", testJar.getAbsolutePath(), "com"); + } + + static void pass(String msg) { + System.out.println("pass: " + msg); + } + + static void errout(String msg) { + System.err.println(msg); + } + + // Return position of -J option or -1 is does not contain a -J option. + static int indexOfJoption(String[] opts) { + for (int i = 0; i < opts.length; i++) { + if (opts[i].startsWith("-J")) { + return i; + } + } + return -1; + } + + /* + * Check that J options a) are not passed to tool, and b) do the right thing, + * that is, they should be passed to java launcher and work as expected. + */ + static void checkJoptionOutput(TestResult tr, String[] opts) throws IOException { + // Check -J-version options are not passed but do what they should. + String jopts = ""; + for (String pat : opts) { + jopts = jopts.concat(pat + " "); + if (tr.contains("-J")) { + throw new RuntimeException( + "failed: output should not contain option " + pat); + } + if (pat.compareTo("-J-version") == 0 || + pat.compareTo("-J-showversion") == 0) { + if (!tr.contains("java version") && + !tr.contains("openjdk version")) { + throw new RuntimeException("failed: " + pat + + " should display a version string."); + } + } else if (pat.compareTo("-J-XshowSettings:VM") == 0) { + if (!tr.contains("VM settings")) { + throw new RuntimeException("failed: " + pat + + " should have display VM settings."); + } + } + } + pass("Joption check: " + jopts); + } + + /* + * Feed each option pattern in optionPatterns array to javac launcher with + * checking program preempting javac. Check that option received by 'dummy' + * javac is the one passed on the command line. + */ + static void runTestOptions() throws IOException { + init(); + TestResult tr = null; + String sTestJar = testJar.getAbsolutePath(); + int jpos = -1; + for (String arg[] : optionPatterns) { + jpos = indexOfJoption(arg); + //Build a cmd string for output in results reporting. + String cmdString = javacCmd + " " + JBCP_PREPEND + sTestJar; + for (String opt : arg) { + cmdString = cmdString.concat(" " + opt); + } + switch (arg.length) { + case 1: + tr = doExec(javacCmd, JBCP_PREPEND + sTestJar, + arg[0]); + break; + case 2: + tr = doExec(javacCmd, JBCP_PREPEND + sTestJar, + arg[0], arg[1]); + break; + case 3: + tr = doExec(javacCmd, JBCP_PREPEND + sTestJar, + arg[0], arg[1], arg[2]); + break; + case 4: + tr = doExec(javacCmd, JBCP_PREPEND + sTestJar, + arg[0], arg[1], arg[2], arg[3]); + break; + default: + tr = null; + break; + } + + String[] output = tr.testOutput.toArray(new String[tr.testOutput.size()]); + //-Joptions should not be passed to tool + if (jpos > -1) { + checkJoptionOutput(tr, arg); + if (tr.contains(arg[jpos])) { + throw new RuntimeException( + "failed! Should not have passed -J option to tool.\n" + + "CMD: " + cmdString); + } + } else { + //check that each non -J option was passed to tool. + for (int i = 0; i < arg.length; i++) { + if (output[i].compareTo(arg[i]) != 0) { + throw new RuntimeException( + "failed! CMD: " + cmdString + "\n case:" + + output[i] + " != " + arg[i]); + } else { + pass("check " + output[i] + " == " + arg[i]); + } + } + } + pass(cmdString); + } + } + + public static void main(String... args) throws IOException { + runTestOptions(); + } +}