JDK-4983802 : Cleanups in src/windows/native/java/io/io_util_md.c
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_98
  • CPU: generic
  • Submitted: 2004-01-27
  • Updated: 2005-09-17
  • Resolved: 2005-09-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b53Fixed
Related Reports
Relates :  
Description
This code is a no-op because O_RDONLY is 0:
    if (flags & O_RDONLY) {
	access = GENERIC_READ;
    }

The variable `pathlen' is unused.

The code could benefit from a little bit of cleanup for maintainability.
###@###.### 2004-01-26

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
14-06-2004

SUGGESTED FIX --- /u/martin/ws/mustang/src/windows/native/java/io/io_util_md.c 2005-02-07 15:40:18.950931000 -0800 +++ /u/martin/ws/io_util/src/windows/native/java/io/io_util_md.c 2005-09-03 20:26:51.463988000 -0700 @@ -162,37 +162,22 @@ void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags) { - DWORD access = 0; - DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE; - DWORD disposition = OPEN_EXISTING; - DWORD flagsAndAttributes = FILE_ATTRIBUTE_NORMAL; - HANDLE h = NULL; - int pathlen = 0; - + const DWORD access = + (flags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) : + (flags & O_WRONLY) ? GENERIC_WRITE : + GENERIC_READ; + const DWORD sharing = + FILE_SHARE_READ | FILE_SHARE_WRITE; + const DWORD disposition = /* Note: O_TRUNC overrides O_CREAT */ - if (flags & O_TRUNC) { - disposition = CREATE_ALWAYS; - } else if (flags & O_CREAT) { - disposition = OPEN_ALWAYS; - } - if (flags & O_SYNC) { - flagsAndAttributes = FILE_FLAG_WRITE_THROUGH; - } - if (flags & O_DSYNC) { - flagsAndAttributes = FILE_FLAG_WRITE_THROUGH; - } - if (flags & O_RDONLY) { - access = GENERIC_READ; - } - if (flags & O_WRONLY) { - access = GENERIC_WRITE; - } - if (flags & O_RDWR) { - access = GENERIC_READ | GENERIC_WRITE; - } - if (flags == 0) { - access = GENERIC_READ; - } + (flags & O_TRUNC) ? CREATE_ALWAYS : + (flags & O_CREAT) ? OPEN_ALWAYS : + OPEN_EXISTING; + const DWORD flagsAndAttributes = + (flags & (O_SYNC | O_DSYNC)) ? + FILE_FLAG_WRITE_THROUGH : + FILE_ATTRIBUTE_NORMAL; + HANDLE h = NULL; if (onNT) { WCHAR *pathbuf = pathToNTPath(env, path, JNI_TRUE); @@ -203,7 +188,7 @@ h = CreateFileW( pathbuf, /* Wide char path name */ - access, /* Combine read and/or write permission */ + access, /* Read and/or write permission */ sharing, /* File sharing flags */ NULL, /* Security attributes */ disposition, /* creation disposition */
11-06-2004

PUBLIC COMMENTS -
10-06-2004

EVALUATION For early mustang. ###@###.### 2004-01-26
26-01-2004