From b1c4a6ff3f9819eff1dfafc35ed02a402f0a7c68 Mon Sep 17 00:00:00 2001 From: Tomas Hurka Date: Wed, 7 Jan 2009 14:06:04 +0100 Subject: [PATCH 1/5] 6790467: Add test for setInterval() for local MonitoredHost and local MonitoredVm Test for MonitoredHost.setInterval() and MonitoredVm.setInterval() added Reviewed-by: swamyv --- .../monitor/MonitoredVm/CR6672135.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 jdk/test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java diff --git a/jdk/test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java b/jdk/test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java new file mode 100644 index 00000000000..9a75f3da644 --- /dev/null +++ b/jdk/test/sun/jvmstat/monitor/MonitoredVm/CR6672135.java @@ -0,0 +1,71 @@ +/* + * Copyright 2004 Sun Microsystems, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.net.URISyntaxException; +import java.util.Set; +import sun.jvmstat.monitor.MonitorException; +import sun.jvmstat.monitor.MonitoredHost; +import sun.jvmstat.monitor.MonitoredVm; +import sun.jvmstat.monitor.VmIdentifier; + +/** + * + * @test + * @bug 6672135 + * @summary setInterval() for local MonitoredHost and local MonitoredVm + * @author Tomas Hurka + */ +public class CR6672135 { + + private static final int INTERVAL = 2000; + + public static void main(String[] args) { + int vmInterval; + int hostInterval; + + try { + MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost"); + Set vms = localHost.activeVms(); + Integer vmInt = (Integer) vms.iterator().next(); + String uriString = "//" + vmInt + "?mode=r"; // NOI18N + VmIdentifier vmId = new VmIdentifier(uriString); + MonitoredVm vm = localHost.getMonitoredVm(vmId); + + vm.setInterval(INTERVAL); + localHost.setInterval(INTERVAL); + vmInterval = vm.getInterval(); + hostInterval = localHost.getInterval(); + } catch (Exception ex) { + throw new Error ("Test failed",ex); + } + System.out.println("VM "+vmInterval); + if (vmInterval != INTERVAL) { + throw new Error("Test failed"); + } + System.out.println("Host "+hostInterval); + if (hostInterval != INTERVAL) { + throw new Error("Test failed"); + } + } +} + From 95f522244519b01732d8ebd15cba84a7c406f242 Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Wed, 7 Jan 2009 11:50:32 -0800 Subject: [PATCH 2/5] 6788196: (porting) Bounds checks in io_util.c rely on undefined behaviour Reviewed-by: alanb --- jdk/src/share/native/java/io/io_util.c | 24 ++- .../java/io/readBytes/ReadBytesBounds.java | 151 +++++++----------- 2 files changed, 76 insertions(+), 99 deletions(-) diff --git a/jdk/src/share/native/java/io/io_util.c b/jdk/src/share/native/java/io/io_util.c index 52450307a16..547ff5a6504 100644 --- a/jdk/src/share/native/java/io/io_util.c +++ b/jdk/src/share/native/java/io/io_util.c @@ -58,12 +58,24 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) { */ #define BUF_SIZE 8192 +/* + * Returns true if the array slice defined by the given offset and length + * is out of bounds. + */ +static int +outOfBounds(JNIEnv *env, jint off, jint len, jbyteArray array) { + return ((off < 0) || + (len < 0) || + // We are very careful to avoid signed integer overflow, + // the result of which is undefined in C. + ((*env)->GetArrayLength(env, array) - off < len)); +} int readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, jint len, jfieldID fid) { - int nread, datalen; + int nread; char stackBuf[BUF_SIZE]; char *buf = 0; FD fd; @@ -72,10 +84,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, JNU_ThrowNullPointerException(env, 0); return -1; } - datalen = (*env)->GetArrayLength(env, bytes); - if ((off < 0) || (off > datalen) || - (len < 0) || ((off + len) > datalen) || ((off + len) < 0)) { + if (outOfBounds(env, off, len, bytes)) { JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0); return -1; } @@ -136,7 +146,7 @@ void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, jint len, jfieldID fid) { - int n, datalen; + int n; char stackBuf[BUF_SIZE]; char *buf = 0; FD fd; @@ -145,10 +155,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, JNU_ThrowNullPointerException(env, 0); return; } - datalen = (*env)->GetArrayLength(env, bytes); - if ((off < 0) || (off > datalen) || - (len < 0) || ((off + len) > datalen) || ((off + len) < 0)) { + if (outOfBounds(env, off, len, bytes)) { JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0); return; } diff --git a/jdk/test/java/io/readBytes/ReadBytesBounds.java b/jdk/test/java/io/readBytes/ReadBytesBounds.java index 75b0a311998..d0671585631 100644 --- a/jdk/test/java/io/readBytes/ReadBytesBounds.java +++ b/jdk/test/java/io/readBytes/ReadBytesBounds.java @@ -22,107 +22,76 @@ */ /* - @test - @bug 4017728 4079849 - @summary Check for correct Array Bounds check in read of FileInputStream and - RandomAccessFile - */ + * @test + * @bug 4017728 4079849 6788196 + * @summary Check for correct Array Bounds check in read of FileInputStream and + * RandomAccessFile + */ import java.io.*; - /* - * The test calls the read(byte buf[] , int off , int len) of FileInputStream with - * different values of off and len to see if the ArrayOutOfBoundsException is - * thrown according to the JLS1.0 specification. The read(...) method calls - * readBytes(...) in native code(io_util.c). The read(...) method in RandomAccessFile - * also calls the same native method. So one should see similar results. + * The test calls the read(byte buf[] , int off , int len) of + * FileInputStream with different values of off and len to see if the + * IndexOutOfBoundsException is thrown. The read(...) method calls + * readBytes(...) in native code(io_util.c). The read(...) method in + * RandomAccessFile also calls the same native method. So one should + * see similar results. */ - public class ReadBytesBounds { - public static void main(String argv[]) throws Exception{ - - int num_test_cases = 12; - int off[] = {-1 , -1 , 0 , 0 , 33 , 33 , 0 , 32 , 32 , 4 , 1 , 0}; - int len[] = {-1 , 0 , -1 , 33 , 0 , 4 , 32 , 0 , 4 , 16 , 31 , 0}; - boolean results[] = { false , false , false , false , false , false , - true , true , false , true , true , true}; - - - FileInputStream fis = null; - RandomAccessFile raf = null; - byte b[] = new byte[32]; - - int num_good = 0; - int num_bad = 0; - - String dir = System.getProperty("test.src", "."); - File testFile = new File(dir, "input.txt"); - fis = new FileInputStream(testFile); - for(int i = 0; i < num_test_cases; i++) { - - try { - int bytes_read = fis.read(b , off[i] , len[i]); - } catch(IndexOutOfBoundsException aiobe) { - if (results[i]) { - throw new RuntimeException("Unexpected result"); - } - else { - num_good++; - } - continue; - } - - if (results[i]) { - num_good++; - } - else { - throw new RuntimeException("Unexpected result"); - } + static final FileInputStream fis; + static final RandomAccessFile raf; + static final byte[] b = new byte[32]; + static { + try { + String dir = System.getProperty("test.src", "."); + File testFile = new File(dir, "input.txt"); + fis = new FileInputStream(testFile); + raf = new RandomAccessFile(testFile , "r"); + } catch (Throwable t) { + throw new Error(t); } - System.out.println("Results for FileInputStream.read"); - System.out.println("\nTotal number of test cases = " + num_test_cases + - "\nNumber succeded = " + num_good + - "\nNumber failed = " + num_bad); - - - - num_good = 0; - num_bad = 0; - - raf = new RandomAccessFile(testFile , "r"); - for(int i = 0; i < num_test_cases; i++) { - - try { - int bytes_read = raf.read(b , off[i] , len[i]); - } catch(IndexOutOfBoundsException aiobe) { - if (results[i]) { - throw new RuntimeException("Unexpected result"); - } - else { - num_good++; - } - continue; - } - - if (results[i]) { - num_good++; - } - else { - throw new RuntimeException("Unexpected result"); - } - - } - - System.out.println("Results for RandomAccessFile.read"); - System.out.println("\nTotal number of test cases = " + num_test_cases + - "\nNumber succeded = " + num_good + - "\nNumber failed = " + num_bad); - - } + public static void main(String argv[]) throws Throwable { + byte b[] = new byte[32]; + testRead(-1, -1, false); + testRead(-1, 0, false); + testRead( 0, -1, false); + testRead( 0, 33, false); + testRead(33, 0, false); + testRead(33, 4, false); + testRead( 0, 32, true); + testRead(32, 0, true); + testRead(32, 4, false); + testRead( 4, 16, true); + testRead( 1, 31, true); + testRead( 0, 0, true); + testRead(31, Integer.MAX_VALUE, false); + testRead( 0, Integer.MAX_VALUE, false); + testRead(-1, Integer.MAX_VALUE, false); + testRead(-4, Integer.MIN_VALUE, false); + testRead( 0, Integer.MIN_VALUE, false); + } + + static void testRead(int off, int len, boolean expected) throws Throwable { + System.err.printf("off=%d len=%d expected=%b%n", off, len, expected); + boolean result; + try { + fis.read(b, off, len); + raf.read(b, off, len); + result = true; + } catch (IndexOutOfBoundsException e) { + result = false; + } + + if (result != expected) { + throw new RuntimeException + (String.format("Unexpected result off=%d len=%d expected=%b", + off, len, expected)); + } + } } From 3849600cdd854b6ad70c460f381a2641b344f386 Mon Sep 17 00:00:00 2001 From: Bhavesh Patel Date: Wed, 7 Jan 2009 16:39:43 -0800 Subject: [PATCH 3/5] 6790217: Javadoc HTML WCAG 2.0 accessibility issues in jdk docs makefile - Bold tags should be strong Reviewed-by: jjg --- jdk/make/docs/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jdk/make/docs/Makefile b/jdk/make/docs/Makefile index 21d7825d3a5..07fe50e6416 100644 --- a/jdk/make/docs/Makefile +++ b/jdk/make/docs/Makefile @@ -64,7 +64,7 @@ CORE_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -bottom $(JAVADOCBOTTOM_SWITCH) \ $(OVERVIEW_OPTION) -DRAFT = '
DRAFT '$(MILESTONE)-$(BUILD_NUMBER)'' +DRAFT = '
DRAFT '$(MILESTONE)-$(BUILD_NUMBER)'' THIS_YEAR := $(shell $(DATE) | $(SED) -e 's/ / /g' | $(CUT) -d' ' -f6) TRADEMARK = &\#x2122; @@ -95,7 +95,7 @@ endif JAVADOCTITLE = 'Java$(TRADEMARK) Platform, Standard Edition $(JDK_MINOR_VERSION)
API Specification' JAVADOCWINDOWTITLE = 'Java Platform SE $(JDK_MINOR_VERSION)' -JAVADOCHEADER = 'Java$(TRADEMARK) Platform
Standard Ed. $(JDK_MINOR_VERSION)
' +JAVADOCHEADER = 'Java$(TRADEMARK) Platform
Standard Ed. $(JDK_MINOR_VERSION)
' JAVADOCBOTTOM = 'Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms. Also see the documentation redistribution policy.' JAVADOCOVERVIEW = $(SHARE_SRC)/classes/overview-core.html @@ -120,7 +120,7 @@ DOMAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -group $(DOMAPI_GROUPNAME) $(DOMAPI_REGEXP) DOMAPI_JAVADOCTITLE = 'Common DOM API' DOMAPI_JAVADOCWINDOWTITLE = 'Common DOM API' -DOMAPI_JAVADOCHEADER = 'Common DOM API' +DOMAPI_JAVADOCHEADER = 'Common DOM API' DOMAPI_JAVADOCBOTTOM = 'Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright $(THIS_YEAR) Sun Microsystems, Inc. 4150 Network Circle
Santa Clara, California, 95054, U.S.A. All Rights Reserved.
' DOMAPI_GROUPNAME = "Packages" DOMAPI_REGEXP = "com.sun.java.browser.dom:org.w3c.dom*" @@ -140,7 +140,7 @@ MIRROR_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -overview $(MIRROR_OVERVIEW) MIRROR_JAVADOCTITLE = 'Mirror API' MIRROR_JAVADOCWINDOWTITLE = 'Mirror API' -MIRROR_JAVADOCHEADER = 'Mirror API' +MIRROR_JAVADOCHEADER = 'Mirror API' MIRROR_JAVADOCBOTTOM = 'Report a bug or request a feature.
Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.
' MIRROR_GROUPNAME = "Packages" MIRROR_OVERVIEW = $(IMPORTSRCDIR)/com/sun/mirror/overview.html @@ -163,7 +163,7 @@ DOCLETAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ -group $(DOCLETAPI_GROUPNAME) $(DOCLETAPI_REGEXP) DOCLETAPI_JAVADOCTITLE = 'Doclet API' DOCLETAPI_JAVADOCWINDOWTITLE = 'Doclet API' -DOCLETAPI_JAVADOCHEADER = 'Doclet API' +DOCLETAPI_JAVADOCHEADER = 'Doclet API' DOCLETAPI_JAVADOCBOTTOM = 'Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-$(THIS_YEAR) Sun Microsystems, Inc. 4150 Network Circle
Santa Clara, California, 95054, U.S.A. All Rights Reserved.
' DOCLETAPI_GROUPNAME = "Packages" DOCLETAPI_REGEXP = "com.sun.javadoc" @@ -407,7 +407,7 @@ TREEAPI_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS) \ # TREEAPI_JAVADOCTITLE = 'Compiler Tree API' TREEAPI_JAVADOCWINDOWTITLE = 'Compiler Tree API' -TREEAPI_JAVADOCHEADER = 'Compiler Tree API' +TREEAPI_JAVADOCHEADER = 'Compiler Tree API' TREEAPI_JAVADOCBOTTOM = 'Report a bug or request a feature.
Copyright $(THIS_YEAR) Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.
' TREEAPI_GROUPNAME = "Packages" TREEAPI_OVERVIEW = $(SHARE_SRC)/classes/com/sun/source/overview.html From e8974fee90a38d406e281171e4bf521af6ef561f Mon Sep 17 00:00:00 2001 From: Jeremy Manson Date: Thu, 8 Jan 2009 14:07:45 -0800 Subject: [PATCH 4/5] 6791458: FileInputStream/RandomAccessFile.read leaks memory if invoked on closed stream with len > 8k Reviewed-by: alanb --- jdk/src/share/native/java/io/io_util.c | 22 +++++----- jdk/test/java/io/readBytes/MemoryLeak.java | 51 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 jdk/test/java/io/readBytes/MemoryLeak.java diff --git a/jdk/src/share/native/java/io/io_util.c b/jdk/src/share/native/java/io/io_util.c index 547ff5a6504..c5ca5334fbd 100644 --- a/jdk/src/share/native/java/io/io_util.c +++ b/jdk/src/share/native/java/io/io_util.c @@ -105,18 +105,18 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, fd = GET_FD(this, fid); if (fd == -1) { JNU_ThrowIOException(env, "Stream Closed"); - return -1; - } - - nread = IO_Read(fd, buf, len); - if (nread > 0) { - (*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf); - } else if (nread == JVM_IO_ERR) { - JNU_ThrowIOExceptionWithLastError(env, "Read error"); - } else if (nread == JVM_IO_INTR) { /* EOF */ - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); - } else { /* EOF */ nread = -1; + } else { + nread = IO_Read(fd, buf, len); + if (nread > 0) { + (*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf); + } else if (nread == JVM_IO_ERR) { + JNU_ThrowIOExceptionWithLastError(env, "Read error"); + } else if (nread == JVM_IO_INTR) { /* EOF */ + JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + } else { /* EOF */ + nread = -1; + } } if (buf != stackBuf) { diff --git a/jdk/test/java/io/readBytes/MemoryLeak.java b/jdk/test/java/io/readBytes/MemoryLeak.java new file mode 100644 index 00000000000..6fa0c0313a9 --- /dev/null +++ b/jdk/test/java/io/readBytes/MemoryLeak.java @@ -0,0 +1,51 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6791458 + * @summary Reading from closed input files leaks native memory + */ + +import java.io.*; + +public class MemoryLeak { + public static void main(String[] args) throws Throwable { + byte[] bytes = new byte[1 << 20]; + String dir = System.getProperty("test.src", "."); + File testFile = new File(dir, "input.txt"); + FileInputStream s = new FileInputStream(testFile); + s.close(); + for (int i = 0; i < 10000; i++) { + try { + s.read(bytes); + throw new Error("expected IOException"); + } catch (IOException _) { + /* OK */ + } catch (OutOfMemoryError oome) { + System.out.printf("Got OutOfMemoryError, i=%d%n", i); + throw oome; + } + } + } +} From 1db3e0312e5b190cab028103c7257298af40edcd Mon Sep 17 00:00:00 2001 From: Martin Buchholz Date: Fri, 9 Jan 2009 16:48:46 -0800 Subject: [PATCH 5/5] 6792066: src/share/native/java/io/io_util.c clean-ups Reviewed-by: alanb --- jdk/src/share/native/java/io/io_util.c | 60 +++++++++++++------------- jdk/src/share/native/java/io/io_util.h | 6 +-- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/jdk/src/share/native/java/io/io_util.c b/jdk/src/share/native/java/io/io_util.c index c5ca5334fbd..144287bb758 100644 --- a/jdk/src/share/native/java/io/io_util.c +++ b/jdk/src/share/native/java/io/io_util.c @@ -25,6 +25,7 @@ #include #include +#include #include "jni.h" #include "jni_util.h" @@ -34,9 +35,9 @@ /* IO helper functions */ -int +jint readSingle(JNIEnv *env, jobject this, jfieldID fid) { - int nread; + jint nread; char ret; FD fd = GET_FD(this, fid); if (fd == -1) { @@ -49,7 +50,7 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) { } else if (nread == JVM_IO_ERR) { /* error */ JNU_ThrowIOExceptionWithLastError(env, "Read error"); } else if (nread == JVM_IO_INTR) { - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL); } return ret & 0xFF; } @@ -71,22 +72,22 @@ outOfBounds(JNIEnv *env, jint off, jint len, jbyteArray array) { ((*env)->GetArrayLength(env, array) - off < len)); } -int +jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, jint len, jfieldID fid) { - int nread; + jint nread; char stackBuf[BUF_SIZE]; - char *buf = 0; + char *buf = NULL; FD fd; if (IS_NULL(bytes)) { - JNU_ThrowNullPointerException(env, 0); + JNU_ThrowNullPointerException(env, NULL); return -1; } if (outOfBounds(env, off, len, bytes)) { - JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0); + JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL); return -1; } @@ -94,8 +95,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, return 0; } else if (len > BUF_SIZE) { buf = malloc(len); - if (buf == 0) { - JNU_ThrowOutOfMemoryError(env, 0); + if (buf == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); return 0; } } else { @@ -112,8 +113,8 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, (*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf); } else if (nread == JVM_IO_ERR) { JNU_ThrowIOExceptionWithLastError(env, "Read error"); - } else if (nread == JVM_IO_INTR) { /* EOF */ - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + } else if (nread == JVM_IO_INTR) { + JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL); } else { /* EOF */ nread = -1; } @@ -127,8 +128,9 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, void writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid) { - char c = byte; - int n; + // Discard the 24 high-order bits of byte. See OutputStream#write(int) + char c = (char) byte; + jint n; FD fd = GET_FD(this, fid); if (fd == -1) { JNU_ThrowIOException(env, "Stream Closed"); @@ -138,26 +140,26 @@ writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid) { if (n == JVM_IO_ERR) { JNU_ThrowIOExceptionWithLastError(env, "Write error"); } else if (n == JVM_IO_INTR) { - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL); } } void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, - jint off, jint len, jfieldID fid) + jint off, jint len, jfieldID fid) { - int n; + jint n; char stackBuf[BUF_SIZE]; - char *buf = 0; + char *buf = NULL; FD fd; if (IS_NULL(bytes)) { - JNU_ThrowNullPointerException(env, 0); + JNU_ThrowNullPointerException(env, NULL); return; } if (outOfBounds(env, off, len, bytes)) { - JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", 0); + JNU_ThrowByName(env, "java/lang/IndexOutOfBoundsException", NULL); return; } @@ -165,8 +167,8 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, return; } else if (len > BUF_SIZE) { buf = malloc(len); - if (buf == 0) { - JNU_ThrowOutOfMemoryError(env, 0); + if (buf == NULL) { + JNU_ThrowOutOfMemoryError(env, NULL); return; } } else { @@ -188,7 +190,7 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, JNU_ThrowIOExceptionWithLastError(env, "Write error"); break; } else if (n == JVM_IO_INTR) { - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + JNU_ThrowByName(env, "java/io/InterruptedIOException", NULL); break; } off += n; @@ -204,19 +206,19 @@ void throwFileNotFoundException(JNIEnv *env, jstring path) { char buf[256]; - int n; + jint n; jobject x; jstring why = NULL; n = JVM_GetLastErrorString(buf, sizeof(buf)); if (n > 0) { - why = JNU_NewStringPlatform(env, buf); + why = JNU_NewStringPlatform(env, buf); } x = JNU_NewObjectByName(env, - "java/io/FileNotFoundException", - "(Ljava/lang/String;Ljava/lang/String;)V", - path, why); + "java/io/FileNotFoundException", + "(Ljava/lang/String;Ljava/lang/String;)V", + path, why); if (x != NULL) { - (*env)->Throw(env, x); + (*env)->Throw(env, x); } } diff --git a/jdk/src/share/native/java/io/io_util.h b/jdk/src/share/native/java/io/io_util.h index 5b2d487058a..9a7e7b13f85 100644 --- a/jdk/src/share/native/java/io/io_util.h +++ b/jdk/src/share/native/java/io/io_util.h @@ -38,9 +38,9 @@ extern jfieldID IO_handle_fdID; * IO helper functions */ -int readSingle(JNIEnv *env, jobject this, jfieldID fid); -int readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, - jint len, jfieldID fid); +jint readSingle(JNIEnv *env, jobject this, jfieldID fid); +jint readBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, + jint len, jfieldID fid); void writeSingle(JNIEnv *env, jobject this, jint byte, jfieldID fid); void writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, jint off, jint len, jfieldID fid);