changeset 45893:2678b360eecd

8184807: (ch) Clean up handling of some Windows function return values in libnio Summary: Properly check and respond to Windows function return values in libnio Reviewed-by: alanb
author bpb
date Tue, 18 Jul 2017 17:56:52 -0700
parents 0b9499e86ee6
children 995421c69f66
files jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c jdk/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c
diffstat 3 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c	Tue Jul 18 12:40:30 2017 +0200
+++ b/jdk/src/java.base/windows/native/libnio/ch/FileChannelImpl.c	Tue Jul 18 17:56:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, 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
@@ -170,8 +170,8 @@
 {
     HANDLE h = (HANDLE)(handleval(env, fdo));
     if (h != INVALID_HANDLE_VALUE) {
-        jint result = CloseHandle(h);
-        if (result < 0) {
+        BOOL result = CloseHandle(h);
+        if (result == 0) {
             JNU_ThrowIOExceptionWithLastError(env, "Close failed");
         }
     }
--- a/jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c	Tue Jul 18 12:40:30 2017 +0200
+++ b/jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c	Tue Jul 18 17:56:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, 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
@@ -334,7 +334,7 @@
                                         FileEndOfFileInfo,
                                         &eofInfo,
                                         sizeof(eofInfo));
-    if (result == FALSE) {
+    if (result == 0) {
         JNU_ThrowIOExceptionWithLastError(env, "Truncation failed");
         return IOS_THROWN;
     }
@@ -411,7 +411,7 @@
     long highPos = (long)(pos >> 32);
     DWORD lowNumBytes = (DWORD)size;
     DWORD highNumBytes = (DWORD)(size >> 32);
-    jint result = 0;
+    BOOL result = 0;
     OVERLAPPED o;
     o.hEvent = 0;
     o.Offset = lowPos;
@@ -422,7 +422,7 @@
         if (error == ERROR_IO_PENDING) {
             DWORD dwBytes;
             result = GetOverlappedResult(h, &o, &dwBytes, TRUE);
-            if (result == 0) {
+            if (result != 0) {
                 return;
             }
             error = GetLastError();
@@ -437,7 +437,7 @@
     HANDLE h = (HANDLE)fd;
     if (h != INVALID_HANDLE_VALUE) {
         int result = CloseHandle(h);
-        if (result < 0)
+        if (result == 0)
             JNU_ThrowIOExceptionWithLastError(env, "Close failed");
     }
 }
--- a/jdk/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c	Tue Jul 18 12:40:30 2017 +0200
+++ b/jdk/src/java.base/windows/native/libnio/ch/WindowsAsynchronousFileChannelImpl.c	Tue Jul 18 17:56:52 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, 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
@@ -126,5 +126,8 @@
     jlong handle)
 {
     HANDLE h = (HANDLE)jlong_to_ptr(handle);
-    CloseHandle(h);
+    BOOL result = CloseHandle(h);
+    if (result == 0) {
+        JNU_ThrowIOExceptionWithLastError(env, "Close failed");
+    }
 }