3471N/A/*
3471N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3471N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3471N/A *
3471N/A * This code is free software; you can redistribute it and/or modify it
3471N/A * under the terms of the GNU General Public License version 2 only, as
3471N/A * published by the Free Software Foundation.
3471N/A *
3471N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3471N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3471N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3471N/A * version 2 for more details (a copy is included in the LICENSE file that
3471N/A * accompanied this code).
3471N/A *
3471N/A * You should have received a copy of the GNU General Public License version
3471N/A * 2 along with this work; if not, write to the Free Software Foundation,
3471N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3471N/A *
3471N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3471N/A * or visit www.oracle.com if you need additional information or have any
3471N/A * questions.
3471N/A */
3471N/A
3471N/A/* @test
3471N/A * @bug 4313887 6865748
3471N/A * @summary Unit test for java.nio.file.Files.walkFileTree
3471N/A */
3471N/A
3471N/Aimport java.nio.file.*;
3471N/Aimport java.nio.file.attribute.BasicFileAttributes;
3471N/Aimport java.io.IOException;
3471N/Aimport java.util.*;
3471N/A
3471N/Apublic class Nulls {
3471N/A
3471N/A static void npeExpected() {
3471N/A throw new RuntimeException("NullPointerException expected");
3471N/A }
3471N/A
3471N/A public static void main(String[] args) throws IOException {
3471N/A try {
3471N/A Files.walkFileTree(null, EnumSet.noneOf(FileVisitOption.class),
3471N/A Integer.MAX_VALUE, new SimpleFileVisitor<Path>(){});
3471N/A npeExpected();
3471N/A } catch (NullPointerException e) {
3471N/A }
3471N/A try {
3471N/A Files.walkFileTree(Paths.get("."), null, Integer.MAX_VALUE,
3471N/A new SimpleFileVisitor<Path>(){});
3471N/A npeExpected();
3471N/A } catch (NullPointerException e) {
3471N/A }
3471N/A try {
3471N/A Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class),
3471N/A -1, new SimpleFileVisitor<Path>(){});
3471N/A throw new RuntimeException("IllegalArgumentExpected expected");
3471N/A } catch (IllegalArgumentException e) {
3471N/A }
3471N/A try {
3471N/A Set<FileVisitOption> opts = new HashSet<>(1);
3471N/A opts.add(null);
3471N/A Files.walkFileTree(Paths.get("."), opts, Integer.MAX_VALUE,
3471N/A new SimpleFileVisitor<Path>(){});
3471N/A npeExpected();
3471N/A } catch (NullPointerException e) {
3471N/A }
3471N/A try {
3471N/A Files.walkFileTree(Paths.get("."), EnumSet.noneOf(FileVisitOption.class),
3471N/A Integer.MAX_VALUE, null);
3471N/A npeExpected();
3471N/A } catch (NullPointerException e) {
3471N/A }
3471N/A
3471N/A SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { };
3471N/A boolean ranTheGauntlet = false;
3471N/A Path dir = Paths.get(".");
3471N/A BasicFileAttributes attrs = Files.readAttributes(dir, BasicFileAttributes.class);
3471N/A
3471N/A try { visitor.preVisitDirectory(null, attrs);
3471N/A } catch (NullPointerException x0) {
3471N/A try { visitor.preVisitDirectory(dir, null);
3471N/A } catch (NullPointerException x1) {
3471N/A try { visitor.visitFile(null, attrs);
3471N/A } catch (NullPointerException x2) {
3471N/A try { visitor.visitFile(dir, null);
3471N/A } catch (NullPointerException x3) {
3471N/A try { visitor.visitFileFailed(null, new IOException());
3471N/A } catch (NullPointerException x4) {
3471N/A try { visitor.visitFileFailed(dir, null);
3471N/A } catch (NullPointerException x5) {
3471N/A try { visitor.postVisitDirectory(null, new IOException());
3471N/A } catch (NullPointerException x6) {
3471N/A // if we get here then all visit* methods threw NPE as expected
3471N/A ranTheGauntlet = true;
3471N/A }}}}}}}
3471N/A if (!ranTheGauntlet)
3471N/A throw new RuntimeException("A visit method did not throw NPE");
3471N/A }
3471N/A}