changeset 29270:0f65e3c44659

8073445: (fs) FileSystem.getPathMatcher(...) should check syntax component without regard to case Summary: Change String equals() to equalsIgnoreCase() where needed. Reviewed-by: alanb
author bpb
date Wed, 04 Mar 2015 15:05:41 -0800
parents 5f136809bb3c
children 162fe03153a4
files jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java jdk/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java jdk/test/java/nio/file/PathMatcher/Basic.java
diffstat 5 files changed, 39 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Wed Mar 04 13:22:45 2015 -0800
+++ b/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Wed Mar 04 15:05:41 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -253,10 +253,10 @@
         String syntax = syntaxAndInput.substring(0, pos);
         String input = syntaxAndInput.substring(pos + 1);
         String expr;
-        if (syntax.equals(GLOB_SYNTAX)) {
+        if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
             expr = JrtUtils.toRegexPattern(input);
         } else {
-            if (syntax.equals(REGEX_SYNTAX)) {
+            if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
                 expr = input;
             } else {
                 throw new UnsupportedOperationException("Syntax '" + syntax
--- a/jdk/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java	Wed Mar 04 13:22:45 2015 -0800
+++ b/jdk/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java	Wed Mar 04 15:05:41 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -290,10 +290,10 @@
         String input = syntaxAndInput.substring(pos+1);
 
         String expr;
-        if (syntax.equals(GLOB_SYNTAX)) {
+        if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
             expr = Globs.toUnixRegexPattern(input);
         } else {
-            if (syntax.equals(REGEX_SYNTAX)) {
+            if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
                 expr = input;
             } else {
                 throw new UnsupportedOperationException("Syntax '" + syntax +
--- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java	Wed Mar 04 13:22:45 2015 -0800
+++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java	Wed Mar 04 15:05:41 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -290,10 +290,10 @@
         String input = syntaxAndInput.substring(pos+1);
 
         String expr;
-        if (syntax.equals(GLOB_SYNTAX)) {
+        if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
             expr = Globs.toWindowsRegexPattern(input);
         } else {
-            if (syntax.equals(REGEX_SYNTAX)) {
+            if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
                 expr = input;
             } else {
                 throw new UnsupportedOperationException("Syntax '" + syntax +
--- a/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java	Wed Mar 04 13:22:45 2015 -0800
+++ b/jdk/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java	Wed Mar 04 15:05:41 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 201, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -237,10 +237,10 @@
         String syntax = syntaxAndInput.substring(0, pos);
         String input = syntaxAndInput.substring(pos + 1);
         String expr;
-        if (syntax.equals(GLOB_SYNTAX)) {
+        if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
             expr = toRegexPattern(input);
         } else {
-            if (syntax.equals(REGEX_SYNTAX)) {
+            if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
                 expr = input;
             } else {
                 throw new UnsupportedOperationException("Syntax '" + syntax +
--- a/jdk/test/java/nio/file/PathMatcher/Basic.java	Wed Mar 04 13:22:45 2015 -0800
+++ b/jdk/test/java/nio/file/PathMatcher/Basic.java	Wed Mar 04 15:05:41 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4313887 6866397
+ * @bug 4313887 6866397 8073445
  * @summary Unit test for java.nio.file.PathMatcher
  */
 
@@ -173,6 +173,31 @@
             System.out.println(" OKAY");
         }
 
+        // GLOB_SYNTAX case sensitivity of getPathMatcher: should not throw UOE
+        try {
+            FileSystems.getDefault().getPathMatcher("glob:java");
+            FileSystems.getDefault().getPathMatcher("Glob:java");
+            FileSystems.getDefault().getPathMatcher("GLOB:java");
+            System.out.println("Test GLOB_SYNTAX case sensitivity OKAY");
+        } catch (UnsupportedOperationException e) {
+            System.err.println("getPathMatcher GLOB_SYNTAX case sensitivity");
+            e.printStackTrace();
+            failures++;
+        }
+
+        // REGEX_SYNTAX case sensitivity of getPathMatcher: should not throw UOE
+        try {
+            FileSystems.getDefault().getPathMatcher("regex:java");
+            FileSystems.getDefault().getPathMatcher("Regex:java");
+            FileSystems.getDefault().getPathMatcher("RegEx:java");
+            FileSystems.getDefault().getPathMatcher("REGEX:java");
+            System.out.println("Test REGEX_SYNTAX case sensitivity OKAY");
+        } catch (UnsupportedOperationException e) {
+            System.err.println("getPathMatcher REGEX_SYNTAX case sensitivity");
+            e.printStackTrace();
+            failures++;
+        }
+
         if (failures > 0)
             throw new RuntimeException(failures +
                 " sub-test(s) failed - see log for details");