--- a/make/common/NativeCompilation.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/common/NativeCompilation.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -798,10 +798,6 @@
"-map:$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map"
$1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).pdb \
$$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).map
- # No separate command is needed for debuginfo on windows, instead
- # touch target to make sure it has a later time stamp than the debug
- # symbol files to avoid unnecessary relinking on rebuild.
- $1_CREATE_DEBUGINFO_CMDS := $(TOUCH) $$($1_TARGET)
else ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), )
$1_DEBUGINFO_FILES := $$($1_OUTPUT_DIR)/$$($1_NOSUFFIX).debuginfo
@@ -816,15 +812,23 @@
$1_DEBUGINFO_FILES := \
$$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Info.plist \
$$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM/Contents/Resources/DWARF/$$($1_BASENAME)
- # On Macosx, the debuginfo generation doesn't touch the linked binary, but
- # to avoid always relinking, touch it anyway to force a later timestamp than
- # the dSYM files.
$1_CREATE_DEBUGINFO_CMDS := \
- $(DSYMUTIL) --out $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET) $$(NEWLINE) \
- $(TOUCH) $$($1_TARGET)
+ $(DSYMUTIL) --out $$($1_OUTPUT_DIR)/$$($1_BASENAME).dSYM $$($1_TARGET)
endif # OPENJDK_TARGET_OS
+ # Since the link rule creates more than one file that we want to track,
+ # we have to use some tricks to get make to cooperate. To properly
+ # trigger downstream dependants of $$($1_DEBUGINFO_FILES), we must have
+ # a recipe in the rule below. To avoid rerunning the recipe every time
+ # have it touch the target. If a debuginfo file is deleted by something
+ # external, explicitly delete the TARGET to trigger a rebuild of both.
+ ifneq ($$(wildcard $$($1_DEBUGINFO_FILES)), $$($1_DEBUGINFO_FILES))
+ $$(call LogDebug, Deleting $$($1_BASENAME) because debuginfo files are missing)
+ $$(shell $(RM) $$($1_TARGET))
+ endif
$$($1_DEBUGINFO_FILES): $$($1_TARGET)
+ $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<))
+ $(TOUCH) $$@
$1 += $$($1_DEBUGINFO_FILES)
@@ -859,9 +863,20 @@
# Generating a dynamic library.
$1_EXTRA_LDFLAGS += $$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
ifeq ($(OPENJDK_TARGET_OS), windows)
- $1_EXTRA_LDFLAGS += "-implib:$$($1_OBJECT_DIR)/$$($1_NAME).lib"
- # Create a rule for the import lib so that other rules may depend on it
- $$($1_OBJECT_DIR)/$$($1_NAME).lib: $$($1_TARGET)
+ $1_IMPORT_LIBRARY := $$($1_OBJECT_DIR)/$$($1_NAME).lib
+ $1_EXTRA_LDFLAGS += "-implib:$$($1_IMPORT_LIBRARY)"
+ # To properly trigger downstream dependants of the import library, just as
+ # for debug files, we must have a recipe in the rule. To avoid rerunning
+ # the recipe every time have it touch the target. If an import library
+ # file is deleted by something external, explicitly delete the target to
+ # trigger a rebuild of both.
+ ifneq ($$(wildcard $$($1_IMPORT_LIBRARY)), $$($1_IMPORT_LIBRARY))
+ $$(call LogDebug, Deleting $$($1_BASENAME) because import library is missing)
+ $$(shell $(RM) $$($1_TARGET))
+ endif
+ $$($1_IMPORT_LIBRARY): $$($1_TARGET)
+ $$(if $$(wildcard $$@), , $$(error $$@ was not created for $$<))
+ $(TOUCH) $$@
endif
# Create loadmap on AIX. Helps in diagnosing some problems.
--- a/make/hotspot/lib/CompileJvm.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/hotspot/lib/CompileJvm.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -243,10 +243,10 @@
ifeq ($(OPENJDK_TARGET_OS), windows)
# It doesn't matter which jvm.lib file gets exported, but we need
# to pick just one.
- ifeq ($(JVM_VARIANT), $(firstword $(JVM_VARIANTS)))
+ ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
$(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
DEST := $(LIB_OUTPUTDIR), \
- FILES :=$(JVM_VARIANT_OUTPUTDIR)/libjvm/objs/jvm.lib, \
+ FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
))
TARGETS += $(COPY_JVM_LIB)
endif
--- a/make/lib/Awt2dLibraries.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/lib/Awt2dLibraries.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -739,7 +739,7 @@
$(BUILD_LIBJAWT): $(BUILD_LIBAWT)
$(eval $(call SetupCopyFiles, COPY_JAWT_LIB, \
- FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjawt/$(LIBRARY_PREFIX)jawt$(STATIC_LIBRARY_SUFFIX), \
+ FILES := $(BUILD_LIBJAWT_IMPORT_LIBRARY), \
DEST := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
))
@@ -931,7 +931,7 @@
TARGETS += $(BUILD_LIBSPLASHSCREEN)
ifeq ($(OPENJDK_TARGET_OS), macosx)
- $(BUILD_LIBSPLASHSCREEN): $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)osxapp$(SHARED_LIBRARY_SUFFIX)
+ $(BUILD_LIBSPLASHSCREEN): $(call FindLib, java.desktop, osxapp)
endif
endif
@@ -1009,7 +1009,7 @@
$(BUILD_LIBAWT_LWAWT): $(BUILD_LIBMLIB_IMAGE)
- $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBOSXAPP)
+ $(BUILD_LIBAWT_LWAWT): $(call FindLib, java.desktop, osxapp)
$(BUILD_LIBAWT_LWAWT): $(call FindLib, java.base, java)
@@ -1047,12 +1047,10 @@
$(BUILD_LIBOSXUI): $(BUILD_LIBAWT)
- $(BUILD_LIBOSXUI): $(BUILD_LIBOSXAPP)
+ $(BUILD_LIBOSXUI): $(call FindLib, java.desktop, osxapp)
$(BUILD_LIBOSXUI): $(BUILD_LIBAWT_LWAWT)
- #$(BUILD_LIBOSXUI): $(call FindLib, java.base, java)
-
endif
################################################################################
--- a/make/lib/Lib-java.instrument.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/lib/Lib-java.instrument.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -73,17 +73,17 @@
LIBS_aix := -liconv -ljli_static $(LIBDL), \
LIBS_macosx := -liconv -framework Cocoa -framework Security \
-framework ApplicationServices \
- $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a, \
+ $(call FindStaticLib, java.base, jli_static), \
LIBS_windows := jvm.lib $(WIN_JAVA_LIB) advapi32.lib \
- $(SUPPORT_OUTPUTDIR)/native/java.base/jli_static.lib, \
+ $(call FindStaticLib, java.base, jli_static), \
))
-ifneq (, $(findstring $(OPENJDK_TARGET_OS), macosx windows aix))
- $(BUILD_LIBINSTRUMENT): $(SUPPORT_OUTPUTDIR)/native/java.base/$(LIBRARY_PREFIX)jli_static$(STATIC_LIBRARY_SUFFIX)
+ifneq ($(filter $(OPENJDK_TARGET_OS), macosx windows aix), )
+ $(BUILD_LIBINSTRUMENT): $(call FindStaticLib, java.base, jli_static)
else
$(BUILD_LIBINSTRUMENT): $(call FindLib, java.base, jli, /jli)
endif
-$(BUILD_LIBINSTRUMENT): $(BUILD_LIBJAVA)
+$(BUILD_LIBINSTRUMENT): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBINSTRUMENT)
--- a/make/lib/Lib-jdk.crypto.ucrypto.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/lib/Lib-jdk.crypto.ucrypto.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -42,7 +42,7 @@
LIBS := $(LIBDL), \
))
- $(BUILD_LIBJ2UCRYPTO): $(BUILD_LIBJAVA)
+ $(BUILD_LIBJ2UCRYPTO): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBJ2UCRYPTO)
--- a/make/lib/LibCommon.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/lib/LibCommon.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -54,11 +54,19 @@
# Find a library
# Param 1 - module name
# Param 2 - library name
-# Param 3 - subdir for library
+# Param 3 - optional subdir for library
FindLib = \
$(call FindLibDirForModule, \
$(strip $1))$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(SHARED_LIBRARY_SUFFIX)
+################################################################################
+# Find a static library
+# Param 1 - module name
+# Param 2 - library name
+# Param 3 - optional subdir for library
+FindStaticLib = \
+ $(addprefix $(SUPPORT_OUTPUTDIR)/native/, \
+ $(strip $1)$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(STATIC_LIBRARY_SUFFIX))
################################################################################
# Define the header include flags needed to compile against it.
--- a/make/lib/SoundLibraries.gmk Mon Mar 19 12:29:23 2018 +0530
+++ b/make/lib/SoundLibraries.gmk Mon Mar 19 10:46:31 2018 -0700
@@ -133,7 +133,7 @@
LIBS_windows := $(WIN_JAVA_LIB) advapi32.lib winmm.lib, \
))
-$(BUILD_LIBJSOUND): $(BUILD_LIBJAVA)
+$(BUILD_LIBJSOUND): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBJSOUND)
@@ -166,7 +166,7 @@
LIBS := $(ALSA_LIBS) -ljava -ljvm, \
))
- $(BUILD_LIBJSOUNDALSA): $(BUILD_LIBJAVA)
+ $(BUILD_LIBJSOUNDALSA): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBJSOUNDALSA)
@@ -191,7 +191,7 @@
LIBS := $(JDKLIB_LIBS) dsound.lib winmm.lib user32.lib ole32.lib, \
))
- $(BUILD_LIBJSOUNDDS): $(BUILD_LIBJAVA)
+ $(BUILD_LIBJSOUNDDS): $(call FindLib, java.base, java)
TARGETS += $(BUILD_LIBJSOUNDDS)
--- a/make/mapfiles/libjava/reorder-sparc Mon Mar 19 12:29:23 2018 +0530
+++ b/make/mapfiles/libjava/reorder-sparc Mon Mar 19 10:46:31 2018 -0700
@@ -26,7 +26,6 @@
text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_Object_getClass;
text: .text%Java_sun_reflect_Reflection_getClassAccessFlags;
--- a/make/mapfiles/libjava/reorder-sparcv9 Mon Mar 19 12:29:23 2018 +0530
+++ b/make/mapfiles/libjava/reorder-sparcv9 Mon Mar 19 10:46:31 2018 -0700
@@ -25,7 +25,6 @@
text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_String_intern;
text: .text%Java_java_lang_StringUTF16_isBigEndian;
--- a/make/mapfiles/libjava/reorder-x86 Mon Mar 19 12:29:23 2018 +0530
+++ b/make/mapfiles/libjava/reorder-x86 Mon Mar 19 10:46:31 2018 -0700
@@ -26,7 +26,6 @@
text: .text%Java_java_io_FileDescriptor_initIDs;
text: .text%Java_java_io_FileOutputStream_initIDs;
text: .text%Java_java_lang_System_setIn0;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__;
text: .text%Java_java_lang_Class_forName0;
text: .text%Java_java_lang_String_intern;
text: .text%Java_java_lang_StringUTF16_isBigEndian;
--- a/src/java.base/share/classes/java/io/FileReader.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/java.base/share/classes/java/io/FileReader.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, 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
@@ -25,16 +25,17 @@
package java.io;
+import java.nio.charset.Charset;
/**
- * Convenience class for reading character files. The constructors of this
- * class assume that the default character encoding and the default byte-buffer
- * size are appropriate. To specify these values yourself, construct an
- * InputStreamReader on a FileInputStream.
+ * Reads text from character files using a default buffer size. Decoding from bytes
+ * to characters uses either a specified {@linkplain java.nio.charset.Charset charset}
+ * or the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * <p>{@code FileReader} is meant for reading streams of characters.
- * For reading streams of raw bytes, consider using a
- * {@code FileInputStream}.
+ * <p>
+ * The {@code FileReader} is meant for reading streams of characters. For reading
+ * streams of raw bytes, consider using a {@code FileInputStream}.
*
* @see InputStreamReader
* @see FileInputStream
@@ -45,10 +46,11 @@
public class FileReader extends InputStreamReader {
/**
- * Creates a new {@code FileReader}, given the name of the
- * file to read from.
+ * Creates a new {@code FileReader}, given the name of the file to read,
+ * using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * @param fileName the name of the file to read from
+ * @param fileName the name of the file to read
* @exception FileNotFoundException if the named file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
@@ -59,10 +61,11 @@
}
/**
- * Creates a new {@code FileReader}, given the {@code File}
- * to read from.
+ * Creates a new {@code FileReader}, given the {@code File} to read,
+ * using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * @param file the {@code File} to read from
+ * @param file the {@code File} to read
* @exception FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
@@ -73,13 +76,47 @@
}
/**
- * Creates a new {@code FileReader}, given the
- * {@code FileDescriptor} to read from.
+ * Creates a new {@code FileReader}, given the {@code FileDescriptor} to read,
+ * using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * @param fd the FileDescriptor to read from
+ * @param fd the {@code FileDescriptor} to read
*/
public FileReader(FileDescriptor fd) {
super(new FileInputStream(fd));
}
+ /**
+ * Creates a new {@code FileReader}, given the name of the file to read
+ * and the {@linkplain java.nio.charset.Charset charset}.
+ *
+ * @param fileName the name of the file to read
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @exception IOException if the named file does not exist,
+ * is a directory rather than a regular file,
+ * or for some other reason cannot be opened for
+ * reading.
+ *
+ * @since 11
+ */
+ public FileReader(String fileName, Charset charset) throws IOException {
+ super(new FileInputStream(fileName), charset);
+ }
+
+ /**
+ * Creates a new {@code FileReader}, given the {@code File} to read and
+ * the {@linkplain java.nio.charset.Charset charset}.
+ *
+ * @param file the {@code File} to read
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @exception IOException if the file does not exist,
+ * is a directory rather than a regular file,
+ * or for some other reason cannot be opened for
+ * reading.
+ *
+ * @since 11
+ */
+ public FileReader(File file, Charset charset) throws IOException {
+ super(new FileInputStream(file), charset);
+ }
}
--- a/src/java.base/share/classes/java/io/FileWriter.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/java.base/share/classes/java/io/FileWriter.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, 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
@@ -25,22 +25,24 @@
package java.io;
+import java.nio.charset.Charset;
/**
- * Convenience class for writing character files. The constructors of this
- * class assume that the default character encoding and the default byte-buffer
- * size are acceptable. To specify these values yourself, construct an
- * OutputStreamWriter on a FileOutputStream.
+ * Writes text to character files using a default buffer size. Encoding from characters
+ * to bytes uses either a specified {@linkplain java.nio.charset.Charset charset}
+ * or the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * <p>Whether or not a file is available or may be created depends upon the
+ * <p>
+ * Whether or not a file is available or may be created depends upon the
* underlying platform. Some platforms, in particular, allow a file to be
* opened for writing by only one {@code FileWriter} (or other file-writing
* object) at a time. In such situations the constructors in this class
* will fail if the file involved is already open.
*
- * <p>{@code FileWriter} is meant for writing streams of characters.
- * For writing streams of raw bytes, consider using a
- * {@code FileOutputStream}.
+ * <p>
+ * The {@code FileWriter} is meant for writing streams of characters. For writing
+ * streams of raw bytes, consider using a {@code FileOutputStream}.
*
* @see OutputStreamWriter
* @see FileOutputStream
@@ -52,7 +54,8 @@
public class FileWriter extends OutputStreamWriter {
/**
- * Constructs a FileWriter object given a file name.
+ * Constructs a {@code FileWriter} given a file name, using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
*
* @param fileName String The system-dependent filename.
* @throws IOException if the named file exists but is a directory rather
@@ -64,8 +67,9 @@
}
/**
- * Constructs a FileWriter object given a file name with a boolean
- * indicating whether or not to append the data written.
+ * Constructs a {@code FileWriter} given a file name and a boolean indicating
+ * whether to append the data written, using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
* @param fileName String The system-dependent filename.
* @param append boolean if {@code true}, then data will be written
@@ -79,9 +83,11 @@
}
/**
- * Constructs a FileWriter object given a File object.
+ * Constructs a {@code FileWriter} given the {@code File} to write,
+ * using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
*
- * @param file a File object to write to.
+ * @param file the {@code File} to write.
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
@@ -91,11 +97,11 @@
}
/**
- * Constructs a FileWriter object given a File object. If the second
- * argument is {@code true}, then bytes will be written to the end
- * of the file rather than the beginning.
+ * Constructs a {@code FileWriter} given the {@code File} to write and
+ * a boolean indicating whether to append the data written, using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * @param file a File object to write to
+ * @param file the {@code File} to write
* @param append if {@code true}, then bytes will be written
* to the end of the file rather than the beginning
* @throws IOException if the file exists but is a directory rather than
@@ -108,12 +114,83 @@
}
/**
- * Constructs a FileWriter object associated with a file descriptor.
+ * Constructs a {@code FileWriter} given a file descriptor,
+ * using the platform's
+ * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
- * @param fd FileDescriptor object to write to.
+ * @param fd the {@code FileDescriptor} to write.
*/
public FileWriter(FileDescriptor fd) {
super(new FileOutputStream(fd));
}
+
+ /**
+ * Constructs a {@code FileWriter} given a file name and
+ * {@linkplain java.nio.charset.Charset charset}.
+ *
+ * @param fileName the name of the file to write
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @throws IOException if the named file exists but is a directory rather
+ * than a regular file, does not exist but cannot be
+ * created, or cannot be opened for any other reason
+ *
+ * @since 11
+ */
+ public FileWriter(String fileName, Charset charset) throws IOException {
+ super(new FileOutputStream(fileName), charset);
+ }
+
+ /**
+ * Constructs a {@code FileWriter} given a file name,
+ * {@linkplain java.nio.charset.Charset charset} and a boolean indicating
+ * whether to append the data written.
+ *
+ * @param fileName the name of the file to write
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @param append a boolean. If {@code true}, the writer will write the data
+ * to the end of the file rather than the beginning.
+ * @throws IOException if the named file exists but is a directory rather
+ * than a regular file, does not exist but cannot be
+ * created, or cannot be opened for any other reason
+ *
+ * @since 11
+ */
+ public FileWriter(String fileName, Charset charset, boolean append) throws IOException {
+ super(new FileOutputStream(fileName, append), charset);
+ }
+
+ /**
+ * Constructs a {@code FileWriter} given the {@code File} to write and
+ * {@linkplain java.nio.charset.Charset charset}.
+ *
+ * @param file the {@code File} to write
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @throws IOException if the file exists but is a directory rather than
+ * a regular file, does not exist but cannot be created,
+ * or cannot be opened for any other reason
+ *
+ * @since 11
+ */
+ public FileWriter(File file, Charset charset) throws IOException {
+ super(new FileOutputStream(file), charset);
+ }
+
+ /**
+ * Constructs a {@code FileWriter} given the {@code File} to write,
+ * {@linkplain java.nio.charset.Charset charset} and a boolean indicating
+ * whether to append the data written.
+ *
+ * @param file the {@code File} to write
+ * @param charset the {@linkplain java.nio.charset.Charset charset}
+ * @param append a boolean. If {@code true}, the writer will write the data
+ * to the end of the file rather than the beginning.
+ * @throws IOException if the file exists but is a directory rather than
+ * a regular file, does not exist but cannot be created,
+ * or cannot be opened for any other reason
+ * @since 11
+ */
+ public FileWriter(File file, Charset charset, boolean append) throws IOException {
+ super(new FileOutputStream(file, append), charset);
+ }
}
--- a/src/java.base/share/classes/java/io/Reader.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/java.base/share/classes/java/io/Reader.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, 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
@@ -26,6 +26,7 @@
package java.io;
+import java.nio.CharBuffer;
import java.util.Objects;
/**
@@ -55,6 +56,85 @@
private static final int TRANSFER_BUFFER_SIZE = 8192;
/**
+ * Returns a new {@code Reader} that reads no characters. The returned
+ * stream is initially open. The stream is closed by calling the
+ * {@code close()} method. Subsequent calls to {@code close()} have no
+ * effect.
+ *
+ * <p> While the stream is open, the {@code read()}, {@code read(char[])},
+ * {@code read(char[], int, int)}, {@code read(Charbuffer)}, {@code
+ * ready())}, {@code skip(long)}, and {@code transferTo()} methods all
+ * behave as if end of stream has been reached. After the stream has been
+ * closed, these methods all throw {@code IOException}.
+ *
+ * <p> The {@code markSupported()} method returns {@code false}. The
+ * {@code mark()} method does nothing, and the {@code reset()} method
+ * throws {@code IOException}.
+ *
+ * <p> The {@link #lock object} used to synchronize operations on the
+ * returned {@code Reader} is not specified.
+ *
+ * @return a {@code Reader} which reads no characters
+ *
+ * @since 11
+ */
+ public static Reader nullReader() {
+ return new Reader() {
+ private volatile boolean closed;
+
+ private void ensureOpen() throws IOException {
+ if (closed) {
+ throw new IOException("Stream closed");
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ ensureOpen();
+ return -1;
+ }
+
+ @Override
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ Objects.checkFromIndexSize(off, len, cbuf.length);
+ ensureOpen();
+ if (len == 0) {
+ return 0;
+ }
+ return -1;
+ }
+
+ @Override
+ public int read(CharBuffer target) throws IOException {
+ Objects.requireNonNull(target);
+ ensureOpen();
+ if (target.hasRemaining()) {
+ return -1;
+ }
+ return 0;
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ ensureOpen();
+ return 0L;
+ }
+
+ @Override
+ public long transferTo(Writer out) throws IOException {
+ Objects.requireNonNull(out);
+ ensureOpen();
+ return 0L;
+ }
+
+ @Override
+ public void close() {
+ closed = true;
+ }
+ };
+ }
+
+ /**
* The object used to synchronize operations on this stream. For
* efficiency, a character-stream object may use an object other than
* itself to protect critical sections. A subclass should therefore use
--- a/src/java.base/share/classes/java/io/Writer.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/java.base/share/classes/java/io/Writer.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, 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
@@ -26,6 +26,8 @@
package java.io;
+import java.util.Objects;
+
/**
* Abstract class for writing to character streams. The only methods that a
* subclass must implement are write(char[], int, int), flush(), and close().
@@ -59,6 +61,91 @@
private static final int WRITE_BUFFER_SIZE = 1024;
/**
+ * Returns a new {@code Writer} which discards all characters. The
+ * returned stream is initially open. The stream is closed by calling
+ * the {@code close()} method. Subsequent calls to {@code close()} have
+ * no effect.
+ *
+ * <p> While the stream is open, the {@code append(char)}, {@code
+ * append(CharSequence)}, {@code append(CharSequence, int, int)},
+ * {@code flush()}, {@code write(int)}, {@code write(char[])}, and
+ * {@code write(char[], int, int)} methods do nothing. After the stream
+ * has been closed, these methods all throw {@code IOException}.
+ *
+ * <p> The {@link #lock object} used to synchronize operations on the
+ * returned {@code Writer} is not specified.
+ *
+ * @return a {@code Writer} which discards all characters
+ *
+ * @since 11
+ */
+ public static Writer nullWriter() {
+ return new Writer() {
+ private volatile boolean closed;
+
+ private void ensureOpen() throws IOException {
+ if (closed) {
+ throw new IOException("Stream closed");
+ }
+ }
+
+ @Override
+ public Writer append(char c) throws IOException {
+ ensureOpen();
+ return this;
+ }
+
+ @Override
+ public Writer append(CharSequence csq) throws IOException {
+ ensureOpen();
+ return this;
+ }
+
+ @Override
+ public Writer append(CharSequence csq, int start, int end) throws IOException {
+ ensureOpen();
+ if (csq != null) {
+ Objects.checkFromToIndex(start, end, csq.length());
+ }
+ return this;
+ }
+
+ @Override
+ public void write(int c) throws IOException {
+ ensureOpen();
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ Objects.checkFromIndexSize(off, len, cbuf.length);
+ ensureOpen();
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ Objects.requireNonNull(str);
+ ensureOpen();
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ Objects.checkFromIndexSize(off, len, str.length());
+ ensureOpen();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ ensureOpen();
+ }
+
+ @Override
+ public void close() throws IOException {
+ closed = true;
+ }
+ };
+ }
+
+ /**
* The object used to synchronize operations on this stream. For
* efficiency, a character-stream object may use an object other than
* itself to protect critical sections. A subclass should therefore use
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/lookup/Lookup.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/lookup/Lookup.java Mon Mar 19 10:46:31 2018 -0700
@@ -56,11 +56,8 @@
/** Method handle to the empty setter */
public static final MethodHandle EMPTY_SETTER = findOwnMH("emptySetter", void.class, Object.class, Object.class);
- /** Method handle to a getter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_GETTER = findOwnMH("typeErrorThrowerGetter", Object.class, Object.class);
-
- /** Method handle to a setter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_SETTER = findOwnMH("typeErrorThrowerSetter", void.class, Object.class, Object.class);
+ /** Method handle to a getter or setter that only throws type error */
+ public static final MethodHandle TYPE_ERROR_THROWER = findOwnMH("typeErrorThrower", Object.class, Object.class);
/** Method handle to the most generic of getters, the one that returns an Object */
public static final MethodType GET_OBJECT_TYPE = MH.type(Object.class, Object.class);
@@ -114,17 +111,7 @@
* @param self self reference
* @return undefined (but throws error before return point)
*/
- public static Object typeErrorThrowerGetter(final Object self) {
- throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
- }
-
- /**
- * Getter function that always throws type error
- *
- * @param self self reference
- * @param value (ignored)
- */
- public static void typeErrorThrowerSetter(final Object self, final Object value) {
+ public static Object typeErrorThrower(final Object self) {
throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Mon Mar 19 10:46:31 2018 -0700
@@ -2978,7 +2978,7 @@
anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
// use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
- this.typeErrorThrower = ScriptFunction.createBuiltin("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER);
+ this.typeErrorThrower = ScriptFunction.createBuiltin("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER);
typeErrorThrower.preventExtensions();
// now initialize Object
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeStrictArguments.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeStrictArguments.java Mon Mar 19 10:46:31 2018 -0700
@@ -79,9 +79,8 @@
final ScriptFunction func = Global.instance().getTypeErrorThrower();
// We have to fill user accessor functions late as these are stored
// in this object rather than in the PropertyMap of this object.
- final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
- initUserAccessors("caller", flags, func, func);
- initUserAccessors("callee", flags, func, func);
+ initUserAccessors("caller", func, func);
+ initUserAccessors("callee", func, func);
setArray(ArrayData.allocate(values));
this.length = values.length;
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java Mon Mar 19 10:46:31 2018 -0700
@@ -137,8 +137,8 @@
final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
PropertyMap newMap = map;
// Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
- newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags));
- newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags));
+ newMap = newMap.addPropertyNoHistory(newMap.newUserAccessors("arguments", flags));
+ newMap = newMap.addPropertyNoHistory(newMap.newUserAccessors("caller", flags));
return newMap;
}
@@ -215,8 +215,8 @@
assert objectSpill == null;
if (isStrict() || isBoundFunction()) {
final ScriptFunction typeErrorThrower = global.getTypeErrorThrower();
- initUserAccessors("arguments", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower);
- initUserAccessors("caller", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower);
+ initUserAccessors("arguments", typeErrorThrower, typeErrorThrower);
+ initUserAccessors("caller", typeErrorThrower, typeErrorThrower);
}
}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java Mon Mar 19 12:29:23 2018 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java Mon Mar 19 10:46:31 2018 -0700
@@ -962,24 +962,19 @@
/**
* Fast initialization functions for ScriptFunctions that are strict, to avoid
* creating setters that probably aren't used. Inject directly into the spill pool
- * the defaults for "arguments" and "caller"
+ * the defaults for "arguments" and "caller", asserting the property is already
+ * defined in the map.
*
- * @param key property key
- * @param propertyFlags flags
- * @param getter getter for {@link UserAccessorProperty}, null if not present or N/A
- * @param setter setter for {@link UserAccessorProperty}, null if not present or N/A
+ * @param key property key
+ * @param getter getter for {@link UserAccessorProperty}
+ * @param setter setter for {@link UserAccessorProperty}
*/
- protected final void initUserAccessors(final String key, final int propertyFlags, final ScriptFunction getter, final ScriptFunction setter) {
- final PropertyMap oldMap = getMap();
- final int slot = oldMap.getFreeSpillSlot();
- ensureSpillSize(slot);
- objectSpill[slot] = new UserAccessorProperty.Accessors(getter, setter);
- Property newProperty;
- PropertyMap newMap;
- do {
- newProperty = new UserAccessorProperty(key, propertyFlags, slot);
- newMap = oldMap.addProperty(newProperty);
- } while (!compareAndSetMap(oldMap, newMap));
+ protected final void initUserAccessors(final String key, final ScriptFunction getter, final ScriptFunction setter) {
+ final PropertyMap map = getMap();
+ final Property property = map.findProperty(key);
+ assert property instanceof UserAccessorProperty;
+ ensureSpillSize(property.getSlot());
+ objectSpill[property.getSlot()] = new UserAccessorProperty.Accessors(getter, setter);
}
/**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/io/FileReader/ConstructorTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * @test
+ * @bug 8183554
+ * @summary Test to verify the new Constructors that take a Charset.
+ * @run testng ConstructorTest
+ */
+public class ConstructorTest {
+ static String USER_DIR = System.getProperty("user.dir", ".");
+
+ public static enum ConstructorType {
+ STRING,
+ FILE
+ }
+
+ static final String TEST_STRING = "abc \u0100 \u0101 \u0555 \u07FD \u07FF";
+ static final int BUFFER_SIZE = 8192;
+
+ @DataProvider(name = "parameters")
+ public Object[][] getParameters() throws IOException {
+ File file1 = new File(USER_DIR, "FileReaderTest1.txt");
+ File file2 = new File(USER_DIR, "FileReaderTest2.txt");
+
+ return new Object[][]{
+ {ConstructorType.STRING, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.FILE, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.STRING, file1, file2, StandardCharsets.ISO_8859_1},
+ {ConstructorType.FILE, file1, file2, StandardCharsets.ISO_8859_1},
+ };
+ }
+
+ /**
+ * Verifies that the new constructors that take a Charset function the same
+ * as an InputStreamReader on a FileInputStream as was recommended before
+ * this change.
+ *
+ * @param type the type of the constructor
+ * @param file1 file1 to be read with a FileReader
+ * @param file2 file2 to be read with an InputStreamReader
+ * @param charset the charset
+ * @throws IOException
+ */
+ @Test(dataProvider = "parameters")
+ void test(ConstructorType type, File file1, File file2, Charset charset)
+ throws Exception {
+ prepareFile(file1, TEST_STRING, charset);
+ prepareFile(file2, TEST_STRING, charset);
+
+ try (FileReader fr = getFileReader(type, file1, charset);
+ FileInputStream is = new FileInputStream(file2);
+ InputStreamReader isr = new InputStreamReader(is, charset);) {
+ String result1 = readAll(fr, BUFFER_SIZE);
+ String result2 = readAll(isr, BUFFER_SIZE);
+ Assert.assertEquals(result1, result2);
+ }
+ }
+
+ public String readAll(Reader reader, int bufferSize) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ char[] buf = new char[bufferSize];
+ int numRead;
+ while ((numRead = reader.read(buf)) != -1) {
+ if (numRead == buf.length) {
+ sb.append(buf);
+ } else {
+ sb.append(String.valueOf(buf, 0, numRead));
+ }
+ }
+ return sb.toString();
+ }
+
+ /*
+ * Creates a FileReader over the given input file.
+ */
+ FileReader getFileReader(ConstructorType type, File file, Charset charset)
+ throws IOException {
+ switch (type) {
+ case STRING:
+ return new FileReader(file.getPath(), charset);
+ case FILE:
+ return new FileReader(file, charset);
+ }
+
+ return null;
+ }
+
+ void prepareFile(File file, String content, Charset charset) throws IOException {
+ try (FileWriter writer = new FileWriter(file, charset);) {
+ writer.write(content);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/io/FileWriter/ConstructorTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * @test
+ * @bug 8183554
+ * @summary Test to verify the new Constructors that take a Charset.
+ * @run testng ConstructorTest
+ */
+public class ConstructorTest {
+ static String USER_DIR = System.getProperty("user.dir", ".");
+
+ public static enum ConstructorType {
+ STRING,
+ FILE,
+ STRING_APPEND,
+ FILE_APPEND
+ }
+
+ static final String TEST_STRING = "abc \u0100 \u0101 \u0555 \u07FD \u07FF";
+ static final int BUFFER_SIZE = 8192;
+
+ @DataProvider(name = "parameters")
+ public Object[][] getParameters() throws IOException {
+ File file1 = new File(USER_DIR, "FileWriterTest1.txt");
+ File file2 = new File(USER_DIR, "FileWriterTest2.txt");
+
+ return new Object[][]{
+ {ConstructorType.STRING, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.FILE, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.STRING_APPEND, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.FILE_APPEND, file1, file2, StandardCharsets.UTF_8},
+ {ConstructorType.STRING, file1, file2, StandardCharsets.ISO_8859_1},
+ {ConstructorType.FILE, file1, file2, StandardCharsets.ISO_8859_1},
+ {ConstructorType.STRING_APPEND, file1, file2, StandardCharsets.ISO_8859_1},
+ {ConstructorType.FILE_APPEND, file1, file2, StandardCharsets.ISO_8859_1},
+ };
+ }
+
+ /**
+ * Verifies that the new constructors that take a Charset function the same
+ * as an OutputStreamWriter on a FileOutputStream as was recommended before
+ * this change.
+ *
+ * @param type the type of the constructor
+ * @param file1 file1 to be written with a FileWriter
+ * @param file2 file2 to be written with an OutputStreamWriter
+ * @param charset the charset
+ * @throws IOException
+ */
+ @Test(dataProvider = "parameters")
+ void test(ConstructorType type, File file1, File file2, Charset charset)
+ throws Exception {
+ writeWithFileWriter(type, file1, TEST_STRING, charset);
+ writeWithOutputStreamWriter(type, file2, TEST_STRING, charset);
+
+ try (
+ FileReader r1 = getFileReader(type, file1, charset);
+ FileReader r2 = getFileReader(type, file2, charset);
+ ) {
+ String result1 = readAll(r1, BUFFER_SIZE);
+ String result2 = readAll(r2, BUFFER_SIZE);
+ Assert.assertEquals(result1, result2);
+ }
+ }
+
+ public String readAll(Reader reader, int bufferSize) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ char[] buf = new char[bufferSize];
+ int numRead;
+ while ((numRead = reader.read(buf)) != -1) {
+ if (numRead == buf.length) {
+ sb.append(buf);
+ } else {
+ sb.append(String.valueOf(buf, 0, numRead));
+ }
+ }
+ return sb.toString();
+ }
+
+ /*
+ * Creates a FileReader over the given input file.
+ */
+ FileReader getFileReader(ConstructorType type, File file, Charset charset)
+ throws IOException {
+ switch (type) {
+ case STRING:
+ case STRING_APPEND:
+ return new FileReader(file.getPath(), charset);
+ case FILE:
+ case FILE_APPEND:
+ return new FileReader(file, charset);
+ }
+
+ return null;
+ }
+
+ /*
+ * Creates a FileWriter using the constructor as specified.
+ */
+ FileWriter getFileWriter(ConstructorType type, File file, Charset charset)
+ throws IOException {
+ switch (type) {
+ case STRING:
+ return new FileWriter(file.getPath(), charset);
+ case FILE:
+ return new FileWriter(file, charset);
+ case STRING_APPEND:
+ return new FileWriter(file.getPath(), charset, true);
+ case FILE_APPEND:
+ return new FileWriter(file, charset, true);
+ }
+
+ return null;
+ }
+
+ void writeWithFileWriter(ConstructorType type, File file, String content, Charset charset)
+ throws IOException {
+ if (type == ConstructorType.STRING_APPEND || type == ConstructorType.FILE_APPEND) {
+ try (FileWriter writer = getFileWriter(ConstructorType.FILE, file, charset);) {
+ writer.write(content);
+ }
+ }
+ try (FileWriter writer = getFileWriter(type, file, charset);) {
+ writer.write(content);
+ }
+ }
+
+ void writeWithOutputStreamWriter(ConstructorType type, File file, String content, Charset charset)
+ throws IOException {
+ try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), charset)) {
+ writer.write(content);
+ if (type == ConstructorType.STRING_APPEND || type == ConstructorType.FILE_APPEND) {
+ writer.write(content);
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/io/Reader/NullReader.java Mon Mar 19 10:46:31 2018 -0700
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.Reader;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+/*
+ * @test
+ * @bug 8196298
+ * @run testng NullReader
+ * @summary Check for expected behavior of Reader.nullReader().
+ */
+public class NullReader {
+ private static Reader openReader;
+ private static Reader closedReader;
+
+ @BeforeGroups(groups = "open")
+ public static void openStream() {
+ openReader = Reader.nullReader();
+ }
+
+ @BeforeGroups(groups = "closed")
+ public static void openAndCloseStream() throws IOException {
+ closedReader = Reader.nullReader();
+ closedReader.close();
+ }
+
+ @AfterGroups(groups = "open")
+ public static void closeStream() throws IOException {
+ openReader.close();
+ }
+
+ @Test(groups = "open")
+ public static void testOpen() {
+ assertNotNull(openReader, "Reader.nullReader() returned null");
+ }
+
+ @Test(groups = "open")
+ public static void testRead() throws IOException {
+ assertEquals(-1, openReader.read(), "read() != -1");
+ }
+
+ @Test(groups = "open")
+ public static void testReadBII() throws IOException {
+ assertEquals(-1, openReader.read(new char[1], 0, 1),
+ "read(char[],int,int) != -1");
+ }
+
+ @Test(groups = "open")
+ public static void testReadBIILenZero() throws IOException {
+ assertEquals(0, openReader.read(new char[1], 0, 0),
+ "read(char[],int,int) != 0");
+ }
+
+ @Test(groups = "open")
+ public static void testReadCharBuffer() throws IOException {
+ CharBuffer charBuffer = CharBuffer.allocate(1);
+ assertEquals(-1, openReader.read(charBuffer),
+ "read(CharBuffer) != -1");
+ }
+
+ @Test(groups = "open")
+ public static void testReadCharBufferZeroRemaining() throws IOException {
+ CharBuffer charBuffer = CharBuffer.allocate(0);
+ assertEquals(0, openReader.read(charBuffer),
+ "read(CharBuffer) != 0");
+ }
+
+ @Test(groups = "open")
+ public static void testSkip() throws IOException {
+ assertEquals(0, openReader.skip(1), "skip() != 0");
+ }
+
+ @Test(groups = "open")
+ public static void testTransferTo() throws IOException {
+ assertEquals(0, openReader.transferTo(new StringWriter(7)),
+ "transferTo() != 0");
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testReadClosed() throws IOException {
+ closedReader.read();
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testReadBIIClosed() throws IOException {
+ closedReader.read(new char[1], 0, 1);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testReadCharBufferClosed() throws IOException {
+ CharBuffer charBuffer = CharBuffer.allocate(0);
+ closedReader.read(charBuffer);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testReadCharBufferZeroRemainingClosed() throws IOException {
+ CharBuffer charBuffer = CharBuffer.allocate(0);
+ closedReader.read(charBuffer);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testSkipClosed() throws IOException {
+ closedReader.skip(1);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testTransferToClosed() throws IOException {
+ closedReader.transferTo(new StringWriter(7));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/io/Writer/NullWriter.java Mon Mar 19 10:46:31 2018 -0700
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2018, 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
+ * 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+/*
+ * @test
+ * @bug 8196298
+ * @run testng NullWriter
+ * @summary Check for expected behavior of Writer.nullWriter().
+ */
+public class NullWriter {
+ private static Writer openWriter;
+ private static Writer closedWriter;
+
+ @BeforeGroups(groups = "open")
+ public static void openStream() {
+ openWriter = Writer.nullWriter();
+ }
+
+ @BeforeGroups(groups = "closed")
+ public static void openAndCloseStream() throws IOException {
+ closedWriter = Writer.nullWriter();
+ closedWriter.close();
+ }
+
+ @AfterGroups(groups = "open")
+ public static void closeStream() throws IOException {
+ openWriter.close();
+ }
+
+ @Test(groups = "open")
+ public static void testOpen() {
+ assertNotNull(openWriter, "Writer.nullWriter() returned null");
+ }
+
+ @Test(groups = "open")
+ public static void testAppendChar() throws IOException {
+ assertSame(openWriter, openWriter.append('x'));
+ }
+
+ @Test(groups = "open")
+ public static void testAppendCharSequence() throws IOException {
+ CharSequence cs = "abc";
+ assertSame(openWriter, openWriter.append(cs));
+ }
+
+ @Test(groups = "open")
+ public static void testAppendCharSequenceNull() throws IOException {
+ assertSame(openWriter, openWriter.append(null));
+ }
+
+ @Test(groups = "open")
+ public static void testAppendCharSequenceII() throws IOException {
+ CharSequence cs = "abc";
+ assertSame(openWriter, openWriter.append(cs, 0, 1));
+ }
+
+ @Test(groups = "open")
+ public static void testAppendCharSequenceIINull() throws IOException {
+ assertSame(openWriter, openWriter.append(null, 2, 1));
+ }
+
+ @Test(groups = "open")
+ public static void testFlush() throws IOException {
+ openWriter.flush();
+ }
+
+ @Test(groups = "open")
+ public static void testWrite() throws IOException {
+ openWriter.write(62832);
+ }
+
+ @Test(groups = "open")
+ public static void testWriteString() throws IOException {
+ openWriter.write("");
+ }
+
+ @Test(groups = "open")
+ public static void testWriteStringII() throws IOException {
+ openWriter.write("", 0, 0);
+ }
+
+ @Test(groups = "open")
+ public static void testWriteBII() throws IOException, Exception {
+ openWriter.write(new char[]{(char) 6}, 0, 1);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testAppendCharClosed() throws IOException {
+ closedWriter.append('x');
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testAppendCharSequenceClosed() throws IOException {
+ CharSequence cs = "abc";
+ closedWriter.append(cs);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testAppendCharSequenceNullClosed() throws IOException {
+ closedWriter.append(null);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testAppendCharSequenceIIClosed() throws IOException {
+ CharSequence cs = "abc";
+ closedWriter.append(cs, 0, 1);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testAppendCharSequenceIINullClosed() throws IOException {
+ closedWriter.append(null, 2, 1);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testFlushClosed() throws IOException {
+ closedWriter.flush();
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testWriteClosed() throws IOException {
+ closedWriter.write(62832);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testWriteStringClosed() throws IOException {
+ closedWriter.write("");
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testWriteStringIIClosed() throws IOException {
+ closedWriter.write("", 0, 0);
+ }
+
+ @Test(groups = "closed", expectedExceptions = IOException.class)
+ public static void testWriteBIIClosed() throws IOException {
+ closedWriter.write(new char[]{(char) 6}, 0, 1);
+ }
+}
--- a/test/jdk/java/lang/ProcessHandle/OnExitTest.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/lang/ProcessHandle/OnExitTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -41,6 +41,7 @@
/*
* @test
* @library /test/lib
+ * @modules jdk.management
* @build jdk.test.lib.Utils
* @run testng OnExitTest
* @summary Functions of Process.onExit and ProcessHandle.onExit
--- a/test/jdk/java/lang/module/ModuleReader/ModuleReaderTest.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/lang/module/ModuleReader/ModuleReaderTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -26,6 +26,7 @@
* @library /lib/testlibrary /test/lib
* @modules java.base/jdk.internal.module
* jdk.compiler
+ * jdk.jlink
* @build ModuleReaderTest jdk.test.lib.compiler.CompilerUtils JarUtils
* @run testng ModuleReaderTest
* @summary Basic tests for java.lang.module.ModuleReader
--- a/test/jdk/java/nio/channels/DatagramChannel/AdaptDatagramSocket.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/DatagramChannel/AdaptDatagramSocket.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4313882 4981129 8143610
* @summary Unit test for datagram-socket-channel adaptors
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main AdaptDatagramSocket
* @key randomness
*/
--- a/test/jdk/java/nio/channels/DatagramChannel/IsBound.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/DatagramChannel/IsBound.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4468875
* @summary Simple test of DatagramChannel isBound
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main IsBound
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/DatagramChannel/IsConnected.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/DatagramChannel/IsConnected.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4446035
* @summary Simple test of DatagramSocket connection consistency
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main IsConnected
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/Selector/Alias.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/Selector/Alias.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4513011
* @summary Registering and cancelling same fd many times
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main Alias
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/Selector/BasicConnect.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/Selector/BasicConnect.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @summary Test nonblocking connect and finishConnect
* @bug 4457776
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main BasicConnect
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/Selector/Connect.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/Selector/Connect.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4511624
* @summary Test Making lots of Selectors
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main Connect
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/Selector/ConnectWrite.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/Selector/ConnectWrite.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4505829
* @summary Test ready for connect followed by ready for write
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main ConnectWrite
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/Selector/KeysReady.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/Selector/KeysReady.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4530007
* @summary Test if keys reported ready multiple times
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main KeysReady
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/AdaptSocket.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/AdaptSocket.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 8156002
* @summary Unit test for socket-channel adaptors
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main AdaptSocket
*/
import java.io.*;
--- a/test/jdk/java/nio/channels/SocketChannel/Basic.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/Basic.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, 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
@@ -23,7 +23,9 @@
/* @test
* @summary Unit test for socket channels
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main Basic
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/CloseDuringConnect.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/CloseDuringConnect.java Mon Mar 19 10:46:31 2018 -0700
@@ -23,6 +23,8 @@
/* @test
* @bug 8198928
+ * @library /test/lib
+ * @build jdk.test.lib.Utils
* @run main CloseDuringConnect
* @summary Attempt to cause a deadlock by closing a SocketChannel in one thread
* where another thread is closing the channel after a connect fail
@@ -40,6 +42,8 @@
import java.util.stream.IntStream;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import jdk.test.lib.Utils;
+
public class CloseDuringConnect {
// number of test iterations, needs to be 5-10 at least
@@ -49,26 +53,6 @@
static final int MAX_DELAY_BEFORE_CLOSE = 20;
/**
- * Returns the socket address of an endpoint that refuses connections. The
- * endpoint is an InetSocketAddress where the address is the loopback address
- * and the port is a system port (1-1023 range).
- */
- static SocketAddress refusingEndpoint() {
- InetAddress lb = InetAddress.getLoopbackAddress();
- int port = 1;
- while (port < 1024) {
- SocketAddress sa = new InetSocketAddress(lb, port);
- try {
- SocketChannel.open(sa).close();
- } catch (IOException ioe) {
- return sa;
- }
- port++;
- }
- throw new RuntimeException("Unable to find system port that is refusing connections");
- }
-
- /**
* Invoked by a task in the thread pool to connect to a remote address.
* The connection should never be established.
*/
@@ -123,7 +107,7 @@
}
public static void main(String[] args) throws Exception {
- SocketAddress refusing = refusingEndpoint();
+ SocketAddress refusing = Utils.refusingEndpoint();
ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);
try {
IntStream.range(0, ITERATIONS).forEach(i -> {
--- a/test/jdk/java/nio/channels/SocketChannel/Connect.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/Connect.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4650679 8037360
* @summary Unit test for socket channels
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main Connect
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/ConnectState.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/ConnectState.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -23,7 +23,9 @@
/* @test
* @summary Test socket-channel connection-state transitions
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main ConnectState
*/
import java.io.*;
--- a/test/jdk/java/nio/channels/SocketChannel/FinishConnect.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/FinishConnect.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -23,7 +23,9 @@
/* @test
* @summary Test SocketChannel.finishConnect
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main FinishConnect
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/IsConnectable.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/IsConnectable.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4737146 4750573
* @summary Test if isConnectable returns true after connected
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main IsConnectable
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/LocalAddress.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/LocalAddress.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4672609 5076965 4739238
* @summary Test getLocalAddress getLocalPort
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main LocalAddress
*/
import java.net.*;
--- a/test/jdk/java/nio/channels/SocketChannel/Stream.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/Stream.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4430139
* @summary Test result of read on stream from nonblocking channel
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main Stream
*/
import java.io.*;
--- a/test/jdk/java/nio/channels/SocketChannel/VectorParams.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/SocketChannel/VectorParams.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, 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
@@ -24,7 +24,9 @@
/* @test
* @bug 4865031
* @summary Test ScatteringByteChannel/GatheringByteChannel read/write
- * @library ..
+ * @library .. /test/lib
+ * @build jdk.test.lib.Utils TestServers
+ * @run main VectorParams
*/
import java.io.*;
--- a/test/jdk/java/nio/channels/TestServers.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/nio/channels/TestServers.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, 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
@@ -31,6 +31,8 @@
import java.util.Date;
import java.util.List;
+import jdk.test.lib.Utils;
+
public class TestServers {
@@ -81,11 +83,8 @@
}
public static RefusingServer newRefusingServer() throws IOException {
- // The port 1 is reserved for TCPMUX(RFC 1078), which is seldom used,
- // and it's not used on all the test platform through JPRT.
- // So we choose to use it as a refusing "server"'s "listen" port,
- // it's much more stable than "open->close a server socket".
- return new RefusingServer(InetAddress.getLocalHost(), 1);
+ return new RefusingServer(InetAddress.getLocalHost(),
+ Utils.refusingEndpoint().getPort());
}
}
--- a/test/jdk/java/rmi/testlibrary/TestSocketFactory.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/rmi/testlibrary/TestSocketFactory.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, 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
@@ -135,7 +135,7 @@
* @param matchBytes bytes to match after the trigger has been seen
* @param replaceBytes bytes to replace the matched bytes
*/
- public void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
+ public synchronized void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
byte[] replaceBytes) {
this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
@@ -147,7 +147,7 @@
}
@Override
- public Socket createSocket(String host, int port) throws IOException {
+ public synchronized Socket createSocket(String host, int port) throws IOException {
Socket socket = RMISocketFactory.getDefaultSocketFactory()
.createSocket(host, port);
InterposeSocket s = new InterposeSocket(socket,
@@ -160,13 +160,13 @@
* Return the current list of sockets.
* @return Return a snapshot of the current list of sockets
*/
- public List<InterposeSocket> getSockets() {
+ public synchronized List<InterposeSocket> getSockets() {
List<InterposeSocket> snap = new ArrayList<>(sockets);
return snap;
}
@Override
- public ServerSocket createServerSocket(int port) throws IOException {
+ public synchronized ServerSocket createServerSocket(int port) throws IOException {
ServerSocket serverSocket = RMISocketFactory.getDefaultSocketFactory()
.createServerSocket(port);
@@ -180,7 +180,7 @@
* Return the current list of server sockets.
* @return Return a snapshot of the current list of server sockets
*/
- public List<InterposeServerSocket> getServerSockets() {
+ public synchronized List<InterposeServerSocket> getServerSockets() {
List<InterposeServerSocket> snap = new ArrayList<>(serverSockets);
return snap;
}
@@ -202,7 +202,7 @@
private final ByteArrayOutputStream inLogStream;
private final ByteArrayOutputStream outLogStream;
private final String name;
- private static volatile int num = 0; // index for created InterposeSockets
+ private static volatile int num = 0; // index for created Interpose509s
/**
* Construct a socket that interposes on a socket to match and replace.
@@ -457,7 +457,7 @@
* @param matchBytes bytes to match after the trigger has been seen
* @param replaceBytes bytes to replace the matched bytes
*/
- public void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
+ public synchronized void setMatchReplaceBytes(byte[] triggerBytes, byte[] matchBytes,
byte[] replaceBytes) {
this.triggerBytes = triggerBytes;
this.matchBytes = matchBytes;
@@ -468,7 +468,7 @@
* Return a snapshot of the current list of sockets created from this server socket.
* @return Return a snapshot of the current list of sockets
*/
- public List<InterposeSocket> getSockets() {
+ public synchronized List<InterposeSocket> getSockets() {
List<InterposeSocket> snap = new ArrayList<>(sockets);
return snap;
}
@@ -501,9 +501,12 @@
@Override
public Socket accept() throws IOException {
Socket s = socket.accept();
- InterposeSocket socket = new InterposeSocket(s, matchBytes, replaceBytes);
- sockets.add(socket);
- return socket;
+ synchronized(this) {
+ InterposeSocket aSocket = new InterposeSocket(s, matchBytes,
+ replaceBytes);
+ sockets.add(aSocket);
+ return aSocket;
+ }
}
@Override
--- a/test/jdk/java/util/ServiceLoader/ReloadTest.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/util/ServiceLoader/ReloadTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -24,7 +24,7 @@
/**
* @test
* @library modules
- * @modules java.scripting
+ * @modules jdk.scripting.nashorn
* @run testng/othervm ReloadTest
* @summary Basic test of ServiceLoader.reload
*/
--- a/test/jdk/java/util/zip/ZipFile/ReadZip.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/java/util/zip/ZipFile/ReadZip.java Mon Mar 19 10:46:31 2018 -0700
@@ -25,6 +25,7 @@
@bug 4241361 4842702 4985614 6646605 5032358 6923692 6233323 8144977 8186464
@summary Make sure we can read a zip file.
@key randomness
+ @modules jdk.zipfs
*/
import java.io.*;
--- a/test/jdk/jdk/modules/scenarios/automaticmodules/RunWithAutomaticModules.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/jdk/modules/scenarios/automaticmodules/RunWithAutomaticModules.java Mon Mar 19 10:46:31 2018 -0700
@@ -25,6 +25,8 @@
* @test
* @library /lib/testlibrary /test/lib
* @modules jdk.compiler
+ * java.scripting
+ * jdk.zipfs
* @build RunWithAutomaticModules jdk.test.lib.compiler.CompilerUtils JarUtils
* jdk.testlibrary.ProcessTools
* @run testng RunWithAutomaticModules
--- a/test/jdk/lib/testlibrary/jdk/testlibrary/Utils.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/lib/testlibrary/jdk/testlibrary/Utils.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -176,28 +176,15 @@
/**
* Returns the free port on the local host.
- * The function will spin until a valid port number is found.
*
* @return The port number
- * @throws InterruptedException if any thread has interrupted the current thread
* @throws IOException if an I/O error occurs when opening the socket
*/
- public static int getFreePort() throws InterruptedException, IOException {
- int port = -1;
-
- while (port <= 0) {
- Thread.sleep(100);
-
- ServerSocket serverSocket = null;
- try {
- serverSocket = new ServerSocket(0);
- port = serverSocket.getLocalPort();
- } finally {
- serverSocket.close();
- }
+ public static int getFreePort() throws IOException {
+ try (ServerSocket serverSocket =
+ new ServerSocket(0, 5, InetAddress.getLoopbackAddress());) {
+ return serverSocket.getLocalPort();
}
-
- return port;
}
/**
--- a/test/jdk/sun/misc/JarIndex/metaInfFilenames/Basic.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/sun/misc/JarIndex/metaInfFilenames/Basic.java Mon Mar 19 10:46:31 2018 -0700
@@ -28,6 +28,7 @@
* @modules jdk.jartool/sun.tools.jar
* jdk.httpserver
* jdk.compiler
+ * jdk.zipfs
* @run main/othervm Basic
*/
--- a/test/jdk/sun/misc/URLClassPath/ClassnameCharTest.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/sun/misc/URLClassPath/ClassnameCharTest.java Mon Mar 19 10:46:31 2018 -0700
@@ -26,6 +26,7 @@
* @summary cannot load class names containing some JSR 202 characters;
* plugin does not escape unicode character in http request
* @modules java.desktop/sun.applet
+ * jdk.httpserver
* @compile -XDignore.symbol.file=true ClassnameCharTest.java
* @run main ClassnameCharTest
*/
--- a/test/jdk/tools/pack200/Pack200Props.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/tools/pack200/Pack200Props.java Mon Mar 19 10:46:31 2018 -0700
@@ -25,7 +25,8 @@
* @test
* @bug 6575373 6969063
* @summary verify default properties of the packer/unpacker and segment limit
- * @modules jdk.compiler
+ * @modules java.logging
+ * jdk.compiler
* jdk.zipfs
* @compile -XDignore.symbol.file Utils.java Pack200Props.java
* @run main Pack200Props
--- a/test/jdk/tools/pack200/Pack200Test.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/tools/pack200/Pack200Test.java Mon Mar 19 10:46:31 2018 -0700
@@ -27,6 +27,8 @@
* @requires (sun.arch.data.model == "64" & os.maxMemory >= 4g)
* @summary test general packer/unpacker functionality
* using native and java unpackers
+ * @modules jdk.management
+ * jdk.zipfs
* @compile -XDignore.symbol.file Utils.java Pack200Test.java
* @run main/othervm/timeout=1200 -Xmx1280m -Xshare:off Pack200Test
*/
--- a/test/jdk/vm/verifier/defaultMethods/DefaultMethodRegressionTestsRun.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/jdk/vm/verifier/defaultMethods/DefaultMethodRegressionTestsRun.java Mon Mar 19 10:46:31 2018 -0700
@@ -26,6 +26,7 @@
* @bug 8003639
* @summary defaultMethod resolution and verification using an URLClassLoader
* @modules jdk.compiler
+ * jdk.zipfs
* @compile -XDignore.symbol.file=true DefaultMethodRegressionTestsRun.java
* @run main DefaultMethodRegressionTestsRun
*/
--- a/test/lib/jdk/test/lib/Utils.java Mon Mar 19 12:29:23 2018 +0530
+++ b/test/lib/jdk/test/lib/Utils.java Mon Mar 19 10:46:31 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
@@ -34,6 +35,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -260,29 +262,38 @@
}
/**
+ * Returns the socket address of an endpoint that refuses connections. The
+ * endpoint is an InetSocketAddress where the address is the loopback address
+ * and the port is a system port (1-1023 range).
+ * This method is a better choice than getFreePort for tests that need
+ * an endpoint that refuses connections.
+ */
+ public static InetSocketAddress refusingEndpoint() {
+ InetAddress lb = InetAddress.getLoopbackAddress();
+ int port = 1;
+ while (port < 1024) {
+ InetSocketAddress sa = new InetSocketAddress(lb, port);
+ try {
+ SocketChannel.open(sa).close();
+ } catch (IOException ioe) {
+ return sa;
+ }
+ port++;
+ }
+ throw new RuntimeException("Unable to find system port that is refusing connections");
+ }
+
+ /**
* Returns the free port on the local host.
- * The function will spin until a valid port number is found.
*
* @return The port number
- * @throws InterruptedException if any thread has interrupted the current thread
* @throws IOException if an I/O error occurs when opening the socket
*/
- public static int getFreePort() throws InterruptedException, IOException {
- int port = -1;
-
- while (port <= 0) {
- Thread.sleep(100);
-
- ServerSocket serverSocket = null;
- try {
- serverSocket = new ServerSocket(0);
- port = serverSocket.getLocalPort();
- } finally {
- serverSocket.close();
- }
+ public static int getFreePort() throws IOException {
+ try (ServerSocket serverSocket =
+ new ServerSocket(0, 5, InetAddress.getLoopbackAddress());) {
+ return serverSocket.getLocalPort();
}
-
- return port;
}
/**