1 /* 2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.nio.file; 27 28 import java.util.ConcurrentModificationException; 29 import java.util.Objects; 30 import java.io.IOException; 31 import java.io.ObjectInputStream; 32 import java.io.InvalidObjectException; 33 34 /** 35 * Runtime exception thrown if an I/O error is encountered when iterating over 36 * the entries in a directory. The I/O error is retrieved as an {@link 37 * IOException} using the {@link #getCause() getCause()} method. 38 * 39 * @since 1.7 40 * @see DirectoryStream 41 */ 42 43 public final class DirectoryIteratorException 44 extends ConcurrentModificationException 45 { 46 @java.io.Serial 47 private static final long serialVersionUID = -6012699886086212874L; 48 49 /** 50 * Constructs an instance of this class. 51 * 52 * @param cause 53 * the {@code IOException} that caused the directory iteration 54 * to fail 55 * 56 * @throws NullPointerException 57 * if the cause is {@code null} 58 */ 59 public DirectoryIteratorException(IOException cause) { 60 super(Objects.requireNonNull(cause)); 61 } 62 63 /** 64 * Returns the cause of this exception. 65 * 66 * @return the cause 67 */ 68 @Override 69 public IOException getCause() { 70 return (IOException)super.getCause(); 71 } 72 73 /** 74 * Called to read the object from a stream. 75 * 76 * @throws InvalidObjectException 77 * if the object is invalid or has a cause that is not 78 * an {@code IOException} 79 */ 80 @java.io.Serial 81 private void readObject(ObjectInputStream s) 82 throws IOException, ClassNotFoundException 83 { 84 s.defaultReadObject(); 85 Throwable cause = super.getCause(); 86 if (!(cause instanceof IOException)) 87 throw new InvalidObjectException("Cause must be an IOException"); 88 } 89 }