# HG changeset patch # User bpb # Date 1425497120 28800 # Wed Mar 04 11:25:20 2015 -0800 # Node ID 6a0b1147b35969c50149ccdaa9d5e2eee1596c1d # Parent 0c85e7c7addaacc0d63b8da2dc1f3b054995a9ef 8073445: (fs) FileSystem.getPathMatcher(...) should check syntax component without regard to case Summary: Change String equals() to equalsIgnoreCase() where needed. Reviewed-by: alanb diff --git a/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java b/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java --- a/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java +++ b/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java @@ -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 diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java b/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java --- a/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java @@ -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 + diff --git a/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java b/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java --- a/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java +++ b/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystem.java @@ -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 + diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -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 + diff --git a/test/java/nio/file/PathMatcher/Basic.java b/test/java/nio/file/PathMatcher/Basic.java --- a/test/java/nio/file/PathMatcher/Basic.java +++ b/test/java/nio/file/PathMatcher/Basic.java @@ -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,46 @@ System.out.println(" OKAY"); } + // GLOB_SYNTAX case sensitivity of getPathMatcher: should not throw UOE + Path foobar = Paths.get("/foo", "bar"); + try { + PathMatcher pmGlob = + FileSystems.getDefault().getPathMatcher("glob:java"); + pmGlob = FileSystems.getDefault().getPathMatcher("Glob:java"); + pmGlob = FileSystems.getDefault().getPathMatcher("GLOB:java"); + // next three lines to avoid unused variable complaints about + // 'pmGlob' and any possibility of things eventually being + // optimized out + if (pmGlob.matches(Paths.get("/foo", "bar"))) { + System.out.println("pmGlob matches foobar!"); + } + 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 { + PathMatcher pmRegex = + FileSystems.getDefault().getPathMatcher("regex:java"); + pmRegex = FileSystems.getDefault().getPathMatcher("Regex:java"); + pmRegex = FileSystems.getDefault().getPathMatcher("RegEx:java"); + pmRegex = FileSystems.getDefault().getPathMatcher("REGEX:java"); + // next three lines to avoid unused variable complaints about + // 'pmRegex' and any possibility of things eventually being + // optimized out + if (pmRegex.matches(Paths.get("/foo", "bar"))) { + System.out.println("pmRegex matches foobar!"); + } + 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");