changeset 3949:1d0039aea814

Merge
author mduigou
date Mon, 21 Mar 2011 11:49:37 -0700
parents e74e7991ba1d be5a4198c468
children 8fafdc993bf2 ef5bbbe0dd75
files
diffstat 40 files changed, 489 insertions(+), 352 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon Mar 21 11:31:54 2011 -0700
+++ b/.hgtags	Mon Mar 21 11:49:37 2011 -0700
@@ -108,3 +108,4 @@
 8ac52c85f9e91336dc00b52ef90b42eecf3230b3 jdk7-b131
 6bbc7a4734952ae7604578f270e1566639fa8752 jdk7-b132
 5e5f68a01d12a4432172f384d5201f3a05254493 jdk7-b133
+554adcfb615e63e62af530b1c10fcf7813a75b26 jdk7-b134
--- a/make/common/Demo.gmk	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/common/Demo.gmk	Mon Mar 21 11:49:37 2011 -0700
@@ -118,8 +118,11 @@
 DEMO_ALL_NATIVE_SOURCES += $(filter %.hpp,$(DEMO_ALL_FILES))
 
 # If we have java sources, then define the jar file we will create
+ifndef DEMO_JAR_NAME
+  DEMO_JAR_NAME = $(DEMONAME).jar
+endif
 ifneq ($(strip $(DEMO_JAVA_SOURCES)),)
-  DEMO_JAR            = $(DEMO_DESTDIR)/$(DEMONAME).jar
+  DEMO_JAR            = $(DEMO_DESTDIR)/$(DEMO_JAR_NAME)
 endif
 
 # If we have native sources, define the native library we will create
@@ -252,6 +255,17 @@
 	$(MKDIR) -p $(DEMO_JAR_IMAGE)
 	$(JAVAC_CMD) -d $(DEMO_JAR_IMAGE) -sourcepath $(DEMO_BUILD_SRCDIR) \
 	    @$(DEMO_JAVAC_INPUT)
+  ifeq ($(DEMO_INCL_SRC),true)
+	$(CP) $(DEMO_JAVA_SOURCES:%=$(DEMO_BUILD_SRCDIR)/%) $(DEMO_JAR_IMAGE)
+  endif
+  ifeq ($(DEMO_ONLY_SRC),true)
+	$(RM) -r $(DEMO_JAR_IMAGE)
+	$(MKDIR) -p $(DEMO_JAR_IMAGE)
+	$(CP) -r $(DEMO_BUILD_SRCDIR)/* $(DEMO_JAR_IMAGE)
+    ifneq ($(DEMO_TOPFILES),)
+	$(CP) $(DEMO_ROOT)/$(DEMO_TOPFILES) $(DEMO_JAR_IMAGE)
+    endif
+  endif
 	$(BOOT_JAR_CMD) -cfm $@ $(DEMO_MANIFEST) \
 	     -C $(DEMO_JAR_IMAGE) . \
 	     $(BOOT_JAR_JFLAGS)
@@ -324,9 +338,9 @@
 ifdef DEMO_IS_APPLET
 	@$(ECHO) "Expanding jar file into demos area at $(DEMO_DESTDIR)"
 	( $(CD) $(DEMO_DESTDIR) && \
-	  $(BOOT_JAR_CMD) -xfv $(DEMONAME).jar \
+	  $(BOOT_JAR_CMD) -xfv $(DEMO_JAR_NAME) \
 	     $(BOOT_JAR_JFLAGS) && \
-	  $(RM) -r META-INF $(DEMONAME).jar  && \
+	  $(RM) -r META-INF $(DEMO_JAR_NAME) && \
 	  $(java-vm-cleanup) )
 	@( $(CD) $(DEMO_DESTDIR) && $(java-vm-cleanup) )
 	@$(ECHO) "Expanding source into demos area at $(DEMO_DESTDIR)"
--- a/make/common/shared/Compiler-msvc.gmk	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/common/shared/Compiler-msvc.gmk	Mon Mar 21 11:49:37 2011 -0700
@@ -153,6 +153,9 @@
   ifndef COMPILER_VERSION
     COMPILER_VERSION := $(error COMPILER_VERSION cannot be empty here)
   endif
+  ifneq ($(COMPILER_VERSION),VS2010)
+    COMPILER_VERSION := $(error COMPILER_VERSION must be VS2010)
+  endif
   
   # Shared library generation flag
   SHARED_LIBRARY_FLAG = -LD
--- a/make/common/shared/Platform.gmk	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/common/shared/Platform.gmk	Mon Mar 21 11:49:37 2011 -0700
@@ -148,7 +148,7 @@
   # Suffix for file bundles used in previous release
   BUNDLE_FILE_SUFFIX=.tar
   # How much RAM does this machine have:
-  MB_OF_MEMORY=$(shell /etc/prtconf | fgrep 'Memory size:' | expand | cut -d' ' -f3)
+  MB_OF_MEMORY=$(shell /usr/sbin/prtconf | fgrep 'Memory size:' | expand | cut -d' ' -f3)
 endif
 
 # Platform settings specific to Linux
--- a/make/mkdemo/jfc/SwingSet2/Makefile	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/mkdemo/jfc/SwingSet2/Makefile	Mon Mar 21 11:49:37 2011 -0700
@@ -37,6 +37,7 @@
 DEMO_MAINCLASS  = $(DEMONAME)
 DEMO_MANIFEST_ATTR = SplashScreen-Image: resources/images/splash.png
 DEMO_DESTDIR    = $(DEMODIR)/jfc/$(DEMONAME)
+DEMO_INCL_SRC   = true
 
 #
 # Demo jar building rules.
--- a/make/mkdemo/jpda/Makefile	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/mkdemo/jpda/Makefile	Mon Mar 21 11:49:37 2011 -0700
@@ -32,6 +32,8 @@
 DEMO_PKGDIR     = com/sun/tools/example
 DEMO_TOPFILES   = ./com/sun/tools/example/README
 DEMO_DESTDIR    = $(DEMODIR)/jpda
+DEMO_JAR_NAME   = examples.jar
+DEMO_ONLY_SRC   = true
 
 #
 # Demo jar building rules.
--- a/make/tools/manifest.mf	Mon Mar 21 11:31:54 2011 -0700
+++ b/make/tools/manifest.mf	Mon Mar 21 11:49:37 2011 -0700
@@ -1,6 +1,6 @@
 Manifest-Version: 1.0
 Specification-Title: Java Platform API Specification
-Specification-Version: 1.6
+Specification-Version: 1.7
 Specification-Vendor: Oracle
 Implementation-Title: Java Runtime Environment
 Implementation-Version: @@RELEASE@@
--- a/src/share/bin/java.c	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/bin/java.c	Mon Mar 21 11:49:37 2011 -0700
@@ -61,6 +61,9 @@
  * interfaces.
  */
 
+/* we always print to stderr */
+#define USE_STDERR JNI_TRUE
+
 static jboolean printVersion = JNI_FALSE; /* print and exit */
 static jboolean showVersion = JNI_FALSE;  /* print but continue */
 static jboolean printUsage = JNI_FALSE;   /* print and exit*/
@@ -1136,36 +1139,18 @@
     return; \
   }
 
-static jstring platformEncoding = NULL;
-static jstring getPlatformEncoding(JNIEnv *env) {
-    if (platformEncoding == NULL) {
-        jstring propname = (*env)->NewStringUTF(env, "sun.jnu.encoding");
-        if (propname) {
-            jclass cls;
-            jmethodID mid;
-            NULL_CHECK0 (cls = FindBootStrapClass(env, "java/lang/System"));
-            NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
-                                   env, cls,
-                                   "getProperty",
-                                   "(Ljava/lang/String;)Ljava/lang/String;"));
-            platformEncoding = (*env)->CallStaticObjectMethod (
-                                    env, cls, mid, propname);
-        }
+static jclass helperClass = NULL;
+
+static jclass
+GetLauncherHelperClass(JNIEnv *env) {
+    if (helperClass == NULL) {
+        NULL_CHECK0(helperClass = FindBootStrapClass(env,
+                "sun/launcher/LauncherHelper"));
     }
-    return platformEncoding;
+    return helperClass;
 }
 
-static jboolean isEncodingSupported(JNIEnv *env, jstring enc) {
-    jclass cls;
-    jmethodID mid;
-    NULL_CHECK0 (cls = FindBootStrapClass(env, "java/nio/charset/Charset"));
-    NULL_CHECK0 (mid = (*env)->GetStaticMethodID(
-                           env, cls,
-                           "isSupported",
-                           "(Ljava/lang/String;)Z"));
-    return (*env)->CallStaticBooleanMethod(env, cls, mid, enc);
-}
-
+static jmethodID makePlatformStringMID = NULL;
 /*
  * Returns a new Java string object for the specified platform string.
  */
@@ -1173,36 +1158,23 @@
 NewPlatformString(JNIEnv *env, char *s)
 {
     int len = (int)JLI_StrLen(s);
-    jclass cls;
-    jmethodID mid;
     jbyteArray ary;
-    jstring enc;
-
+    jclass cls = GetLauncherHelperClass(env);
+    NULL_CHECK0(cls);
     if (s == NULL)
         return 0;
-    enc = getPlatformEncoding(env);
 
     ary = (*env)->NewByteArray(env, len);
     if (ary != 0) {
         jstring str = 0;
         (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s);
         if (!(*env)->ExceptionOccurred(env)) {
-            NULL_CHECK0(cls = FindBootStrapClass(env, "java/lang/String"));
-            if (isEncodingSupported(env, enc) == JNI_TRUE) {
-                NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
-                                          "([BLjava/lang/String;)V"));
-                str = (*env)->NewObject(env, cls, mid, ary, enc);
-            } else {
-                /*If the encoding specified in sun.jnu.encoding is not
-                  endorsed by "Charset.isSupported" we have to fall back
-                  to use String(byte[]) explicitly here without specifying
-                  the encoding name, in which the StringCoding class will
-                  pickup the iso-8859-1 as the fallback converter for us.
-                */
-                NULL_CHECK0(mid = (*env)->GetMethodID(env, cls, "<init>",
-                                          "([B)V"));
-                str = (*env)->NewObject(env, cls, mid, ary);
+            if (makePlatformStringMID == NULL) {
+                NULL_CHECK0(makePlatformStringMID = (*env)->GetStaticMethodID(env,
+                        cls, "makePlatformString", "(Z[B)Ljava/lang/String;"));
             }
+            str = (*env)->CallStaticObjectMethod(env, cls,
+                    makePlatformStringMID, USE_STDERR, ary);
             (*env)->DeleteLocalRef(env, ary);
             return str;
         }
@@ -1239,20 +1211,28 @@
 static jclass
 LoadMainClass(JNIEnv *env, int mode, char *name)
 {
-    jclass cls;
     jmethodID mid;
     jstring str;
     jobject result;
     jlong start, end;
-
+    jclass cls = GetLauncherHelperClass(env);
+    NULL_CHECK0(cls);
     if (JLI_IsTraceLauncher()) {
         start = CounterGet();
     }
-    NULL_CHECK0(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
-    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls, "checkAndLoadMain",
-                                          "(ZILjava/lang/String;)Ljava/lang/Class;"));
-    str = (*env)->NewStringUTF(env, name);
-    result = (*env)->CallStaticObjectMethod(env, cls, mid, JNI_TRUE, mode, str);
+    NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,
+                "checkAndLoadMain",
+                "(ZILjava/lang/String;)Ljava/lang/Class;"));
+
+    switch (mode) {
+        case LM_CLASS:
+            str = NewPlatformString(env, name);
+            break;
+        default:
+            str = (*env)->NewStringUTF(env, name);
+            break;
+    }
+    result = (*env)->CallStaticObjectMethod(env, cls, mid, USE_STDERR, mode, str);
 
     if (JLI_IsTraceLauncher()) {
         end   = CounterGet();
@@ -1478,15 +1458,15 @@
 static void
 ShowSettings(JNIEnv *env, char *optString)
 {
-    jclass cls;
     jmethodID showSettingsID;
     jstring joptString;
-    NULL_CHECK(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
+    jclass cls = GetLauncherHelperClass(env);
+    NULL_CHECK(cls);
     NULL_CHECK(showSettingsID = (*env)->GetStaticMethodID(env, cls,
             "showSettings", "(ZLjava/lang/String;JJJZ)V"));
     joptString = (*env)->NewStringUTF(env, optString);
     (*env)->CallStaticVoidMethod(env, cls, showSettingsID,
-                                 JNI_TRUE,
+                                 USE_STDERR,
                                  joptString,
                                  (jlong)initialHeapSize,
                                  (jlong)maxHeapSize,
@@ -1500,18 +1480,15 @@
 static void
 PrintUsage(JNIEnv* env, jboolean doXUsage)
 {
-  jclass cls;
   jmethodID initHelp, vmSelect, vmSynonym, vmErgo, printHelp, printXUsageMessage;
   jstring jprogname, vm1, vm2;
   int i;
-
-  NULL_CHECK(cls = FindBootStrapClass(env, "sun/launcher/LauncherHelper"));
-
-
+  jclass cls = GetLauncherHelperClass(env);
+  NULL_CHECK(cls);
   if (doXUsage) {
     NULL_CHECK(printXUsageMessage = (*env)->GetStaticMethodID(env, cls,
                                         "printXUsageMessage", "(Z)V"));
-    (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, JNI_TRUE);
+    (*env)->CallStaticVoidMethod(env, cls, printXUsageMessage, USE_STDERR);
   } else {
     NULL_CHECK(initHelp = (*env)->GetStaticMethodID(env, cls,
                                         "initHelpMessage", "(Ljava/lang/String;)V"));
@@ -1570,7 +1547,7 @@
     }
 
     /* Complete the usage message and print to stderr*/
-    (*env)->CallStaticVoidMethod(env, cls, printHelp, JNI_TRUE);
+    (*env)->CallStaticVoidMethod(env, cls, printHelp, USE_STDERR);
   }
   return;
 }
--- a/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java	Mon Mar 21 11:49:37 2011 -0700
@@ -743,24 +743,24 @@
 
         private void dumpBand() throws IOException {
             assert(optDumpBands);
-            PrintStream ps = new PrintStream(getDumpStream(this, ".txt"));
-            String irr = (bandCoding == regularCoding) ? "" : " irregular";
-            ps.print("# length="+length+
-                     " size="+outputSize()+
-                     irr+" coding="+bandCoding);
-            if (metaCoding != noMetaCoding) {
-                StringBuffer sb = new StringBuffer();
-                for (int i = 0; i < metaCoding.length; i++) {
-                    if (i == 1)  sb.append(" /");
-                    sb.append(" ").append(metaCoding[i] & 0xFF);
+            try (PrintStream ps = new PrintStream(getDumpStream(this, ".txt"))) {
+                String irr = (bandCoding == regularCoding) ? "" : " irregular";
+                ps.print("# length="+length+
+                         " size="+outputSize()+
+                         irr+" coding="+bandCoding);
+                if (metaCoding != noMetaCoding) {
+                    StringBuffer sb = new StringBuffer();
+                    for (int i = 0; i < metaCoding.length; i++) {
+                        if (i == 1)  sb.append(" /");
+                        sb.append(" ").append(metaCoding[i] & 0xFF);
+                    }
+                    ps.print(" //header: "+sb);
                 }
-                ps.print(" //header: "+sb);
+                printArrayTo(ps, values, 0, length);
             }
-            printArrayTo(ps, values, 0, length);
-            ps.close();
-            OutputStream ds = getDumpStream(this, ".bnd");
-            bandCoding.writeArrayTo(ds, values, 0, length);
-            ds.close();
+            try (OutputStream ds = getDumpStream(this, ".bnd")) {
+                bandCoding.writeArrayTo(ds, values, 0, length);
+            }
         }
 
         /** Disburse one value. */
@@ -829,12 +829,12 @@
 
         private void dumpBand() throws IOException {
             assert(optDumpBands);
-            OutputStream ds = getDumpStream(this, ".bnd");
-            if (bytesForDump != null)
-                bytesForDump.writeTo(ds);
-            else
-                bytes.writeTo(ds);
-            ds.close();
+            try (OutputStream ds = getDumpStream(this, ".bnd")) {
+                if (bytesForDump != null)
+                    bytesForDump.writeTo(ds);
+                else
+                    bytes.writeTo(ds);
+            }
         }
 
         public void readDataFrom(InputStream in) throws IOException {
--- a/src/share/classes/com/sun/java/util/jar/pack/Driver.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/Driver.java	Mon Mar 21 11:49:37 2011 -0700
@@ -150,12 +150,12 @@
                 // See if there is any other action to take.
                 if ("--config-file=".equals(state)) {
                     String propFile = av.remove(0);
-                    InputStream propIn = new FileInputStream(propFile);
                     Properties fileProps = new Properties();
-                    fileProps.load(new BufferedInputStream(propIn));
+                    try (InputStream propIn = new FileInputStream(propFile)) {
+                        fileProps.load(propIn);
+                    }
                     if (engProps.get(verboseProp) != null)
                         fileProps.list(System.out);
-                    propIn.close();
                     for (Map.Entry<Object,Object> me : fileProps.entrySet()) {
                         engProps.put((String) me.getKey(), (String) me.getValue());
                     }
@@ -348,10 +348,10 @@
                 else
                     fileOut = new FileOutputStream(outfile);
                 fileOut = new BufferedOutputStream(fileOut);
-                JarOutputStream out = new JarOutputStream(fileOut);
-                junpack.unpack(in, out);
-                //in.close();  // p200 closes in but not out
-                out.close();
+                try (JarOutputStream out = new JarOutputStream(fileOut)) {
+                    junpack.unpack(in, out);
+                    // p200 closes in but not out
+                }
                 // At this point, we have a good jarfile (or newfile, if -r)
             }
 
@@ -411,8 +411,7 @@
         long filelen = new File(jarfile).length();
         if (filelen <= 0)  return "";
         long skiplen = Math.max(0, filelen - tail.length);
-        InputStream in = new FileInputStream(new File(jarfile));
-        try {
+        try (InputStream in = new FileInputStream(new File(jarfile))) {
             in.skip(skiplen);
             in.read(tail);
             for (int i = tail.length-4; i >= 0; i--) {
@@ -426,8 +425,6 @@
                 }
             }
             return "";
-        } finally {
-            in.close();
         }
     }
 
--- a/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java	Mon Mar 21 11:49:37 2011 -0700
@@ -241,9 +241,9 @@
     void run(File inFile, JarOutputStream jstream) throws IOException {
         // %%% maybe memory-map the file, and pass it straight into unpacker
         ByteBuffer mappedFile = null;
-        FileInputStream fis = new FileInputStream(inFile);
-        run(fis, jstream, mappedFile);
-        fis.close();
+        try (FileInputStream fis = new FileInputStream(inFile)) {
+            run(fis, jstream, mappedFile);
+        }
         // Note:  caller is responsible to finish with jstream.
     }
 
--- a/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java	Mon Mar 21 11:49:37 2011 -0700
@@ -540,9 +540,9 @@
             Index index = initCPIndex(tag, cpMap);
 
             if (optDumpBands) {
-                PrintStream ps = new PrintStream(getDumpStream(index, ".idx"));
-                printArrayTo(ps, index.cpMap, 0, index.cpMap.length);
-                ps.close();
+                try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) {
+                    printArrayTo(ps, index.cpMap, 0, index.cpMap.length);
+                }
             }
         }
 
@@ -828,26 +828,27 @@
         attr_definition_headers.readFrom(in);
         attr_definition_name.readFrom(in);
         attr_definition_layout.readFrom(in);
-        PrintStream dump = !optDumpBands ? null
-            : new PrintStream(getDumpStream(attr_definition_headers, ".def"));
-        for (int i = 0; i < numAttrDefs; i++) {
-            int       header = attr_definition_headers.getByte();
-            Utf8Entry name   = (Utf8Entry) attr_definition_name.getRef();
-            Utf8Entry layout = (Utf8Entry) attr_definition_layout.getRef();
-            int       ctype  = (header &  ADH_CONTEXT_MASK);
-            int       index  = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
-            Attribute.Layout def = new Attribute.Layout(ctype,
-                                                        name.stringValue(),
-                                                        layout.stringValue());
-            // Check layout string for Java 6 extensions.
-            String pvLayout = def.layoutForPackageMajver(getPackageMajver());
-            if (!pvLayout.equals(def.layout())) {
-                throw new IOException("Bad attribute layout in version 150 archive: "+def.layout());
+        try (PrintStream dump = !optDumpBands ? null
+                 : new PrintStream(getDumpStream(attr_definition_headers, ".def")))
+        {
+            for (int i = 0; i < numAttrDefs; i++) {
+                int       header = attr_definition_headers.getByte();
+                Utf8Entry name   = (Utf8Entry) attr_definition_name.getRef();
+                Utf8Entry layout = (Utf8Entry) attr_definition_layout.getRef();
+                int       ctype  = (header &  ADH_CONTEXT_MASK);
+                int       index  = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
+                Attribute.Layout def = new Attribute.Layout(ctype,
+                                                            name.stringValue(),
+                                                            layout.stringValue());
+                // Check layout string for Java 6 extensions.
+                String pvLayout = def.layoutForPackageMajver(getPackageMajver());
+                if (!pvLayout.equals(def.layout())) {
+                    throw new IOException("Bad attribute layout in version 150 archive: "+def.layout());
+                }
+                this.setAttributeLayoutIndex(def, index);
+                if (dump != null)  dump.println(index+" "+def);
             }
-            this.setAttributeLayoutIndex(def, index);
-            if (dump != null)  dump.println(index+" "+def);
         }
-        if (dump != null)  dump.close();
         attr_definition_headers.doneDisbursing();
         attr_definition_name.doneDisbursing();
         attr_definition_layout.doneDisbursing();
--- a/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java	Mon Mar 21 11:49:37 2011 -0700
@@ -458,9 +458,9 @@
                 Utils.log.info("Writing "+cpMap.length+" "+ConstantPool.tagName(tag)+" entries...");
 
             if (optDumpBands) {
-                PrintStream ps = new PrintStream(getDumpStream(index, ".idx"));
-                printArrayTo(ps, cpMap, 0, cpMap.length);
-                ps.close();
+                try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) {
+                    printArrayTo(ps, cpMap, 0, cpMap.length);
+                }
             }
 
             switch (tag) {
@@ -923,33 +923,34 @@
             }
         });
         attrDefsWritten = new Attribute.Layout[numAttrDefs];
-        PrintStream dump = !optDumpBands ? null
-            : new PrintStream(getDumpStream(attr_definition_headers, ".def"));
-        int[] indexForDebug = Arrays.copyOf(attrIndexLimit, ATTR_CONTEXT_LIMIT);
-        for (int i = 0; i < defs.length; i++) {
-            int header = ((Integer)defs[i][0]).intValue();
-            Attribute.Layout def = (Attribute.Layout) defs[i][1];
-            attrDefsWritten[i] = def;
-            assert((header & ADH_CONTEXT_MASK) == def.ctype());
-            attr_definition_headers.putByte(header);
-            attr_definition_name.putRef(ConstantPool.getUtf8Entry(def.name()));
-            String layout = def.layoutForPackageMajver(getPackageMajver());
-            attr_definition_layout.putRef(ConstantPool.getUtf8Entry(layout));
-            // Check that we are transmitting that correct attribute index:
-            boolean debug = false;
-            assert(debug = true);
-            if (debug) {
-                int hdrIndex = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
-                if (hdrIndex < 0)  hdrIndex = indexForDebug[def.ctype()]++;
-                int realIndex = (attrIndexTable.get(def)).intValue();
-                assert(hdrIndex == realIndex);
-            }
-            if (dump != null) {
-                int index = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
-                dump.println(index+" "+def);
+        try (PrintStream dump = !optDumpBands ? null
+                 : new PrintStream(getDumpStream(attr_definition_headers, ".def")))
+        {
+            int[] indexForDebug = Arrays.copyOf(attrIndexLimit, ATTR_CONTEXT_LIMIT);
+            for (int i = 0; i < defs.length; i++) {
+                int header = ((Integer)defs[i][0]).intValue();
+                Attribute.Layout def = (Attribute.Layout) defs[i][1];
+                attrDefsWritten[i] = def;
+                assert((header & ADH_CONTEXT_MASK) == def.ctype());
+                attr_definition_headers.putByte(header);
+                attr_definition_name.putRef(ConstantPool.getUtf8Entry(def.name()));
+                String layout = def.layoutForPackageMajver(getPackageMajver());
+                attr_definition_layout.putRef(ConstantPool.getUtf8Entry(layout));
+                // Check that we are transmitting that correct attribute index:
+                boolean debug = false;
+                assert(debug = true);
+                if (debug) {
+                    int hdrIndex = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
+                    if (hdrIndex < 0)  hdrIndex = indexForDebug[def.ctype()]++;
+                    int realIndex = (attrIndexTable.get(def)).intValue();
+                    assert(hdrIndex == realIndex);
+                }
+                if (dump != null) {
+                    int index = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
+                    dump.println(index+" "+def);
+                }
             }
         }
-        if (dump != null)  dump.close();
     }
 
     void writeAttrCounts() throws IOException {
--- a/src/share/classes/com/sun/java/util/jar/pack/PropMap.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/PropMap.java	Mon Mar 21 11:49:37 2011 -0700
@@ -122,26 +122,23 @@
         // Define certain attribute layouts by default.
         // Do this after the previous props are put in place,
         // to allow override if necessary.
-        InputStream propStr = null;
-        try {
-            String propFile = "intrinsic.properties";
-            propStr = PackerImpl.class.getResourceAsStream(propFile);
-            props.load(new BufferedInputStream(propStr));
-            for (Map.Entry<Object, Object> e : props.entrySet()) {
-                String key = (String) e.getKey();
-                String val = (String) e.getValue();
-                if (key.startsWith("attribute.")) {
-                    e.setValue(Attribute.normalizeLayoutString(val));
-                }
+        String propFile = "intrinsic.properties";
+
+        try (InputStream propStr = PackerImpl.class.getResourceAsStream(propFile)) {
+            if (propStr == null) {
+                throw new RuntimeException(propFile + " cannot be loaded");
             }
+            props.load(propStr);
         } catch (IOException ee) {
             throw new RuntimeException(ee);
-        } finally {
-            try {
-                if (propStr != null) {
-                    propStr.close();
-                }
-            } catch (IOException ignore) {}
+        }
+
+        for (Map.Entry<Object, Object> e : props.entrySet()) {
+            String key = (String) e.getKey();
+            String val = (String) e.getValue();
+            if (key.startsWith("attribute.")) {
+                e.setValue(Attribute.normalizeLayoutString(val));
+            }
         }
 
         defaultProps = (new HashMap<>(props));  // shrink to fit
--- a/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java	Mon Mar 21 11:49:37 2011 -0700
@@ -161,8 +161,9 @@
         }
         // Use the stream-based implementation.
         // %%% Reconsider if native unpacker learns to memory-map the file.
-        FileInputStream instr = new FileInputStream(in);
-        unpack(instr, out);
+        try (FileInputStream instr = new FileInputStream(in)) {
+            unpack(instr, out);
+        }
         if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) {
             in.delete();
         }
--- a/src/share/classes/com/sun/java/util/jar/pack/Utils.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/com/sun/java/util/jar/pack/Utils.java	Mon Mar 21 11:49:37 2011 -0700
@@ -268,18 +268,18 @@
         // 4947205 : Peformance is slow when using pack-effort=0
         out = new BufferedOutputStream(out);
         out = new NonCloser(out); // protect from JarOutputStream.close()
-        JarOutputStream jout = new JarOutputStream(out);
-        copyJarFile(in, jout);
-        jout.close();
+        try (JarOutputStream jout = new JarOutputStream(out)) {
+            copyJarFile(in, jout);
+        }
     }
     static void copyJarFile(JarFile in, OutputStream out) throws IOException {
 
         // 4947205 : Peformance is slow when using pack-effort=0
         out = new BufferedOutputStream(out);
         out = new NonCloser(out); // protect from JarOutputStream.close()
-        JarOutputStream jout = new JarOutputStream(out);
-        copyJarFile(in, jout);
-        jout.close();
+        try (JarOutputStream jout = new JarOutputStream(out)) {
+            copyJarFile(in, jout);
+        }
     }
         // Wrapper to prevent closing of client-supplied stream.
     static private
--- a/src/share/classes/java/nio/file/Files.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/java/nio/file/Files.java	Mon Mar 21 11:49:37 2011 -0700
@@ -1712,10 +1712,10 @@
      * @return  the {@code path} parameter
      *
      * @throws  UnsupportedOperationException
-     *          if the attribute view is not available or it does not support
-     *          updating the attribute
+     *          if the attribute view is not available
      * @throws  IllegalArgumentException
-     *          if the attribute value is of the correct type but has an
+     *          if the attribute name is not specified, or is not recognized, or
+     *          the attribute value is of the correct type but has an
      *          inappropriate value
      * @throws  ClassCastException
      *          if the attribute value is not of the expected type or is a
@@ -1776,9 +1776,12 @@
      * @param   options
      *          options indicating how symbolic links are handled
      *
-     * @return  the attribute value or {@code null} if the attribute view
-     *          is not available or it does not support reading the attribute
+     * @return  the attribute value
      *
+     * @throws  UnsupportedOperationException
+     *          if the attribute view is not available
+     * @throws  IllegalArgumentException
+     *          if the attribute name is not specified or is not recognized
      * @throws  IOException
      *          if an I/O error occurs
      * @throws  SecurityException
@@ -1794,8 +1797,9 @@
     {
         // only one attribute should be read
         if (attribute.indexOf('*') >= 0 || attribute.indexOf(',') >= 0)
-            return null;
+            throw new IllegalArgumentException(attribute);
         Map<String,Object> map = readAttributes(path, attribute, options);
+        assert map.size() == 1;
         String name;
         int pos = attribute.indexOf(':');
         if (pos == -1) {
@@ -1868,9 +1872,14 @@
      * @param   options
      *          options indicating how symbolic links are handled
      *
-     * @return  a map of the attributes returned; may be empty. The map's keys
-     *          are the attribute names, its values are the attribute values
+     * @return  a map of the attributes returned; The map's keys are the
+     *          attribute names, its values are the attribute values
      *
+     * @throws  UnsupportedOperationException
+     *          if the attribute view is not available
+     * @throws  IllegalArgumentException
+     *          if no attributes are specified or an unrecognized attributes is
+     *          specified
      * @throws  IOException
      *          if an I/O error occurs
      * @throws  SecurityException
--- a/src/share/classes/java/nio/file/Path.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/java/nio/file/Path.java	Mon Mar 21 11:49:37 2011 -0700
@@ -228,6 +228,9 @@
      * not have a root component and the given path has a root component then
      * this path does not start with the given path.
      *
+     * <p> If the given path is associated with a different {@code FileSystem}
+     * to this path then {@code false} is returned.
+     *
      * @param   other
      *          the given path
      *
@@ -270,6 +273,9 @@
      * does not have a root component and the given path has a root component
      * then this path does not end with the given path.
      *
+     * <p> If the given path is associated with a different {@code FileSystem}
+     * to this path then {@code false} is returned.
+     *
      * @param   other
      *          the given path
      *
@@ -283,7 +289,10 @@
      * the given path string, in exactly the manner specified by the {@link
      * #endsWith(Path) endsWith(Path)} method. On UNIX for example, the path
      * "{@code foo/bar}" ends with "{@code foo/bar}" and "{@code bar}". It does
-     * not end with "{@code r}" or "{@code /bar}".
+     * not end with "{@code r}" or "{@code /bar}". Note that trailing separators
+     * are not taken into account, and so invoking this method on the {@code
+     * Path}"{@code foo/bar}" with the {@code String} "{@code bar/}" returns
+     * {@code true}.
      *
      * @param   other
      *          the given path string
@@ -724,12 +733,18 @@
      * provider, platform specific. This method does not access the file system
      * and neither file is required to exist.
      *
+     * <p> This method may not be used to compare paths that are associated
+     * with different file system providers.
+     *
      * @param   other  the path compared to this path.
      *
      * @return  zero if the argument is {@link #equals equal} to this path, a
      *          value less than zero if this path is lexicographically less than
      *          the argument, or a value greater than zero if this path is
      *          lexicographically greater than the argument
+     *
+     * @throws  ClassCastException
+     *          if the paths are associated with different providers
      */
     @Override
     int compareTo(Path other);
@@ -738,7 +753,7 @@
      * Tests this path for equality with the given object.
      *
      * <p> If the given object is not a Path, or is a Path associated with a
-     * different provider, then this method immediately returns {@code false}.
+     * different {@code FileSystem}, then this method returns {@code false}.
      *
      * <p> Whether or not two path are equal depends on the file system
      * implementation. In some cases the paths are compared without regard
--- a/src/share/classes/java/nio/file/WatchKey.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/java/nio/file/WatchKey.java	Mon Mar 21 11:49:37 2011 -0700
@@ -146,5 +146,5 @@
      *
      * @return the object for which this watch key was created
      */
-    //T watchable();
+    Watchable watchable();
 }
--- a/src/share/classes/java/nio/file/attribute/FileTime.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/java/nio/file/attribute/FileTime.java	Mon Mar 21 11:49:37 2011 -0700
@@ -216,12 +216,14 @@
      * "2009-02-13T23:31:30Z"}, and {@code FileTime.fromMillis(1234567890123L).toString()}
      * yields {@code "2009-02-13T23:31:30.123Z"}.
      *
-     * <p> A {@code FileTime} is primarly intended to represent the value of a
+     * <p> A {@code FileTime} is primarily intended to represent the value of a
      * file's time stamp. Where used to represent <i>extreme values</i>, where
      * the year is less than "{@code 0001}" or greater than "{@code 9999}" then
-     * the year may be expanded to more than four digits and may be
-     * negative-signed. If more than four digits then leading zeros are not
-     * present. The year before "{@code 0001}" is "{@code -0001}".
+     * this method deviates from ISO 8601 in the same manner as the
+     * <a href="http://www.w3.org/TR/xmlschema-2/#deviantformats">XML Schema
+     * language</a>. That is, the year may be expanded to more than four digits
+     * and may be negative-signed. If more than four digits then leading zeros
+     * are not present. The year before "{@code 0001}" is "{@code -0001}".
      *
      * @return  the string representation of this file time
      */
--- a/src/share/classes/java/nio/file/spi/FileSystemProvider.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/java/nio/file/spi/FileSystemProvider.java	Mon Mar 21 11:49:37 2011 -0700
@@ -1037,6 +1037,11 @@
      * @return  a map of the attributes returned; may be empty. The map's keys
      *          are the attribute names, its values are the attribute values
      *
+     * @throws  UnsupportedOperationException
+     *          if the attribute view is not available
+     * @throws  IllegalArgumentException
+     *          if no attributes are specified or an unrecognized attributes is
+     *          specified
      * @throws  IOException
      *          If an I/O error occurs
      * @throws  SecurityException
@@ -1064,10 +1069,10 @@
      *          options indicating how symbolic links are handled
      *
      * @throws  UnsupportedOperationException
-     *          if the attribute view is not available or it does not support
-     *          updating the attribute
+     *          if the attribute view is not available
      * @throws  IllegalArgumentException
-     *          if the attribute value is of the correct type but has an
+     *          if the attribute name is not specified, or is not recognized, or
+     *          the attribute value is of the correct type but has an
      *          inappropriate value
      * @throws  ClassCastException
      *          If the attribute value is not of the expected type or is a
--- a/src/share/classes/sun/launcher/LauncherHelper.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/launcher/LauncherHelper.java	Mon Mar 21 11:49:37 2011 -0700
@@ -42,10 +42,12 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.nio.charset.Charset;
 import java.util.ResourceBundle;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -471,11 +473,11 @@
         } catch (ClassNotFoundException cnfe) {
             abort(ostream, cnfe, "java.launcher.cls.error1", cn);
         }
-        signatureDiagnostic(ostream, c);
+        getMainMethod(ostream, c);
         return c;
     }
 
-    static void signatureDiagnostic(PrintStream ostream, Class<?> clazz) {
+    static Method getMainMethod(PrintStream ostream, Class<?> clazz) {
         String classname = clazz.getName();
         Method method = null;
         try {
@@ -495,6 +497,31 @@
         if (method.getReturnType() != java.lang.Void.TYPE) {
             abort(ostream, null, "java.launcher.cls.error3", classname);
         }
-        return;
+        return method;
+    }
+
+    private static final String encprop = "sun.jnu.encoding";
+    private static String encoding = null;
+    private static boolean isCharsetSupported = false;
+
+    /*
+     * converts a c or a byte array to a platform specific string,
+     * previously implemented as a native method in the launcher.
+     */
+    static String makePlatformString(boolean printToStderr, byte[] inArray) {
+        final PrintStream ostream = (printToStderr) ? System.err : System.out;
+        if (encoding == null) {
+            encoding = System.getProperty(encprop);
+            isCharsetSupported = Charset.isSupported(encoding);
+        }
+        try {
+            String out = isCharsetSupported
+                    ? new String(inArray, encoding)
+                    : new String(inArray);
+            return out;
+        } catch (UnsupportedEncodingException uee) {
+            abort(ostream, uee, null);
+        }
+        return null; // keep the compiler happy
     }
 }
--- a/src/share/classes/sun/nio/fs/AbstractAclFileAttributeView.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/AbstractAclFileAttributeView.java	Mon Mar 21 11:49:37 2011 -0700
@@ -57,8 +57,8 @@
             setAcl((List<AclEntry>)value);
             return;
         }
-        throw new UnsupportedOperationException("'" + name() + ":" +
-                attribute + "' not supported");
+        throw new IllegalArgumentException("'" + name() + ":" +
+            attribute + "' not recognized");
     }
 
     @Override
@@ -81,6 +81,8 @@
                 owner = true;
                 continue;
             }
+            throw new IllegalArgumentException("'" + name() + ":" +
+                attribute + "' not recognized");
         }
         Map<String,Object> result = new HashMap<>(2);
         if (acl)
--- a/src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java	Mon Mar 21 11:49:37 2011 -0700
@@ -46,6 +46,18 @@
     private static final String IS_SYMBOLIC_LINK_NAME = "isSymbolicLink";
     private static final String IS_OTHER_NAME = "isOther";
 
+    // the names of the basic attributes
+    static final Set<String> basicAttributeNames =
+        Util.newSet(SIZE_NAME,
+                    CREATION_TIME_NAME,
+                    LAST_ACCESS_TIME_NAME,
+                    LAST_MODIFIED_TIME_NAME,
+                    FILE_KEY_NAME,
+                    IS_DIRECTORY_NAME,
+                    IS_REGULAR_FILE_NAME,
+                    IS_SYMBOLIC_LINK_NAME,
+                    IS_OTHER_NAME);
+
     protected AbstractBasicFileAttributeView() { }
 
     @Override
@@ -69,24 +81,26 @@
             setTimes(null, null, (FileTime)value);
             return;
         }
-        throw new UnsupportedOperationException("'" + attribute +
-            "' is unknown or read-only attribute");
+        throw new IllegalArgumentException("'" + name() + ":" +
+            attribute + "' not recognized");
     }
 
     /**
      * Used to build a map of attribute name/values.
      */
     static class AttributesBuilder {
-        private Set<String> set = new HashSet<>();
+        private Set<String> names = new HashSet<>();
         private Map<String,Object> map = new HashMap<>();
         private boolean copyAll;
 
-        private AttributesBuilder(String[] attributes) {
-            for (String attribute: attributes) {
-                if (attribute.equals("*")) {
+        private AttributesBuilder(Set<String> allowed, String[] requested) {
+            for (String name: requested) {
+                if (name.equals("*")) {
                     copyAll = true;
                 } else {
-                    set.add(attribute);
+                    if (!allowed.contains(name))
+                        throw new IllegalArgumentException("'" + name + "' not recognized");
+                    names.add(name);
                 }
             }
         }
@@ -94,21 +108,19 @@
         /**
          * Creates builder to build up a map of the matching attributes
          */
-        static AttributesBuilder create(String[] attributes) {
-            return new AttributesBuilder(attributes);
+        static AttributesBuilder create(Set<String> allowed, String[] requested) {
+            return new AttributesBuilder(allowed, requested);
         }
 
         /**
          * Returns true if the attribute should be returned in the map
          */
-        boolean match(String attribute) {
-            if (copyAll)
-                return true;
-            return set.contains(attribute);
+        boolean match(String name) {
+            return copyAll || names.contains(name);
         }
 
-        void add(String attribute, Object value) {
-            map.put(attribute, value);
+        void add(String name, Object value) {
+            map.put(name, value);
         }
 
         /**
@@ -124,7 +136,7 @@
      * Invoked by readAttributes or sub-classes to add all matching basic
      * attributes to the builder
      */
-    final void addBasicAttributesToBuilder(BasicFileAttributes attrs,
+    final void addRequestedBasicAttributes(BasicFileAttributes attrs,
                                            AttributesBuilder builder)
     {
         if (builder.match(SIZE_NAME))
@@ -148,9 +160,12 @@
     }
 
     @Override
-    public Map<String,Object> readAttributes(String[] attributes) throws IOException {
-        AttributesBuilder builder = AttributesBuilder.create(attributes);
-        addBasicAttributesToBuilder(readAttributes(), builder);
+    public Map<String,Object> readAttributes(String[] requested)
+        throws IOException
+    {
+        AttributesBuilder builder =
+            AttributesBuilder.create(basicAttributeNames, requested);
+        addRequestedBasicAttributes(readAttributes(), builder);
         return builder.unmodifiableMap();
     }
 }
--- a/src/share/classes/sun/nio/fs/AbstractFileSystemProvider.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/AbstractFileSystemProvider.java	Mon Mar 21 11:49:37 2011 -0700
@@ -29,7 +29,6 @@
 import java.nio.file.spi.FileSystemProvider;
 import java.io.IOException;
 import java.util.Map;
-import java.util.Collections;
 
 /**
  * Base implementation class of FileSystemProvider
@@ -72,6 +71,8 @@
         throws IOException
     {
         String[] s = split(attribute);
+        if (s[0].length() == 0)
+            throw new IllegalArgumentException(attribute);
         DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
         if (view == null)
             throw new UnsupportedOperationException("View '" + s[0] + "' not available");
@@ -83,9 +84,11 @@
         throws IOException
     {
         String[] s = split(attributes);
+        if (s[0].length() == 0)
+            throw new IllegalArgumentException(attributes);
         DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
         if (view == null)
-            return Collections.emptyMap();
+            throw new UnsupportedOperationException("View '" + s[0] + "' not available");
         return view.readAttributes(s[1].split(","));
     }
 
--- a/src/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/AbstractUserDefinedFileAttributeView.java	Mon Mar 21 11:49:37 2011 -0700
@@ -59,22 +59,6 @@
         return "user";
     }
 
-    private Object getAttribute(String attribute) throws IOException {
-        int size;
-        try {
-            size = size(attribute);
-        } catch (IOException e) {
-            // not found or some other I/O error
-            if (list().contains(attribute))
-                throw e;
-            return null;
-        }
-
-        byte[] buf = new byte[size];
-        int n = read(attribute, ByteBuffer.wrap(buf));
-        return (n == size) ? buf : Arrays.copyOf(buf, n);
-    }
-
     @Override
     public final void setAttribute(String attribute, Object value)
         throws IOException
@@ -94,12 +78,13 @@
     {
         // names of attributes to return
         List<String> names = new ArrayList<>();
-
         for (String name: attributes) {
             if (name.equals("*")) {
                 names = list();
                 break;
             } else {
+                if (name.length() == 0)
+                    throw new IllegalArgumentException();
                 names.add(name);
             }
         }
@@ -107,11 +92,12 @@
         // read each value and return in map
         Map<String,Object> result = new HashMap<>();
         for (String name: names) {
-            Object value = getAttribute(name);
-            if (value != null)
-                result.put(name, value);
+            int size = size(name);
+            byte[] buf = new byte[size];
+            int n = read(name, ByteBuffer.wrap(buf));
+            byte[] value = (n == size) ? buf : Arrays.copyOf(buf, n);
+            result.put(name, value);
         }
-
         return result;
     }
 }
--- a/src/share/classes/sun/nio/fs/AbstractWatchKey.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/AbstractWatchKey.java	Mon Mar 21 11:49:37 2011 -0700
@@ -81,7 +81,8 @@
     /**
      * Return the original watchable (Path)
      */
-    Path watchable() {
+    @Override
+    public Path watchable() {
         return dir;
     }
 
--- a/src/share/classes/sun/nio/fs/FileOwnerAttributeViewImpl.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/FileOwnerAttributeViewImpl.java	Mon Mar 21 11:49:37 2011 -0700
@@ -63,10 +63,10 @@
     {
         if (attribute.equals(OWNER_NAME)) {
             setOwner((UserPrincipal)value);
-            return;
+        } else {
+            throw new IllegalArgumentException("'" + name() + ":" +
+                attribute + "' not recognized");
         }
-        throw new UnsupportedOperationException("'" + name() + ":" +
-                attribute + "' not supported");
     }
 
     @Override
@@ -75,6 +75,9 @@
         for (String attribute: attributes) {
             if (attribute.equals("*") || attribute.equals(OWNER_NAME)) {
                 result.put(OWNER_NAME, getOwner());
+            } else {
+                throw new IllegalArgumentException("'" + name() + ":" +
+                    attribute + "' not recognized");
             }
         }
         return result;
--- a/src/share/classes/sun/nio/fs/Util.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/classes/sun/nio/fs/Util.java	Mon Mar 21 11:49:37 2011 -0700
@@ -25,6 +25,8 @@
 
 package sun.nio.fs;
 
+import java.util.*;
+
 /**
  * Utility methods
  */
@@ -54,6 +56,28 @@
         }
         result[n] = s.substring(last, s.length());
         return result;
+    }
 
+    /**
+     * Returns a Set containing the given elements.
+     */
+    static <E> Set<E> newSet(E... elements) {
+        HashSet<E> set = new HashSet<>();
+        for (E e: elements) {
+            set.add(e);
+        }
+        return set;
+    }
+
+    /**
+     * Returns a Set containing all the elements of the given Set plus
+     * the given elements.
+     */
+    static <E> Set<E> newSet(Set<E> other, E... elements) {
+        HashSet<E> set = new HashSet<>(other);
+        for (E e: elements) {
+            set.add(e);
+        }
+        return set;
     }
 }
--- a/src/share/sample/nio/file/WatchDir.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/share/sample/nio/file/WatchDir.java	Mon Mar 21 11:49:37 2011 -0700
@@ -33,8 +33,7 @@
 import static java.nio.file.StandardWatchEventKind.*;
 import static java.nio.file.LinkOption.*;
 import java.nio.file.attribute.*;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
 
 /**
  * Example to watch a directory (or tree) for changes to files.
@@ -43,9 +42,9 @@
 public class WatchDir {
 
     private final WatchService watcher;
-    private final Map<WatchKey,Path> keys;
     private final boolean recursive;
     private boolean trace = false;
+    private int count;
 
     @SuppressWarnings("unchecked")
     static <T> WatchEvent<T> cast(WatchEvent<?> event) {
@@ -57,17 +56,9 @@
      */
     private void register(Path dir) throws IOException {
         WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
-        if (trace) {
-            Path prev = keys.get(key);
-            if (prev == null) {
-                System.out.format("register: %s\n", dir);
-            } else {
-                if (!dir.equals(prev)) {
-                    System.out.format("update: %s -> %s\n", prev, dir);
-                }
-            }
-        }
-        keys.put(key, dir);
+        count++;
+        if (trace)
+            System.out.format("register: %s\n", dir);
     }
 
     /**
@@ -92,7 +83,6 @@
      */
     WatchDir(Path dir, boolean recursive) throws IOException {
         this.watcher = FileSystems.getDefault().newWatchService();
-        this.keys = new HashMap<WatchKey,Path>();
         this.recursive = recursive;
 
         if (recursive) {
@@ -121,12 +111,6 @@
                 return;
             }
 
-            Path dir = keys.get(key);
-            if (dir == null) {
-                System.err.println("WatchKey not recognized!!");
-                continue;
-            }
-
             for (WatchEvent<?> event: key.pollEvents()) {
                 WatchEvent.Kind kind = event.kind();
 
@@ -138,7 +122,7 @@
                 // Context for directory entry event is the file name of entry
                 WatchEvent<Path> ev = cast(event);
                 Path name = ev.context();
-                Path child = dir.resolve(name);
+                Path child = ((Path)key.watchable()).resolve(name);
 
                 // print out event
                 System.out.format("%s: %s\n", event.kind().name(), child);
@@ -156,15 +140,13 @@
                 }
             }
 
-            // reset key and remove from set if directory no longer accessible
+            // reset key
             boolean valid = key.reset();
             if (!valid) {
-                keys.remove(key);
-
-                // all directories are inaccessible
-                if (keys.isEmpty()) {
+                // directory no longer accessible
+                count--;
+                if (count == 0)
                     break;
-                }
             }
         }
     }
--- a/src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/solaris/classes/sun/nio/fs/LinuxDosFileAttributeView.java	Mon Mar 21 11:49:37 2011 -0700
@@ -27,6 +27,7 @@
 
 import java.nio.file.attribute.*;
 import java.util.Map;
+import java.util.Set;
 import java.io.IOException;
 import sun.misc.Unsafe;
 
@@ -57,6 +58,10 @@
     private static final int DOS_XATTR_SYSTEM   = 0x04;
     private static final int DOS_XATTR_ARCHIVE  = 0x20;
 
+    // the names of the DOS attributes (includes basic)
+    private static final Set<String> dosAttributeNames =
+        Util.newSet(basicAttributeNames, READONLY_NAME, ARCHIVE_NAME, SYSTEM_NAME, HIDDEN_NAME);
+
     LinuxDosFileAttributeView(UnixPath file, boolean followLinks) {
         super(file, followLinks);
     }
@@ -93,9 +98,10 @@
     public Map<String,Object> readAttributes(String[] attributes)
         throws IOException
     {
-        AttributesBuilder builder = AttributesBuilder.create(attributes);
+        AttributesBuilder builder =
+            AttributesBuilder.create(dosAttributeNames, attributes);
         DosFileAttributes attrs = readAttributes();
-        addBasicAttributesToBuilder(attrs, builder);
+        addRequestedBasicAttributes(attrs, builder);
         if (builder.match(READONLY_NAME))
             builder.add(READONLY_NAME, attrs.isReadOnly());
         if (builder.match(ARCHIVE_NAME))
--- a/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/solaris/classes/sun/nio/fs/LinuxFileSystem.java	Mon Mar 21 11:49:37 2011 -0700
@@ -28,8 +28,6 @@
 import java.nio.file.*;
 import java.io.IOException;
 import java.util.*;
-import java.security.AccessController;
-import sun.security.action.GetPropertyAction;
 import static sun.nio.fs.LinuxNativeDispatcher.*;
 
 /**
@@ -37,42 +35,16 @@
  */
 
 class LinuxFileSystem extends UnixFileSystem {
-    private final boolean hasInotify;
-
     LinuxFileSystem(UnixFileSystemProvider provider, String dir) {
         super(provider, dir);
-
-        // assume X.Y[-Z] format
-        String osversion = AccessController
-            .doPrivileged(new GetPropertyAction("os.version"));
-        String[] vers = Util.split(osversion, '.');
-        assert vers.length >= 2;
-
-        int majorVersion = Integer.parseInt(vers[0]);
-        int minorVersion = Integer.parseInt(vers[1]);
-        int microVersion = 0;
-        if (vers.length > 2) {
-            String[] microVers = Util.split(vers[2], '-');
-            microVersion = (microVers.length > 0) ?
-                Integer.parseInt(microVers[0]) : 0;
-        }
-
-        // inotify available since 2.6.13
-        this.hasInotify = ((majorVersion > 2) ||
-            (majorVersion == 2 && minorVersion > 6) ||
-            ((majorVersion == 2) && (minorVersion == 6) && (microVersion >= 13)));
     }
 
     @Override
     public WatchService newWatchService()
         throws IOException
     {
-        if (hasInotify) {
-            return new LinuxWatchService(this);
-        } else {
-            // use polling implementation on older kernels
-            return new PollingWatchService();
-        }
+        // assume 2.6.13 or newer
+        return new LinuxWatchService(this);
     }
 
 
--- a/src/solaris/classes/sun/nio/fs/UnixFileAttributeViews.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/solaris/classes/sun/nio/fs/UnixFileAttributeViews.java	Mon Mar 21 11:49:37 2011 -0700
@@ -123,6 +123,10 @@
         private static final String OWNER_NAME = "owner";
         private static final String GROUP_NAME = "group";
 
+        // the names of the posix attributes (incudes basic)
+        static final Set<String> posixAttributeNames =
+            Util.newSet(basicAttributeNames, PERMISSIONS_NAME, OWNER_NAME, GROUP_NAME);
+
         Posix(UnixPath file, boolean followLinks) {
             super(file, followLinks);
         }
@@ -172,9 +176,10 @@
          * Invoked by readAttributes or sub-classes to add all matching posix
          * attributes to the builder
          */
-        final void addPosixAttributesToBuilder(PosixFileAttributes attrs,
+        final void addRequestedPosixAttributes(PosixFileAttributes attrs,
                                                AttributesBuilder builder)
         {
+            addRequestedBasicAttributes(attrs, builder);
             if (builder.match(PERMISSIONS_NAME))
                 builder.add(PERMISSIONS_NAME, attrs.permissions());
             if (builder.match(OWNER_NAME))
@@ -184,13 +189,13 @@
         }
 
         @Override
-        public Map<String,Object> readAttributes(String[] attributes)
+        public Map<String,Object> readAttributes(String[] requested)
             throws IOException
         {
-            AttributesBuilder builder = AttributesBuilder.create(attributes);
+            AttributesBuilder builder =
+                AttributesBuilder.create(posixAttributeNames, requested);
             PosixFileAttributes attrs = readAttributes();
-            addBasicAttributesToBuilder(attrs, builder);
-            addPosixAttributesToBuilder(attrs, builder);
+            addRequestedPosixAttributes(attrs, builder);
             return builder.unmodifiableMap();
         }
 
@@ -287,6 +292,12 @@
         private static final String GID_NAME = "gid";
         private static final String CTIME_NAME = "ctime";
 
+        // the names of the unix attributes (including posix)
+        static final Set<String> unixAttributeNames =
+            Util.newSet(posixAttributeNames,
+                        MODE_NAME, INO_NAME, DEV_NAME, RDEV_NAME,
+                        NLINK_NAME, UID_NAME, GID_NAME, CTIME_NAME);
+
         Unix(UnixPath file, boolean followLinks) {
             super(file, followLinks);
         }
@@ -316,13 +327,13 @@
         }
 
         @Override
-        public Map<String,Object> readAttributes(String[] attributes)
+        public Map<String,Object> readAttributes(String[] requested)
             throws IOException
         {
-            AttributesBuilder builder = AttributesBuilder.create(attributes);
+            AttributesBuilder builder =
+                AttributesBuilder.create(unixAttributeNames, requested);
             UnixFileAttributes attrs = readAttributes();
-            addBasicAttributesToBuilder(attrs, builder);
-            addPosixAttributesToBuilder(attrs, builder);
+            addRequestedPosixAttributes(attrs, builder);
             if (builder.match(MODE_NAME))
                 builder.add(MODE_NAME, attrs.mode());
             if (builder.match(INO_NAME))
--- a/src/solaris/classes/sun/nio/fs/UnixPath.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/solaris/classes/sun/nio/fs/UnixPath.java	Mon Mar 21 11:49:37 2011 -0700
@@ -606,7 +606,9 @@
 
     @Override
     public boolean startsWith(Path other) {
-        UnixPath that = toUnixPath(other);
+        if (!(Objects.requireNonNull(other) instanceof UnixPath))
+            return false;
+        UnixPath that = (UnixPath)other;
 
         // other path is longer
         if (that.path.length > path.length)
@@ -655,7 +657,9 @@
 
     @Override
     public boolean endsWith(Path other) {
-        UnixPath that = toUnixPath(other);
+        if (!(Objects.requireNonNull(other) instanceof UnixPath))
+            return false;
+        UnixPath that = (UnixPath)other;
 
         int thisLen = path.length;
         int thatLen = that.path.length;
--- a/src/windows/classes/sun/nio/fs/WindowsFileAttributeViews.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/windows/classes/sun/nio/fs/WindowsFileAttributeViews.java	Mon Mar 21 11:49:37 2011 -0700
@@ -157,6 +157,11 @@
         private static final String HIDDEN_NAME = "hidden";
         private static final String ATTRIBUTES_NAME = "attributes";
 
+        // the names of the DOS attribtues (includes basic)
+        static final Set<String> dosAttributeNames =
+            Util.newSet(basicAttributeNames,
+                        READONLY_NAME, ARCHIVE_NAME, SYSTEM_NAME,  HIDDEN_NAME, ATTRIBUTES_NAME);
+
         Dos(WindowsPath file, boolean followLinks) {
             super(file, followLinks);
         }
@@ -193,9 +198,10 @@
         public Map<String,Object> readAttributes(String[] attributes)
             throws IOException
         {
-            AttributesBuilder builder = AttributesBuilder.create(attributes);
+            AttributesBuilder builder =
+                AttributesBuilder.create(dosAttributeNames, attributes);
             WindowsFileAttributes attrs = readAttributes();
-            addBasicAttributesToBuilder(attrs, builder);
+            addRequestedBasicAttributes(attrs, builder);
             if (builder.match(READONLY_NAME))
                 builder.add(READONLY_NAME, attrs.isReadOnly());
             if (builder.match(ARCHIVE_NAME))
--- a/src/windows/classes/sun/nio/fs/WindowsPath.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/windows/classes/sun/nio/fs/WindowsPath.java	Mon Mar 21 11:49:37 2011 -0700
@@ -646,7 +646,9 @@
 
     @Override
     public boolean startsWith(Path obj) {
-        WindowsPath other = toWindowsPath(obj);
+        if (!(Objects.requireNonNull(obj) instanceof WindowsPath))
+            return false;
+        WindowsPath other = (WindowsPath)obj;
 
         // if this path has a root component the given path's root must match
         if (!this.root.equalsIgnoreCase(other.root)) {
@@ -675,7 +677,9 @@
 
     @Override
     public boolean endsWith(Path obj) {
-        WindowsPath other = toWindowsPath(obj);
+        if (!(Objects.requireNonNull(obj) instanceof WindowsPath))
+            return false;
+        WindowsPath other = (WindowsPath)obj;
 
         // other path is longer
         if (other.path.length() > this.path.length()) {
--- a/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c	Mon Mar 21 11:31:54 2011 -0700
+++ b/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c	Mon Mar 21 11:49:37 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -173,24 +173,45 @@
 JNIEXPORT jlong JNICALL Java_sun_tools_attach_WindowsVirtualMachine_openProcess
   (JNIEnv *env, jclass cls, jint pid)
 {
-    HANDLE hProcess;
+    HANDLE hProcess = NULL;
 
-    /*
-     * Attempt to open process. If it fails then we try to enable the
-     * SE_DEBUG_NAME privilege and retry.
-     */
-    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
-    if (hProcess == NULL && GetLastError() == ERROR_ACCESS_DENIED) {
-        hProcess = doPrivilegedOpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+    if (pid == (jint) GetCurrentProcessId()) {
+        /* process is attaching to itself; get a pseudo handle instead */
+        hProcess = GetCurrentProcess();
+        /* duplicate the pseudo handle so it can be used in more contexts */
+        if (DuplicateHandle(hProcess, hProcess, hProcess, &hProcess,
+                PROCESS_ALL_ACCESS, FALSE, 0) == 0) {
+            /*
+             * Could not duplicate the handle which isn't a good sign,
+             * but we'll try again with OpenProcess() below.
+             */
+            hProcess = NULL;
+        }
     }
 
     if (hProcess == NULL) {
-        if (GetLastError() == ERROR_INVALID_PARAMETER) {
-            JNU_ThrowIOException(env, "no such process");
-        } else {
-            JNU_ThrowIOExceptionWithLastError(env, "OpenProcess failed");
+        /*
+         * Attempt to open process. If it fails then we try to enable the
+         * SE_DEBUG_NAME privilege and retry.
+         */
+        hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
+        if (hProcess == NULL && GetLastError() == ERROR_ACCESS_DENIED) {
+            hProcess = doPrivilegedOpenProcess(PROCESS_ALL_ACCESS, FALSE,
+                           (DWORD)pid);
         }
-        return (jlong)0;
+
+        if (hProcess == NULL) {
+            if (GetLastError() == ERROR_INVALID_PARAMETER) {
+                JNU_ThrowIOException(env, "no such process");
+            } else {
+                char err_mesg[255];
+                /* include the last error in the default detail message */
+                sprintf(err_mesg, "OpenProcess(pid=%d) failed; LastError=0x%x",
+                    (int)pid, (int)GetLastError());
+                JNU_ThrowIOExceptionWithLastError(env, err_mesg);
+            }
+            return (jlong)0;
+        }
     }
 
     /*
--- a/test/java/nio/file/Files/FileAttributes.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/test/java/nio/file/Files/FileAttributes.java	Mon Mar 21 11:49:37 2011 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 6838333
+ * @bug 4313887 6838333 7017446
  * @summary Unit test for java.nio.file.Files
  * @library ..
  */
@@ -94,12 +94,6 @@
         assertTrue(map.size() == 2);
         checkEqual(attrs.size(), map.get("size"));
         checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
-
-        map = Files.readAttributes(file,
-            "basic:lastModifiedTime,lastAccessTime,ShouldNotExist");
-        assertTrue(map.size() == 2);
-        checkEqual(attrs.lastModifiedTime(), map.get("lastModifiedTime"));
-        checkEqual(attrs.lastAccessTime(), map.get("lastAccessTime"));
     }
 
     // Exercise getAttribute/setAttribute/readAttributes on posix attributes
@@ -132,7 +126,7 @@
         assertTrue(map.size() >= 12);
         checkEqual(attrs.permissions(), map.get("permissions")); // check one
 
-        map = Files.readAttributes(file, "posix:size,owner,ShouldNotExist");
+        map = Files.readAttributes(file, "posix:size,owner");
         assertTrue(map.size() == 2);
         checkEqual(attrs.size(), map.get("size"));
         checkEqual(attrs.owner(), map.get("owner"));
@@ -155,7 +149,7 @@
         map = Files.readAttributes(file, "unix:*");
         assertTrue(map.size() >= 20);
 
-        map = Files.readAttributes(file, "unix:size,uid,gid,ShouldNotExist");
+        map = Files.readAttributes(file, "unix:size,uid,gid");
         assertTrue(map.size() == 3);
         checkEqual(map.get("size"),
                    Files.readAttributes(file, BasicFileAttributes.class).size());
@@ -206,14 +200,65 @@
         assertTrue(map.size() >= 13);
         checkEqual(attrs.isReadOnly(), map.get("readonly")); // check one
 
-        map = Files.readAttributes(file, "dos:size,hidden,ShouldNotExist");
+        map = Files.readAttributes(file, "dos:size,hidden");
         assertTrue(map.size() == 2);
         checkEqual(attrs.size(), map.get("size"));
         checkEqual(attrs.isHidden(), map.get("hidden"));
     }
 
+    static void checkBadSet(Path file, String attribute, Object value)
+        throws IOException
+    {
+        try {
+            Files.setAttribute(file, attribute, 0);
+            throw new RuntimeException("IllegalArgumentException expected");
+        } catch (IllegalArgumentException ignore) { }
+    }
+
+    static void checkBadGet(Path file, String attribute) throws IOException {
+        try {
+            Files.getAttribute(file, attribute);
+            throw new RuntimeException("IllegalArgumentException expected");
+        } catch (IllegalArgumentException ignore) { }
+    }
+
+    static void checkBadRead(Path file, String attribute) throws IOException {
+        try {
+            Files.readAttributes(file, attribute);
+            throw new RuntimeException("IllegalArgumentException expected");
+        } catch (IllegalArgumentException ignore) { }
+    }
+
     static void miscTests(Path file) throws IOException {
-        // NPE tests
+        // unsupported views
+        try {
+            Files.setAttribute(file, "foo:bar", 0);
+            throw new RuntimeException("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException ignore) { }
+        try {
+            Files.getAttribute(file, "foo:bar");
+            throw new RuntimeException("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException ignore) { }
+        try {
+            Files.readAttributes(file, "foo:*");
+            throw new RuntimeException("UnsupportedOperationException expected");
+        } catch (UnsupportedOperationException ignore) { }
+
+        // bad args
+        checkBadSet(file, "", 0);
+        checkBadSet(file, "basic:", 0);
+        checkBadSet(file, "basic:foobar", 0);
+        checkBadGet(file, "");
+        checkBadGet(file, "basic:");
+        checkBadGet(file, "basic:foobar");
+        checkBadGet(file, "basic:size,lastModifiedTime");
+        checkBadGet(file, "basic:*");
+        checkBadRead(file, "");
+        checkBadRead(file, "basic:");
+        checkBadRead(file, "basic:foobar");
+        checkBadRead(file, "basic:size,foobar");
+
+        // nulls
         try {
             Files.getAttribute(file, null);
             throw new RuntimeException("NullPointerException expected");
--- a/test/java/nio/file/WatchService/Basic.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/test/java/nio/file/WatchService/Basic.java	Mon Mar 21 11:49:37 2011 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 6838333
+ * @bug 4313887 6838333 7017446
  * @summary Unit test for java.nio.file.WatchService
  * @library ..
  * @run main/timeout=120 Basic
@@ -44,6 +44,8 @@
     static void checkKey(WatchKey key, Path dir) {
         if (!key.isValid())
             throw new RuntimeException("Key is not valid");
+        if (key.watchable() != dir)
+            throw new RuntimeException("Unexpected watchable");
     }
 
     static void takeExpectedKey(WatchService watcher, WatchKey expected) {
--- a/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java	Mon Mar 21 11:31:54 2011 -0700
+++ b/test/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java	Mon Mar 21 11:49:37 2011 -0700
@@ -141,9 +141,6 @@
         map = Files.readAttributes(file, "user:*");
         if (!Arrays.equals(valueAsBytes, (byte[])map.get(ATTR_NAME)))
             throw new RuntimeException("Unexpected attribute value");
-        map = Files.readAttributes(file, "user:DoesNotExist");
-        if (!map.isEmpty())
-            throw new RuntimeException("Map expected to be empty");
     }
 
     static void miscTests(final Path file) throws IOException {