Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private WindowsConstants() { }
public static final int ERROR_NOT_SAME_DEVICE = 17;
public static final int ERROR_NOT_READY = 21;
public static final int ERROR_SHARING_VIOLATION = 32;
public static final int ERROR_NETWORK_ACCESS_DENIED = 65;
public static final int ERROR_FILE_EXISTS = 80;
public static final int ERROR_INVALID_PARAMETER = 87;
public static final int ERROR_DISK_FULL = 112;
Expand Down
31 changes: 16 additions & 15 deletions src/java.base/windows/classes/sun/nio/fs/WindowsException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2025, 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
Expand Down Expand Up @@ -76,20 +76,21 @@ public Throwable fillInStackTrace() {
}

private IOException translateToIOException(String file, String other) {
// not created with last error
if (lastError() == 0)
return new IOException(errorString());

// handle specific cases
if (lastError() == ERROR_FILE_NOT_FOUND || lastError() == ERROR_PATH_NOT_FOUND)
return new NoSuchFileException(file, other, null);
if (lastError() == ERROR_FILE_EXISTS || lastError() == ERROR_ALREADY_EXISTS)
return new FileAlreadyExistsException(file, other, null);
if (lastError() == ERROR_ACCESS_DENIED)
return new AccessDeniedException(file, other, null);

// fallback to the more general exception
return new FileSystemException(file, other, errorString());
return switch (lastError()) {
// not created with last error
case 0 -> new IOException(errorString());

// handle specific cases
case ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND
-> new NoSuchFileException(file, other, null);
case ERROR_FILE_EXISTS, ERROR_ALREADY_EXISTS
-> new FileAlreadyExistsException(file, other, null);
case ERROR_ACCESS_DENIED, ERROR_NETWORK_ACCESS_DENIED, ERROR_PRIVILEGE_NOT_HELD
-> new AccessDeniedException(file, other, null);

// fallback to the more general exception
default -> new FileSystemException(file, other, errorString());
};
}

void rethrowAsIOException(String file) throws IOException {
Expand Down