This commit is contained in:
Phil Race 2017-12-04 10:12:46 -08:00
commit 796aeef46b
114 changed files with 1772 additions and 1472 deletions

View File

@ -68,6 +68,7 @@ $(eval $(call IncludeCustomExtension, RunTests.gmk))
TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
TEST_SUMMARY := $(TEST_RESULTS_DIR)/test-summary.txt
TEST_LAST_IDS := $(TEST_SUPPORT_DIR)/test-last-ids.txt
ifeq ($(CUSTOM_ROOT), )
JTREG_TOPDIR := $(TOPDIR)
@ -228,7 +229,8 @@ define ParseJtregTestSelection
$(if $(findstring :, $(TEST_NAME)), \
$(if $(filter :%, $(TEST_NAME)), \
$(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
$(eval TEST_ROOTS := $(JTREG_TESTROOTS)) \
$(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
$(call CleanupJtregPath, $(test_root)))) \
, \
$(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
$(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
@ -316,6 +318,7 @@ SetupRunGtestTest = $(NamedParamsMacroTemplate)
define SetupRunGtestTestBody
$1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
$1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
$1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
$1_TEST_NAME := $$(strip $$(patsubst gtest:%, %, $$($1_TEST)))
ifneq ($$($1_TEST_NAME), all)
@ -332,10 +335,13 @@ define SetupRunGtestTestBody
$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, \
$$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/server/gtestLauncher \
-jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
--gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
$$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
> >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) || true )
-jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
--gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
$$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
> >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
&& $$(ECHO) $$$$? > $$($1_EXITCODE) \
|| $$(ECHO) $$$$? > $$($1_EXITCODE) \
)
$1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
@ -343,7 +349,7 @@ define SetupRunGtestTestBody
$$(call LogWarn, Finished running test '$$($1_TEST)')
$$(call LogWarn, Test report is stored in $$(strip \
$$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
$$(if $$(wildcard $$($1_RESULT_FILE)), \
$$(if $$(wildcard $$($1_RESULT_FILE)), \
$$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE))) \
$$(if $$($1_TOTAL), , $$(eval $1_TOTAL := 0)) \
@ -398,6 +404,7 @@ SetupRunJtregTest = $(NamedParamsMacroTemplate)
define SetupRunJtregTestBody
$1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
$1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
$1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
$1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
@ -505,7 +512,10 @@ define SetupRunJtregTestBody
-workDir:$$($1_TEST_SUPPORT_DIR) \
$$(JTREG_OPTIONS) \
$$(JTREG_FAILURE_HANDLER_OPTIONS) \
$$($1_TEST_NAME) || true )
$$($1_TEST_NAME) \
&& $$(ECHO) $$$$? > $$($1_EXITCODE) \
|| $$(ECHO) $$$$? > $$($1_EXITCODE) \
)
$1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
@ -513,7 +523,7 @@ define SetupRunJtregTestBody
$$(call LogWarn, Finished running test '$$($1_TEST)')
$$(call LogWarn, Test report is stored in $$(strip \
$$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
$$(if $$(wildcard $$($1_RESULT_FILE)), \
$$(if $$(wildcard $$($1_RESULT_FILE)), \
$$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
@ -555,7 +565,7 @@ UseJtregTestHandler = \
# Now process each test to run and setup a proper make rule
$(foreach test, $(TESTS_TO_RUN), \
$(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
$(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
$(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
$(eval ALL_TEST_IDS += $(TEST_ID)) \
$(if $(call UseCustomTestHandler, $(test)), \
$(eval $(call SetupRunCustomTest, $(TEST_ID), \
@ -592,6 +602,8 @@ run-test: $(TARGETS)
# Create and print a table of the result of all tests run
$(RM) $(TEST_SUMMARY).old 2> /dev/null
$(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
$(RM) $(TEST_LAST_IDS).old 2> /dev/null
$(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
$(ECHO) >> $(TEST_SUMMARY) ==============================
$(ECHO) >> $(TEST_SUMMARY) Test summary
$(ECHO) >> $(TEST_SUMMARY) ==============================
@ -599,8 +611,9 @@ run-test: $(TARGETS)
TEST TOTAL PASS FAIL ERROR " "
$(foreach test, $(TESTS_TO_RUN), \
$(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
$(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
$(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c \\n _)) \
$(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
$(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
$(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '[_*1000]')) \
$(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
$(eval TEST_NAME := ) \
$(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" " " "$(test)" $(NEWLINE) \

View File

@ -5159,7 +5159,7 @@ VS_SDK_PLATFORM_NAME_2013=
#CUSTOM_AUTOCONF_INCLUDE
# Do not change or remove the following line, it is needed for consistency checks:
DATE_WHEN_GENERATED=1512085548
DATE_WHEN_GENERATED=1512410983
###############################################################################
#
@ -66263,23 +66263,6 @@ if test "${with_libpng+set}" = set; then :
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for which libpng to use" >&5
$as_echo_n "checking for which libpng to use... " >&6; }
# default is bundled
DEFAULT_LIBPNG=bundled
# if user didn't specify, use DEFAULT_LIBPNG
if test "x${with_libpng}" = "x"; then
with_libpng=${DEFAULT_LIBPNG}
fi
if test "x${with_libpng}" = "xbundled"; then
USE_EXTERNAL_LIBPNG=false
PNG_CFLAGS=""
PNG_LIBS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: bundled" >&5
$as_echo "bundled" >&6; }
elif test "x${with_libpng}" = "xsystem"; then
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PNG" >&5
@ -66347,6 +66330,23 @@ else
$as_echo "yes" >&6; }
LIBPNG_FOUND=yes
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for which libpng to use" >&5
$as_echo_n "checking for which libpng to use... " >&6; }
# default is bundled
DEFAULT_LIBPNG=bundled
# if user didn't specify, use DEFAULT_LIBPNG
if test "x${with_libpng}" = "x"; then
with_libpng=${DEFAULT_LIBPNG}
fi
if test "x${with_libpng}" = "xbundled"; then
USE_EXTERNAL_LIBPNG=false
PNG_CFLAGS=""
PNG_LIBS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: bundled" >&5
$as_echo "bundled" >&6; }
elif test "x${with_libpng}" = "xsystem"; then
if test "x${LIBPNG_FOUND}" = "xyes"; then
# PKG_CHECK_MODULES will set PNG_CFLAGS and PNG_LIBS
USE_EXTERNAL_LIBPNG=true
@ -66444,6 +66444,40 @@ $as_echo "bundled" >&6; }
USE_EXTERNAL_LIBZ=true
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: system" >&5
$as_echo "system" >&6; }
if test "x$USE_EXTERNAL_LIBPNG" != "xtrue"; then
# If we use bundled libpng, we must verify that we have a proper zlib.
# For instance zlib-ng has had issues with inflateValidate().
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for system zlib functionality" >&5
$as_echo_n "checking for system zlib functionality... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include "zlib.h"
int
main ()
{
#if ZLIB_VERNUM >= 0x1281
inflateValidate(NULL, 0);
#endif
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
$as_echo "ok" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not ok" >&5
$as_echo "not ok" >&6; }
as_fn_error $? "System zlib not working correctly" "$LINENO" 5
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: system not found" >&5
$as_echo "system not found" >&6; }

View File

@ -113,6 +113,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBPNG],
AC_ARG_WITH(libpng, [AS_HELP_STRING([--with-libpng],
[use libpng from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
PKG_CHECK_MODULES(PNG, libpng, [LIBPNG_FOUND=yes], [LIBPNG_FOUND=no])
AC_MSG_CHECKING([for which libpng to use])
# default is bundled
@ -128,7 +129,6 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBPNG],
PNG_LIBS=""
AC_MSG_RESULT([bundled])
elif test "x${with_libpng}" = "xsystem"; then
PKG_CHECK_MODULES(PNG, libpng, [LIBPNG_FOUND=yes], [LIBPNG_FOUND=no])
if test "x${LIBPNG_FOUND}" = "xyes"; then
# PKG_CHECK_MODULES will set PNG_CFLAGS and PNG_LIBS
USE_EXTERNAL_LIBPNG=true
@ -183,6 +183,24 @@ AC_DEFUN_ONCE([LIB_SETUP_ZLIB],
if test "x${ZLIB_FOUND}" = "xyes"; then
USE_EXTERNAL_LIBZ=true
AC_MSG_RESULT([system])
if test "x$USE_EXTERNAL_LIBPNG" != "xtrue"; then
# If we use bundled libpng, we must verify that we have a proper zlib.
# For instance zlib-ng has had issues with inflateValidate().
AC_MSG_CHECKING([for system zlib functionality])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([#include "zlib.h"], [
#if ZLIB_VERNUM >= 0x1281
inflateValidate(NULL, 0);
#endif
])],
[AC_MSG_RESULT([ok])],
[
AC_MSG_RESULT([not ok])
AC_MSG_ERROR([System zlib not working correctly])
]
)
fi
else
AC_MSG_RESULT([system not found])
AC_MSG_ERROR([--with-zlib=system specified, but no zlib found!])

View File

@ -293,6 +293,7 @@ FREETYPE_LIBS:=@FREETYPE_LIBS@
FREETYPE_CFLAGS:=@FREETYPE_CFLAGS@
FREETYPE_BUNDLE_LIB_PATH=@FREETYPE_BUNDLE_LIB_PATH@
FREETYPE_LICENSE=@FREETYPE_LICENSE@
FONTCONFIG_CFLAGS:=@FONTCONFIG_CFLAGS@
CUPS_CFLAGS:=@CUPS_CFLAGS@
ALSA_LIBS:=@ALSA_LIBS@
ALSA_CFLAGS:=@ALSA_CFLAGS@

View File

@ -148,6 +148,16 @@ void VM_Version::get_processor_features() {
PrefetchCopyIntervalInBytes = 32760;
}
if (AllocatePrefetchDistance !=-1 && (AllocatePrefetchDistance & 7)) {
warning("AllocatePrefetchDistance must be multiple of 8");
AllocatePrefetchDistance &= ~7;
}
if (AllocatePrefetchStepSize & 7) {
warning("AllocatePrefetchStepSize must be multiple of 8");
AllocatePrefetchStepSize &= ~7;
}
if (SoftwarePrefetchHintDistance != -1 &&
(SoftwarePrefetchHintDistance & 7)) {
warning("SoftwarePrefetchHintDistance must be -1, or a multiple of 8");

View File

@ -53,12 +53,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import jdk.internal.HotSpotIntrinsicCandidate;
@ -1771,7 +1770,7 @@ public final class Class<T> implements java.io.Serializable,
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
return copyFields(privateGetPublicFields(null));
return copyFields(privateGetPublicFields());
}
@ -3026,7 +3025,7 @@ public final class Class<T> implements java.io.Serializable,
// Returns an array of "root" fields. These Field objects must NOT
// be propagated to the outside world, but must instead be copied
// via ReflectionFactory.copyField.
private Field[] privateGetPublicFields(Set<Class<?>> traversedInterfaces) {
private Field[] privateGetPublicFields() {
Field[] res;
ReflectionData<T> rd = reflectionData();
if (rd != null) {
@ -3034,35 +3033,25 @@ public final class Class<T> implements java.io.Serializable,
if (res != null) return res;
}
// No cached value available; compute value recursively.
// Traverse in correct order for getField().
List<Field> fields = new ArrayList<>();
if (traversedInterfaces == null) {
traversedInterfaces = new HashSet<>();
}
// Use a linked hash set to ensure order is preserved and
// fields from common super interfaces are not duplicated
LinkedHashSet<Field> fields = new LinkedHashSet<>();
// Local fields
Field[] tmp = privateGetDeclaredFields(true);
addAll(fields, tmp);
addAll(fields, privateGetDeclaredFields(true));
// Direct superinterfaces, recursively
for (Class<?> c : getInterfaces()) {
if (!traversedInterfaces.contains(c)) {
traversedInterfaces.add(c);
addAll(fields, c.privateGetPublicFields(traversedInterfaces));
}
for (Class<?> si : getInterfaces()) {
addAll(fields, si.privateGetPublicFields());
}
// Direct superclass, recursively
if (!isInterface()) {
Class<?> c = getSuperclass();
if (c != null) {
addAll(fields, c.privateGetPublicFields(traversedInterfaces));
}
Class<?> sc = getSuperclass();
if (sc != null) {
addAll(fields, sc.privateGetPublicFields());
}
res = new Field[fields.size()];
fields.toArray(res);
res = fields.toArray(new Field[0]);
if (rd != null) {
rd.publicFields = res;
}

View File

@ -63,8 +63,8 @@ import jdk.internal.module.ServicesCatalog;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.JavaLangAccess;;
import jdk.internal.misc.SharedSecrets;;
import jdk.internal.misc.JavaLangAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.VM;
import jdk.internal.logger.LoggerFinderLoader;
import jdk.internal.logger.LazyLoggers;

View File

@ -422,8 +422,8 @@ public abstract class AbstractQueuedLongSynchronizer
* @return {@code true} if interrupted while waiting
*/
final boolean acquireQueued(final Node node, long arg) {
boolean interrupted = false;
try {
boolean interrupted = false;
for (;;) {
final Node p = node.predecessor();
if (p == head && tryAcquire(arg)) {
@ -431,12 +431,13 @@ public abstract class AbstractQueuedLongSynchronizer
p.next = null; // help GC
return interrupted;
}
if (shouldParkAfterFailedAcquire(p, node) &&
parkAndCheckInterrupt())
interrupted = true;
if (shouldParkAfterFailedAcquire(p, node))
interrupted |= parkAndCheckInterrupt();
}
} catch (Throwable t) {
cancelAcquire(node);
if (interrupted)
selfInterrupt();
throw t;
}
}
@ -510,8 +511,8 @@ public abstract class AbstractQueuedLongSynchronizer
*/
private void doAcquireShared(long arg) {
final Node node = addWaiter(Node.SHARED);
boolean interrupted = false;
try {
boolean interrupted = false;
for (;;) {
final Node p = node.predecessor();
if (p == head) {
@ -519,18 +520,18 @@ public abstract class AbstractQueuedLongSynchronizer
if (r >= 0) {
setHeadAndPropagate(node, r);
p.next = null; // help GC
if (interrupted)
selfInterrupt();
return;
}
}
if (shouldParkAfterFailedAcquire(p, node) &&
parkAndCheckInterrupt())
interrupted = true;
if (shouldParkAfterFailedAcquire(p, node))
interrupted |= parkAndCheckInterrupt();
}
} catch (Throwable t) {
cancelAcquire(node);
throw t;
} finally {
if (interrupted)
selfInterrupt();
}
}

View File

@ -505,7 +505,7 @@ public abstract class AbstractQueuedSynchronizer
*
* @return the predecessor of this node
*/
final Node predecessor() throws NullPointerException {
final Node predecessor() {
Node p = prev;
if (p == null)
throw new NullPointerException();
@ -902,8 +902,8 @@ public abstract class AbstractQueuedSynchronizer
* @return {@code true} if interrupted while waiting
*/
final boolean acquireQueued(final Node node, int arg) {
boolean interrupted = false;
try {
boolean interrupted = false;
for (;;) {
final Node p = node.predecessor();
if (p == head && tryAcquire(arg)) {
@ -911,12 +911,13 @@ public abstract class AbstractQueuedSynchronizer
p.next = null; // help GC
return interrupted;
}
if (shouldParkAfterFailedAcquire(p, node) &&
parkAndCheckInterrupt())
interrupted = true;
if (shouldParkAfterFailedAcquire(p, node))
interrupted |= parkAndCheckInterrupt();
}
} catch (Throwable t) {
cancelAcquire(node);
if (interrupted)
selfInterrupt();
throw t;
}
}
@ -990,8 +991,8 @@ public abstract class AbstractQueuedSynchronizer
*/
private void doAcquireShared(int arg) {
final Node node = addWaiter(Node.SHARED);
boolean interrupted = false;
try {
boolean interrupted = false;
for (;;) {
final Node p = node.predecessor();
if (p == head) {
@ -999,18 +1000,18 @@ public abstract class AbstractQueuedSynchronizer
if (r >= 0) {
setHeadAndPropagate(node, r);
p.next = null; // help GC
if (interrupted)
selfInterrupt();
return;
}
}
if (shouldParkAfterFailedAcquire(p, node) &&
parkAndCheckInterrupt())
interrupted = true;
if (shouldParkAfterFailedAcquire(p, node))
interrupted |= parkAndCheckInterrupt();
}
} catch (Throwable t) {
cancelAcquire(node);
throw t;
} finally {
if (interrupted)
selfInterrupt();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.*;
import java.nio.file.DirectoryStream.Filter;;
import java.nio.file.DirectoryStream.Filter;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileAttribute;

View File

@ -2746,12 +2746,12 @@ public final class Main {
if (rfc) {
dumpCert(cert, out);
} else {
out.println("Certificate #" + i++);
out.println("Certificate #" + i);
out.println("====================================");
printX509Cert((X509Certificate)cert, out);
out.println();
}
checkWeak(oneInMany(rb.getString("the.certificate"), i, chain.size()), cert);
checkWeak(oneInMany(rb.getString("the.certificate"), i++, chain.size()), cert);
} catch (Exception e) {
if (debug) {
e.printStackTrace();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -164,17 +164,14 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
res = deflateParams(strm, level, strategy);
(*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0);
(*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0);
switch (res) {
case Z_OK:
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
case Z_BUF_ERROR:
this_off += this_len - strm->avail_in;
(*env)->SetIntField(env, this, offID, this_off);
(*env)->SetIntField(env, this, lenID, strm->avail_in);
return (jint) (len - strm->avail_out);
case Z_BUF_ERROR:
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
return 0;
default:
JNU_ThrowInternalError(env, strm->msg);
return 0;
@ -203,19 +200,17 @@ Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
res = deflate(strm, finish ? Z_FINISH : flush);
(*env)->ReleasePrimitiveArrayCritical(env, b, out_buf, 0);
(*env)->ReleasePrimitiveArrayCritical(env, this_buf, in_buf, 0);
switch (res) {
case Z_STREAM_END:
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
/* fall through */
case Z_OK:
case Z_BUF_ERROR:
this_off += this_len - strm->avail_in;
(*env)->SetIntField(env, this, offID, this_off);
(*env)->SetIntField(env, this, lenID, strm->avail_in);
return len - strm->avail_out;
case Z_BUF_ERROR:
return 0;
default:
default:
JNU_ThrowInternalError(env, strm->msg);
return 0;
}

View File

@ -505,8 +505,6 @@ int ZEXPORT deflateResetKeep (strm)
s->pending = 0;
s->pending_out = s->pending_buf;
s->high_water = 0; /* reset to its inital value 0 */
if (s->wrap < 0) {
s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
}
@ -520,7 +518,7 @@ int ZEXPORT deflateResetKeep (strm)
s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
#endif
adler32(0L, Z_NULL, 0);
s->last_flush = Z_NO_FLUSH;
s->last_flush = -2;
_tr_init(s);
@ -613,7 +611,7 @@ int ZEXPORT deflateParams(strm, level, strategy)
func = configuration_table[s->level].func;
if ((strategy != s->strategy || func != configuration_table[level].func) &&
s->high_water) {
s->last_flush != -2) {
/* Flush the last buffer: */
int err = deflate(strm, Z_BLOCK);
if (err == Z_STREAM_ERROR)

View File

@ -93,4 +93,6 @@
s->status =
#ifdef GZIP
(7) deflate.c undo (6), replaced withe the official zlib repo fix see#305/#f969409

View File

@ -45,41 +45,33 @@ class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
ExtendedSocketOptions.getInstance();
protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
super.setOption(name, value);
if (isClosed()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value);
} else {
if (supportedOptions().contains(name)) {
super.setOption(name, value);
} else {
throw new UnsupportedOperationException("unsupported option");
}
super.setOption(name, value);
}
} else {
if (isClosed()) {
throw new SocketException("Socket closed");
}
extendedOptions.setOption(fd, name, value);
throw new UnsupportedOperationException("unsupported option");
}
}
@SuppressWarnings("unchecked")
protected <T> T getOption(SocketOption<T> name) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
return super.getOption(name);
if (isClosed()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
return (T) extendedOptions.getOption(fd, name);
} else {
if (supportedOptions().contains(name)) {
return super.getOption(name);
} else {
throw new UnsupportedOperationException("unsupported option");
}
return super.getOption(name);
}
} else {
if (isClosed()) {
throw new SocketException("Socket closed");
}
return (T) extendedOptions.getOption(fd, name);
throw new UnsupportedOperationException("unsupported option");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,58 +58,57 @@ class PlainSocketImpl extends AbstractPlainSocketImpl
ExtendedSocketOptions.getInstance();
protected <T> void setOption(SocketOption<T> name, T value) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
super.setOption(name, value);
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value);
} else {
if (supportedOptions().contains(name)) {
super.setOption(name, value);
} else {
throw new UnsupportedOperationException("unsupported option");
}
super.setOption(name, value);
}
} else {
if (getSocket() == null) {
throw new UnsupportedOperationException("unsupported option");
}
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
extendedOptions.setOption(fd, name, value);
throw new UnsupportedOperationException("unsupported option");
}
}
@SuppressWarnings("unchecked")
protected <T> T getOption(SocketOption<T> name) throws IOException {
if (!extendedOptions.isOptionSupported(name)) {
if (!name.equals(StandardSocketOptions.SO_REUSEPORT)) {
return super.getOption(name);
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
if (supportedOptions().contains(name)) {
if (extendedOptions.isOptionSupported(name)) {
return (T) extendedOptions.getOption(fd, name);
} else {
if (supportedOptions().contains(name)) {
return super.getOption(name);
} else {
throw new UnsupportedOperationException("unsupported option");
}
return super.getOption(name);
}
} else {
if (getSocket() == null) {
throw new UnsupportedOperationException("unsupported option");
}
if (isClosedOrPending()) {
throw new SocketException("Socket closed");
}
return (T) extendedOptions.getOption(fd, name);
throw new UnsupportedOperationException("unsupported option");
}
}
protected Set<SocketOption<?>> supportedOptions() {
HashSet<SocketOption<?>> options = new HashSet<>(super.supportedOptions());
if (getSocket() != null) {
options.addAll(extendedOptions.options());
}
addExtSocketOptions(extendedOptions.options(), options);
return options;
}
private void addExtSocketOptions(Set<SocketOption<?>> extOptions,
Set<SocketOption<?>> options) {
extOptions.forEach((option) -> {
if (option.name().equals("SO_FLOW_SLA")) {
// SO_FLOW_SLA is Solaris specific option which is not applicable
// for ServerSockets.
// getSocket() will always return null for server socket
if (getSocket() != null) {
options.add(option);
}
} else {
options.add(option);
}
});
}
protected void socketSetOption(int opt, boolean b, Object val) throws SocketException {
if (opt == SocketOptions.SO_REUSEPORT &&
!supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,7 @@ package sun.awt;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;

View File

@ -1410,7 +1410,6 @@ Java_sun_security_jgss_wrapper_GSSLibStub_getMic(JNIEnv *env, jobject jobj,
checkStatus(env, jobj, GSS_S_CONTEXT_EXPIRED, 0, "[GSSLibStub_getMic]");
return NULL;
}
contextHdl = (gss_ctx_id_t) jlong_to_ptr(pContext);
qop = (gss_qop_t) jqop;
initGSSBuffer(env, jmsg, &msg);
if ((*env)->ExceptionCheck(env)) {

View File

@ -115,7 +115,7 @@ public class Lint
values = EnumSet.noneOf(LintCategory.class);
Source source = Source.instance(context);
if (source.compareTo(Source.JDK1_9) >= 0) {
if (source.compareTo(Source.JDK9) >= 0) {
values.add(LintCategory.DEP_ANN);
}
values.add(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC);

View File

@ -31,7 +31,12 @@ import javax.lang.model.SourceVersion;
import static javax.lang.model.SourceVersion.*;
import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
import static com.sun.tools.javac.main.Option.*;
/** The source language version accepted.
@ -59,22 +64,22 @@ public enum Source {
/** 1.5 introduced generics, attributes, foreach, boxing, static import,
* covariant return, enums, varargs, et al. */
JDK1_5("1.5"),
JDK5("5"),
/** 1.6 reports encoding problems as errors instead of warnings. */
JDK1_6("1.6"),
JDK6("6"),
/** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
JDK1_7("1.7"),
JDK7("7"),
/** 1.8 lambda expressions and default methods. */
JDK1_8("1.8"),
JDK8("8"),
/** 1.9 modularity. */
JDK1_9("1.9"),
JDK9("9"),
/** 1.10 covers the to be determined language features that will be added in JDK 10. */
JDK1_10("1.10");
JDK10("10");
private static final Context.Key<Source> sourceKey = new Context.Key<>();
@ -97,19 +102,19 @@ public enum Source {
for (Source s : values()) {
tab.put(s.name, s);
}
tab.put("5", JDK1_5); // Make 5 an alias for 1.5
tab.put("6", JDK1_6); // Make 6 an alias for 1.6
tab.put("7", JDK1_7); // Make 7 an alias for 1.7
tab.put("8", JDK1_8); // Make 8 an alias for 1.8
tab.put("9", JDK1_9); // Make 9 an alias for 1.9
tab.put("10", JDK1_10); // Make 10 an alias for 1.10
tab.put("1.5", JDK5); // Make 5 an alias for 1.5
tab.put("1.6", JDK6); // Make 6 an alias for 1.6
tab.put("1.7", JDK7); // Make 7 an alias for 1.7
tab.put("1.8", JDK8); // Make 8 an alias for 1.8
tab.put("1.9", JDK9); // Make 9 an alias for 1.9
tab.put("1.10", JDK10); // Make 10 an alias for 1.10
}
private Source(String name) {
this.name = name;
}
public static final Source MIN = Source.JDK1_6;
public static final Source MIN = Source.JDK6;
private static final Source MAX = values()[values().length - 1];
@ -120,114 +125,108 @@ public enum Source {
}
public Target requiredTarget() {
if (this.compareTo(JDK1_10) >= 0) return Target.JDK1_10;
if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9;
if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
return Target.JDK1_1;
}
public boolean allowDiamond() {
return compareTo(JDK1_7) >= 0;
/**
* Models a feature of the Java programming language. Each feature can be associated with a
* minimum source level, a maximum source level and a diagnostic fragment describing the feature,
* which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
*/
public enum Feature {
DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
MULTICATCH(JDK7, Fragments.FeatureMulticatch, DiagKind.PLURAL),
IMPROVED_RETHROW_ANALYSIS(JDK7),
IMPROVED_CATCH_ANALYSIS(JDK7),
MODULES(JDK9, Fragments.FeatureModules, DiagKind.PLURAL),
TRY_WITH_RESOURCES(JDK7, Fragments.FeatureTryWithResources, DiagKind.NORMAL),
EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES(JDK9, Fragments.FeatureVarInTryWithResources, DiagKind.PLURAL),
BINARY_LITERALS(JDK7, Fragments.FeatureBinaryLit, DiagKind.PLURAL),
UNDERSCORES_IN_LITERALS(JDK7, Fragments.FeatureUnderscoreLit, DiagKind.PLURAL),
STRINGS_IN_SWITCH(JDK7, Fragments.FeatureStringSwitch, DiagKind.PLURAL),
DEPRECATION_ON_IMPORT(MIN, JDK9),
SIMPLIFIED_VARARGS(JDK7),
OBJECT_TO_PRIMITIVE_CAST(JDK7),
ENFORCE_THIS_DOT_INIT(JDK7),
POLY(JDK8),
LAMBDA(JDK8, Fragments.FeatureLambda, DiagKind.PLURAL),
METHOD_REFERENCES(JDK8, Fragments.FeatureMethodReferences, DiagKind.PLURAL),
DEFAULT_METHODS(JDK8, Fragments.FeatureDefaultMethods, DiagKind.PLURAL),
STATIC_INTERFACE_METHODS(JDK8, Fragments.FeatureStaticIntfMethods, DiagKind.PLURAL),
STATIC_INTERFACE_METHODS_INVOKE(JDK8, Fragments.FeatureStaticIntfMethodInvoke, DiagKind.PLURAL),
STRICT_METHOD_CLASH_CHECK(JDK8),
EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
GRAPH_INFERENCE(JDK8),
FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
PRIVATE_SAFE_VARARGS(JDK9),
DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
UNDERSCORE_IDENTIFIER(MIN, JDK8),
PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
LOCAL_VARIABLE_TYPE_INFERENCE(JDK10);
enum DiagKind {
NORMAL,
PLURAL;
}
private final Source minLevel;
private final Source maxLevel;
private final Fragment optFragment;
private final DiagKind optKind;
Feature(Source minLevel) {
this(minLevel, null, null);
}
Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
this(minLevel, MAX, optFragment, optKind);
}
Feature(Source minLevel, Source maxLevel) {
this(minLevel, maxLevel, null, null);
}
Feature(Source minLevel, Source maxLevel, Fragment optFragment, DiagKind optKind) {
this.minLevel = minLevel;
this.maxLevel = maxLevel;
this.optFragment = optFragment;
this.optKind = optKind;
}
public boolean allowedInSource(Source source) {
return source.compareTo(minLevel) >= 0 &&
source.compareTo(maxLevel) <= 0;
}
public Fragment fragment(String sourceName) {
Assert.checkNonNull(optFragment);
return optKind == DiagKind.NORMAL ?
Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
}
public Error error(String sourceName) {
Assert.checkNonNull(optFragment);
return optKind == DiagKind.NORMAL ?
Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
}
}
public boolean allowMulticatch() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowImprovedRethrowAnalysis() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowImprovedCatchAnalysis() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowModules() {
return compareTo(JDK1_9) >= 0;
}
public boolean allowTryWithResources() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowEffectivelyFinalVariablesInTryWithResources() {
return compareTo(JDK1_9) >= 0;
}
public boolean allowBinaryLiterals() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowUnderscoresInLiterals() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowStringsInSwitch() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowDeprecationOnImport() {
return compareTo(JDK1_9) < 0;
}
public boolean allowSimplifiedVarargs() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowObjectToPrimitiveCast() {
return compareTo(JDK1_7) >= 0;
}
public boolean enforceThisDotInit() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowPoly() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowLambda() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowMethodReferences() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowDefaultMethods() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowStaticInterfaceMethods() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowStrictMethodClashCheck() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowEffectivelyFinalInInnerClasses() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowTypeAnnotations() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowAnnotationsAfterTypeParams() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowRepeatedAnnotations() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowIntersectionTypesInCast() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowGraphInference() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowFunctionalInterfaceMostSpecific() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowPostApplicabilityVarargsAccessCheck() {
return compareTo(JDK1_8) >= 0;
}
public boolean mapCapturesToBounds() {
return compareTo(JDK1_8) < 0;
}
public boolean allowPrivateSafeVarargs() {
return compareTo(JDK1_9) >= 0;
}
public boolean allowDiamondWithAnonymousClassCreation() {
return compareTo(JDK1_9) >= 0;
}
public boolean allowUnderscoreIdentifier() {
return compareTo(JDK1_8) <= 0;
}
public boolean allowPrivateInterfaceMethods() { return compareTo(JDK1_9) >= 0; }
public boolean allowLocalVariableTypeInference() { return compareTo(JDK1_10) >= 0; }
public static SourceVersion toSourceVersion(Source source) {
switch(source) {
case JDK1_2:
@ -236,17 +235,17 @@ public enum Source {
return RELEASE_3;
case JDK1_4:
return RELEASE_4;
case JDK1_5:
case JDK5:
return RELEASE_5;
case JDK1_6:
case JDK6:
return RELEASE_6;
case JDK1_7:
case JDK7:
return RELEASE_7;
case JDK1_8:
case JDK8:
return RELEASE_8;
case JDK1_9:
case JDK9:
return RELEASE_9;
case JDK1_10:
case JDK10:
return RELEASE_10;
default:
return null;

View File

@ -35,6 +35,7 @@ import java.util.Map;
import javax.lang.model.element.ElementVisitor;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.Completer;
import com.sun.tools.javac.code.Symbol.CompletionFailure;
@ -468,7 +469,7 @@ public class Symtab {
scope.enter(errSymbol);
Source source = Source.instance(context);
if (source.allowModules()) {
if (Feature.MODULES.allowedInSource(source)) {
java_base = enterModule(names.java_base);
//avoid completing java.base during the Symtab initialization
java_base.completer = Completer.NULL_COMPLETER;

View File

@ -41,6 +41,7 @@ import javax.tools.JavaFileObject;
import com.sun.tools.javac.code.Attribute.RetentionPolicy;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
import com.sun.tools.javac.comp.AttrContext;
@ -113,9 +114,9 @@ public class Types {
syms = Symtab.instance(context);
names = Names.instance(context);
Source source = Source.instance(context);
allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast();
allowDefaultMethods = source.allowDefaultMethods();
mapCapturesToBounds = source.mapCapturesToBounds();
allowObjectToPrimitiveCast = Feature.OBJECT_TO_PRIMITIVE_CAST.allowedInSource(source);
allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source);
mapCapturesToBounds = Feature.MAP_CAPTURES_TO_BOUNDS.allowedInSource(source);
chk = Check.instance(context);
enter = Enter.instance(context);
capturedName = names.fromString("<captured wildcard>");

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
import com.sun.source.tree.LambdaExpressionTree;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext;
@ -128,7 +129,7 @@ public class Analyzer {
String findOpt = options.get("find");
//parse modes
Source source = Source.instance(context);
allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
allowDiamondWithAnonymousClassCreation = Feature.DIAMOND_WITH_ANONYMOUS_CLASS_CREATION.allowedInSource(source);
analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source);
}
@ -137,17 +138,17 @@ public class Analyzer {
* the {@code -XDfind} option.
*/
enum AnalyzerMode {
DIAMOND("diamond", Source::allowDiamond),
LAMBDA("lambda", Source::allowLambda),
METHOD("method", Source::allowGraphInference),
LOCAL("local", Source::allowLocalVariableTypeInference);
DIAMOND("diamond", Feature.DIAMOND),
LAMBDA("lambda", Feature.LAMBDA),
METHOD("method", Feature.GRAPH_INFERENCE),
LOCAL("local", Feature.LOCAL_VARIABLE_TYPE_INFERENCE);
final String opt;
final Predicate<Source> sourceFilter;
final Feature feature;
AnalyzerMode(String opt, Predicate<Source> sourceFilter) {
AnalyzerMode(String opt, Feature feature) {
this.opt = opt;
this.sourceFilter = sourceFilter;
this.feature = feature;
}
/**
@ -168,7 +169,7 @@ public class Analyzer {
for (AnalyzerMode mode : values()) {
if (modes.contains(mode.opt)) {
res.add(mode);
} else if (modes.contains("-" + mode.opt) || !mode.sourceFilter.test(source)) {
} else if (modes.contains("-" + mode.opt) || !mode.feature.allowedInSource(source)) {
res.remove(mode);
}
}

View File

@ -30,10 +30,12 @@ import com.sun.tools.javac.code.Attribute.Compound;
import com.sun.tools.javac.code.Attribute.TypeCompound;
import com.sun.tools.javac.code.Kinds.KindSelector;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.TypeMetadata.Entry.Kind;
import com.sun.tools.javac.comp.Check.CheckContext;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.TreeInfo;
@ -121,7 +123,7 @@ public class Annotate {
theUnfinishedDefaultValue = new Attribute.Error(syms.errType);
Source source = Source.instance(context);
allowRepeatedAnnos = source.allowRepeatedAnnotations();
allowRepeatedAnnos = Feature.REPEATED_ANNOTATIONS.allowedInSource(source);
sourceName = source.name;
blockCount = 1;
@ -344,7 +346,7 @@ public class Annotate {
if (annotated.containsKey(a.type.tsym)) {
if (!allowRepeatedAnnos) {
log.error(DiagnosticFlag.SOURCE_LEVEL, a.pos(), Errors.RepeatableAnnotationsNotSupportedInSource(sourceName));
log.error(DiagnosticFlag.SOURCE_LEVEL, a.pos(), Feature.REPEATED_ANNOTATIONS.error(sourceName));
}
ListBuffer<T> l = annotated.get(a.type.tsym);
l = l.append(c);

View File

@ -38,6 +38,7 @@ import com.sun.source.util.SimpleTreeVisitor;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.code.TypeMetadata.Annotations;
@ -150,12 +151,12 @@ public class Attr extends JCTree.Visitor {
Options options = Options.instance(context);
Source source = Source.instance(context);
allowStringsInSwitch = source.allowStringsInSwitch();
allowPoly = source.allowPoly();
allowTypeAnnos = source.allowTypeAnnotations();
allowLambda = source.allowLambda();
allowDefaultMethods = source.allowDefaultMethods();
allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
allowStringsInSwitch = Feature.STRINGS_IN_SWITCH.allowedInSource(source);
allowPoly = Feature.POLY.allowedInSource(source);
allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source);
allowLambda = Feature.LAMBDA.allowedInSource(source);
allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source);
allowStaticInterfaceMethods = Feature.STATIC_INTERFACE_METHODS.allowedInSource(source);
sourceName = source.name;
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
@ -1392,7 +1393,7 @@ public class Attr extends JCTree.Visitor {
boolean enumSwitch = (seltype.tsym.flags() & Flags.ENUM) != 0;
boolean stringSwitch = types.isSameType(seltype, syms.stringType);
if (stringSwitch && !allowStringsInSwitch) {
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.selector.pos(), Errors.StringSwitchNotSupportedInSource(sourceName));
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.selector.pos(), Feature.STRINGS_IN_SWITCH.error(sourceName));
}
if (!enumSwitch && !stringSwitch)
seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType);
@ -3667,7 +3668,7 @@ public class Attr extends JCTree.Visitor {
}
if (!allowStaticInterfaceMethods && sitesym.isInterface() &&
sym.isStatic() && sym.kind == MTH) {
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.pos(), Errors.StaticIntfMethodInvokeNotSupportedInSource(sourceName));
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.pos(), Feature.STATIC_INTERFACE_METHODS_INVOKE.error(sourceName));
}
} else if (sym.kind != ERR &&
(sym.flags() & STATIC) != 0 &&

View File

@ -33,6 +33,7 @@ import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Attribute.Compound;
import com.sun.tools.javac.code.Directive.ExportsDirective;
import com.sun.tools.javac.code.Directive.RequiresDirective;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
import com.sun.tools.javac.jvm.*;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
@ -127,11 +128,6 @@ public class Check {
fileManager = context.get(JavaFileManager.class);
source = Source.instance(context);
allowSimplifiedVarargs = source.allowSimplifiedVarargs();
allowDefaultMethods = source.allowDefaultMethods();
allowStrictMethodClashCheck = source.allowStrictMethodClashCheck();
allowPrivateSafeVarargs = source.allowPrivateSafeVarargs();
allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
warnOnAnyAccessToMembers = options.isSet("warnOnAccessToMembers");
Target target = Target.instance(context);
@ -156,26 +152,6 @@ public class Check {
deferredLintHandler = DeferredLintHandler.instance(context);
}
/** Switch: simplified varargs enabled?
*/
boolean allowSimplifiedVarargs;
/** Switch: default methods enabled?
*/
boolean allowDefaultMethods;
/** Switch: should unrelated return types trigger a method clash?
*/
boolean allowStrictMethodClashCheck;
/** Switch: can the @SafeVarargs annotation be applied to private methods?
*/
boolean allowPrivateSafeVarargs;
/** Switch: can diamond inference be used in anonymous instance creation ?
*/
boolean allowDiamondWithAnonymousClassCreation;
/** Character for synthetic names
*/
char syntheticNameChar;
@ -256,7 +232,7 @@ public class Check {
* @param pos Position to be used for error reporting.
*/
void warnUnsafeVararg(DiagnosticPosition pos, String key, Object... args) {
if (lint.isEnabled(LintCategory.VARARGS) && allowSimplifiedVarargs)
if (lint.isEnabled(LintCategory.VARARGS) && Feature.SIMPLIFIED_VARARGS.allowedInSource(source))
log.warning(LintCategory.VARARGS, pos, key, args);
}
@ -814,9 +790,9 @@ public class Check {
t.isErroneous()) {
return checkClassType(tree.clazz.pos(), t, true);
} else {
if (tree.def != null && !allowDiamondWithAnonymousClassCreation) {
if (tree.def != null && !Feature.DIAMOND_WITH_ANONYMOUS_CLASS_CREATION.allowedInSource(source)) {
log.error(DiagnosticFlag.SOURCE_LEVEL, tree.clazz.pos(),
Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name)));
Errors.CantApplyDiamond1(t, Feature.DIAMOND_WITH_ANONYMOUS_CLASS_CREATION.fragment(source.name)));
}
if (t.tsym.type.getTypeArguments().isEmpty()) {
log.error(tree.clazz.pos(),
@ -906,7 +882,7 @@ public class Check {
void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) {
MethodSymbol m = tree.sym;
if (!allowSimplifiedVarargs) return;
if (!Feature.SIMPLIFIED_VARARGS.allowedInSource(source)) return;
boolean hasTrustMeAnno = m.attribute(syms.trustMeType.tsym) != null;
Type varargElemType = null;
if (m.isVarArgs()) {
@ -914,7 +890,7 @@ public class Check {
}
if (hasTrustMeAnno && !isTrustMeAllowedOnMethod(m)) {
if (varargElemType != null) {
JCDiagnostic msg = allowPrivateSafeVarargs ?
JCDiagnostic msg = Feature.PRIVATE_SAFE_VARARGS.allowedInSource(source) ?
diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargs(m)) :
diags.fragment(Fragments.VarargsTrustmeOnVirtualVarargsFinalOnly(m));
log.error(tree,
@ -942,7 +918,7 @@ public class Check {
return (s.flags() & VARARGS) != 0 &&
(s.isConstructor() ||
(s.flags() & (STATIC | FINAL |
(allowPrivateSafeVarargs ? PRIVATE : 0) )) != 0);
(Feature.PRIVATE_SAFE_VARARGS.allowedInSource(source) ? PRIVATE : 0) )) != 0);
}
Type checkLocalVarType(DiagnosticPosition pos, Type t, Name name) {
@ -1019,7 +995,7 @@ public class Check {
if (useVarargs) {
Type argtype = owntype.getParameterTypes().last();
if (!types.isReifiable(argtype) &&
(!allowSimplifiedVarargs ||
(!Feature.SIMPLIFIED_VARARGS.allowedInSource(source) ||
sym.baseSymbol().attribute(syms.trustMeType.tsym) == null ||
!isTrustMeAllowedOnMethod(sym))) {
warnUnchecked(env.tree.pos(),
@ -2489,7 +2465,7 @@ public class Check {
if (m2 == m1) continue;
//if (i) the signature of 'sym' is not a subsignature of m1 (seen as
//a member of 'site') and (ii) m1 has the same erasure as m2, issue an error
if (!types.isSubSignature(sym.type, types.memberType(site, m2), allowStrictMethodClashCheck) &&
if (!types.isSubSignature(sym.type, types.memberType(site, m2), Feature.STRICT_METHOD_CLASH_CHECK.allowedInSource(source)) &&
types.hasSameArgs(m2.erasure(types), m1.erasure(types))) {
sym.flags_field |= CLASH;
if (m1 == sym) {
@ -2534,7 +2510,7 @@ public class Check {
for (Symbol s : types.membersClosure(site, true).getSymbolsByName(sym.name, cf)) {
//if (i) the signature of 'sym' is not a subsignature of m1 (seen as
//a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error
if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) {
if (!types.isSubSignature(sym.type, types.memberType(site, s), Feature.STRICT_METHOD_CLASH_CHECK.allowedInSource(source))) {
if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
log.error(pos,
Errors.NameClashSameErasureNoHide(sym, sym.location(), s, s.location()));
@ -2634,7 +2610,7 @@ public class Check {
void checkPotentiallyAmbiguousOverloads(DiagnosticPosition pos, Type site,
MethodSymbol msym1, MethodSymbol msym2) {
if (msym1 != msym2 &&
allowDefaultMethods &&
Feature.DEFAULT_METHODS.allowedInSource(source) &&
lint.isEnabled(LintCategory.OVERLOADS) &&
(msym1.flags() & POTENTIALLY_AMBIGUOUS) == 0 &&
(msym2.flags() & POTENTIALLY_AMBIGUOUS) == 0) {

View File

@ -32,6 +32,7 @@ import java.util.HashMap;
import com.sun.source.tree.LambdaExpressionTree.BodyKind;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
import com.sun.tools.javac.tree.*;
@ -291,10 +292,10 @@ public class Flow {
rs = Resolve.instance(context);
diags = JCDiagnostic.Factory.instance(context);
Source source = Source.instance(context);
allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis();
allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis();
allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses();
enforceThisDotInit = source.enforceThisDotInit();
allowImprovedRethrowAnalysis = Feature.IMPROVED_RETHROW_ANALYSIS.allowedInSource(source);
allowImprovedCatchAnalysis = Feature.IMPROVED_CATCH_ANALYSIS.allowedInSource(source);
allowEffectivelyFinalInInnerClasses = Feature.EFFECTIVELY_FINAL_IN_INNER_CLASSES.allowedInSource(source);
enforceThisDotInit = Feature.ENFORCE_THIS_DOT_INIT.allowedInSource(source);
}
/**

View File

@ -25,6 +25,7 @@
package com.sun.tools.javac.comp;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Type.UndetVar.UndetVarListener;
import com.sun.tools.javac.code.Types.TypeMapping;
import com.sun.tools.javac.comp.Attr.CheckMode;
@ -116,7 +117,8 @@ public class Infer {
log = Log.instance(context);
inferenceException = new InferenceException(diags);
Options options = Options.instance(context);
allowGraphInference = Source.instance(context).allowGraphInference()
Source source = Source.instance(context);
allowGraphInference = Feature.GRAPH_INFERENCE.allowedInSource(source)
&& options.isUnset("useLegacyInference");
dependenciesFolder = options.get("debug.dumpInferenceGraphsTo");
pendingGraphs = List.nil();

View File

@ -66,6 +66,7 @@ import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.ModuleFinder;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.Completer;
@ -185,7 +186,7 @@ public class Modules extends JCTree.Visitor {
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
source = Source.instance(context);
allowModules = source.allowModules();
allowModules = Feature.MODULES.allowedInSource(source);
Options options = Options.instance(context);
allowAccessIntoSystem = options.isUnset(Option.RELEASE);

View File

@ -28,6 +28,7 @@ package com.sun.tools.javac.comp;
import com.sun.tools.javac.api.Formattable.LocalizedString;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.*;
import com.sun.tools.javac.comp.Attr.ResultInfo;
@ -137,15 +138,15 @@ public class Resolve {
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
Target target = Target.instance(context);
allowMethodHandles = target.hasMethodHandles();
allowFunctionalInterfaceMostSpecific = source.allowFunctionalInterfaceMostSpecific();
allowLocalVariableTypeInference = source.allowLocalVariableTypeInference();
allowFunctionalInterfaceMostSpecific = Feature.FUNCTIONAL_INTERFACE_MOST_SPECIFIC.allowedInSource(source);
allowLocalVariableTypeInference = Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source);
checkVarargsAccessAfterResolution =
source.allowPostApplicabilityVarargsAccessCheck();
Feature.POST_APPLICABILITY_VARARGS_ACCESS_CHECK.allowedInSource(source);
polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
inapplicableMethodException = new InapplicableMethodException(diags);
allowModules = source.allowModules();
allowModules = Feature.MODULES.allowedInSource(source);
}
/** error symbols, which are returned when resolution fails

View File

@ -29,6 +29,7 @@ import java.util.*;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Attribute.TypeCompound;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.tree.*;
@ -94,8 +95,8 @@ public class TransTypes extends TreeTranslator {
make = TreeMaker.instance(context);
resolve = Resolve.instance(context);
Source source = Source.instance(context);
allowInterfaceBridges = source.allowDefaultMethods();
allowGraphInference = source.allowGraphInference();
allowInterfaceBridges = Feature.DEFAULT_METHODS.allowedInSource(source);
allowGraphInference = Feature.GRAPH_INFERENCE.allowedInSource(source);
annotate = Annotate.instance(context);
attr = Attr.instance(context);
}

View File

@ -37,6 +37,7 @@ import com.sun.tools.javac.code.Scope.ImportFilter;
import com.sun.tools.javac.code.Scope.NamedImportScope;
import com.sun.tools.javac.code.Scope.StarImportScope;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.util.*;
@ -137,8 +138,8 @@ public class TypeEnter implements Completer {
typeEnvs = TypeEnvs.instance(context);
dependencies = Dependencies.instance(context);
Source source = Source.instance(context);
allowTypeAnnos = source.allowTypeAnnotations();
allowDeprecationOnImport = source.allowDeprecationOnImport();
allowTypeAnnos = Feature.TYPE_ANNOTATIONS.allowedInSource(source);
allowDeprecationOnImport = Feature.DEPRECATION_ON_IMPORT.allowedInSource(source);
}
/** Switch: support type annotations.

View File

@ -42,6 +42,7 @@ import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.comp.Annotate;
import com.sun.tools.javac.comp.Annotate.AnnotationTypeCompleter;
import com.sun.tools.javac.code.*;
@ -246,8 +247,8 @@ public class ClassReader {
verbose = options.isSet(Option.VERBOSE);
Source source = Source.instance(context);
allowSimplifiedVarargs = source.allowSimplifiedVarargs();
allowModules = source.allowModules();
allowSimplifiedVarargs = Feature.SIMPLIFIED_VARARGS.allowedInSource(source);
allowModules = Feature.MODULES.allowedInSource(source);
saveParameterNames = options.isSet(PARAMETERS);

View File

@ -54,6 +54,7 @@ import javax.tools.StandardLocation;
import com.sun.tools.doclint.DocLint;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.file.BaseFileManager;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.Profile;

View File

@ -52,6 +52,7 @@ import com.sun.source.util.TaskEvent;
import com.sun.tools.javac.api.MultiTaskListener;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Lint.LintCategory;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.CompletionFailure;
import com.sun.tools.javac.code.Symbol.PackageSymbol;
@ -684,7 +685,7 @@ public class JavaCompiler {
if (sep == -1) {
msym = modules.getDefaultModule();
typeName = name;
} else if (source.allowModules()) {
} else if (Feature.MODULES.allowedInSource(source)) {
Name modName = names.fromString(name.substring(0, sep));
msym = moduleFinder.findModule(modName);
@ -1544,7 +1545,7 @@ public class JavaCompiler {
env.tree = transTypes.translateTopLevelClass(env.tree, localMake);
compileStates.put(env, CompileState.TRANSTYPES);
if (source.allowLambda() && scanner.hasLambdas) {
if (Feature.LAMBDA.allowedInSource(source) && scanner.hasLambdas) {
if (shouldStop(CompileState.UNLAMBDA))
return;

View File

@ -51,6 +51,7 @@ import com.sun.tools.javac.code.Directive.OpensFlag;
import com.sun.tools.javac.code.Directive.RequiresDirective;
import com.sun.tools.javac.code.Directive.RequiresFlag;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Enter;
@ -114,7 +115,7 @@ public class JavacElements implements Elements {
javacTaskImpl = t instanceof JavacTaskImpl ? (JavacTaskImpl) t : null;
log = Log.instance(context);
Source source = Source.instance(context);
allowModules = source.allowModules();
allowModules = Feature.MODULES.allowedInSource(source);
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)

View File

@ -26,8 +26,11 @@
package com.sun.tools.javac.parser;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import java.nio.CharBuffer;
@ -46,14 +49,6 @@ public class JavaTokenizer {
private static final boolean scannerDebug = false;
/** Allow binary literals.
*/
private boolean allowBinaryLiterals;
/** Allow underscores in literals.
*/
private boolean allowUnderscoresInLiterals;
/** The source language setting.
*/
private Source source;
@ -121,14 +116,24 @@ public class JavaTokenizer {
this.tokens = fac.tokens;
this.source = fac.source;
this.reader = reader;
this.allowBinaryLiterals = source.allowBinaryLiterals();
this.allowUnderscoresInLiterals = source.allowUnderscoresInLiterals();
}
private void checkSourceLevel(int pos, Feature feature) {
if (!feature.allowedInSource(source)) {
lexError(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name));
}
}
/** Report an error at the given position using the provided arguments.
*/
protected void lexError(int pos, String key, Object... args) {
log.error(pos, key, args);
protected void lexError(int pos, JCDiagnostic.Error key) {
log.error(pos, key);
tk = TokenKind.ERROR;
errPos = pos;
}
protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) {
log.error(flags, pos, key);
tk = TokenKind.ERROR;
errPos = pos;
}
@ -175,7 +180,7 @@ public class JavaTokenizer {
case '\\':
reader.putChar('\\', true); break;
default:
lexError(reader.bp, "illegal.esc.char");
lexError(reader.bp, Errors.IllegalEscChar);
}
}
} else if (reader.bp != reader.buflen) {
@ -190,17 +195,14 @@ public class JavaTokenizer {
if (reader.ch != '_') {
reader.putChar(false);
} else {
if (!allowUnderscoresInLiterals) {
lexError(pos, "unsupported.underscore.lit", source.name);
allowUnderscoresInLiterals = true;
}
checkSourceLevel(pos, Feature.UNDERSCORES_IN_LITERALS);
}
saveCh = reader.ch;
savePos = reader.bp;
reader.scanChar();
} while (reader.digit(pos, digitRadix) >= 0 || reader.ch == '_');
if (saveCh == '_')
lexError(savePos, "illegal.underscore");
lexError(savePos, Errors.IllegalUnderscore);
}
/** Read fractional part of hexadecimal floating point number.
@ -216,11 +218,11 @@ public class JavaTokenizer {
if (reader.digit(pos, 10) >= 0) {
scanDigits(pos, 10);
if (!hexFloatsWork)
lexError(pos, "unsupported.cross.fp.lit");
lexError(pos, Errors.UnsupportedCrossFpLit);
} else
lexError(pos, "malformed.fp.lit");
lexError(pos, Errors.MalformedFpLit);
} else {
lexError(pos, "malformed.fp.lit");
lexError(pos, Errors.MalformedFpLit);
}
if (reader.ch == 'f' || reader.ch == 'F') {
reader.putChar(true);
@ -254,7 +256,7 @@ public class JavaTokenizer {
scanDigits(pos, 10);
return;
}
lexError(pos, "malformed.fp.lit");
lexError(pos, Errors.MalformedFpLit);
reader.sp = sp1;
}
}
@ -287,14 +289,14 @@ public class JavaTokenizer {
scanDigits(pos, 16);
}
if (!seendigit)
lexError(pos, "invalid.hex.number");
lexError(pos, Errors.InvalidHexNumber);
else
scanHexExponentAndSuffix(pos);
}
private void skipIllegalUnderscores() {
if (reader.ch == '_') {
lexError(reader.bp, "illegal.underscore");
lexError(reader.bp, Errors.IllegalUnderscore);
while (reader.ch == '_')
reader.scanChar();
}
@ -329,10 +331,10 @@ public class JavaTokenizer {
if (!seenValidDigit) {
switch (radix) {
case 2:
lexError(pos, "invalid.binary.number");
lexError(pos, Errors.InvalidBinaryNumber);
break;
case 16:
lexError(pos, "invalid.hex.number");
lexError(pos, Errors.InvalidHexNumber);
break;
}
}
@ -504,10 +506,7 @@ public class JavaTokenizer {
skipIllegalUnderscores();
scanNumber(pos, 16);
} else if (reader.ch == 'b' || reader.ch == 'B') {
if (!allowBinaryLiterals) {
lexError(pos, "unsupported.binary.lit", source.name);
allowBinaryLiterals = true;
}
checkSourceLevel(pos, Feature.BINARY_LITERALS);
reader.scanChar();
skipIllegalUnderscores();
scanNumber(pos, 2);
@ -519,7 +518,7 @@ public class JavaTokenizer {
reader.scanChar();
} while (reader.ch == '_');
if (reader.digit(pos, 10) < 0) {
lexError(savePos, "illegal.underscore");
lexError(savePos, Errors.IllegalUnderscore);
}
}
scanNumber(pos, 8);
@ -542,7 +541,7 @@ public class JavaTokenizer {
reader.putChar('.');
tk = TokenKind.ELLIPSIS;
} else {
lexError(savePos, "illegal.dot");
lexError(savePos, Errors.IllegalDot);
}
} else {
tk = TokenKind.DOT;
@ -600,7 +599,7 @@ public class JavaTokenizer {
comments = addComment(comments, processComment(pos, reader.bp, style));
break;
} else {
lexError(pos, "unclosed.comment");
lexError(pos, Errors.UnclosedComment);
break loop;
}
} else if (reader.ch == '=') {
@ -613,17 +612,17 @@ public class JavaTokenizer {
case '\'':
reader.scanChar();
if (reader.ch == '\'') {
lexError(pos, "empty.char.lit");
lexError(pos, Errors.EmptyCharLit);
reader.scanChar();
} else {
if (reader.ch == CR || reader.ch == LF)
lexError(pos, "illegal.line.end.in.char.lit");
lexError(pos, Errors.IllegalLineEndInCharLit);
scanLitChar(pos);
if (reader.ch == '\'') {
reader.scanChar();
tk = TokenKind.CHARLITERAL;
} else {
lexError(pos, "unclosed.char.lit");
lexError(pos, Errors.UnclosedCharLit);
}
}
break loop;
@ -635,7 +634,7 @@ public class JavaTokenizer {
tk = TokenKind.STRINGLITERAL;
reader.scanChar();
} else {
lexError(pos, "unclosed.str.lit");
lexError(pos, Errors.UnclosedStrLit);
}
break loop;
default:
@ -676,7 +675,7 @@ public class JavaTokenizer {
String.format("%s", reader.ch) :
String.format("\\u%04x", (int)reader.ch);
}
lexError(pos, "illegal.char", arg);
lexError(pos, Errors.IllegalChar(arg));
reader.scanChar();
}
}

View File

@ -26,12 +26,15 @@
package com.sun.tools.javac.parser;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
import com.sun.source.tree.ModuleTree.ModuleKind;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.parser.Tokens.*;
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
import com.sun.tools.javac.resources.CompilerProperties;
@ -41,6 +44,7 @@ import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
@ -163,23 +167,7 @@ public class JavacParser implements Parser {
this.log = fac.log;
this.names = fac.names;
this.source = fac.source;
this.allowTWR = source.allowTryWithResources();
this.allowEffectivelyFinalVariablesInTWR =
source.allowEffectivelyFinalVariablesInTryWithResources();
this.allowDiamond = source.allowDiamond();
this.allowMulticatch = source.allowMulticatch();
this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
this.allowLambda = source.allowLambda();
this.allowMethodReferences = source.allowMethodReferences();
this.allowDefaultMethods = source.allowDefaultMethods();
this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
this.allowTypeAnnotations = source.allowTypeAnnotations();
this.allowModules = source.allowModules();
this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
this.allowUnderscoreIdentifier = source.allowUnderscoreIdentifier();
this.allowPrivateInterfaceMethods = source.allowPrivateInterfaceMethods();
this.allowLocalVariableTypeInference = source.allowLocalVariableTypeInference();
this.keepDocComments = keepDocComments;
this.parseModuleInfo = parseModuleInfo;
docComments = newDocCommentTable(keepDocComments, fac);
@ -198,54 +186,10 @@ public class JavacParser implements Parser {
return keepDocComments ? new LazyDocCommentTable(fac) : null;
}
/** Switch: Should diamond operator be recognized?
*/
boolean allowDiamond;
/** Switch: Should multicatch clause be accepted?
*/
boolean allowMulticatch;
/** Switch: should we recognize try-with-resources?
*/
boolean allowTWR;
/** Switch: should we allow (effectively) final variables as resources in try-with-resources?
*/
boolean allowEffectivelyFinalVariablesInTWR;
/** Switch: should we fold strings?
*/
boolean allowStringFolding;
/** Switch: should we recognize lambda expressions?
*/
boolean allowLambda;
/** Switch: should we allow method/constructor references?
*/
boolean allowMethodReferences;
/** Switch: should we recognize modules?
*/
boolean allowModules;
/** Switch: should we allow default methods in interfaces?
*/
boolean allowDefaultMethods;
/** Switch: should we allow static methods in interfaces?
*/
boolean allowStaticInterfaceMethods;
/** Switch: should we allow private (instance) methods in interfaces?
*/
boolean allowPrivateInterfaceMethods;
/** Switch: should we allow intersection types in cast?
*/
boolean allowIntersectionTypesInCast;
/** Switch: should we keep docComments?
*/
boolean keepDocComments;
@ -254,27 +198,11 @@ public class JavacParser implements Parser {
*/
boolean keepLineMap;
/** Switch: should we recognize type annotations?
*/
boolean allowTypeAnnotations;
/** Switch: should we allow annotations after the method type parameters?
*/
boolean allowAnnotationsAfterTypeParams;
/** Switch: should we allow '_' as an identifier?
*/
boolean allowUnderscoreIdentifier;
/** Switch: is "this" allowed as an identifier?
* This is needed to parse receiver types.
*/
boolean allowThisIdent;
/** Switch: is local variable inference allowed?
*/
boolean allowLocalVariableTypeInference;
/** The type of the method receiver, as specified by a first "this" parameter.
*/
JCVariableDecl receiverParam;
@ -628,7 +556,7 @@ public class JavacParser implements Parser {
} else if (token.kind == THIS) {
if (allowThisIdent) {
// Make sure we're using a supported source version.
checkTypeAnnotations();
checkSourceLevel(Feature.TYPE_ANNOTATIONS);
Name name = token.name();
nextToken();
return name;
@ -638,7 +566,7 @@ public class JavacParser implements Parser {
return names.error;
}
} else if (token.kind == UNDERSCORE) {
if (allowUnderscoreIdentifier) {
if (Feature.UNDERSCORE_IDENTIFIER.allowedInSource(source)) {
warning(token.pos, "underscore.as.identifier");
} else {
error(token.pos, "underscore.as.identifier");
@ -1170,7 +1098,7 @@ public class JavacParser implements Parser {
int pos1 = pos;
List<JCExpression> targets = List.of(t = parseType());
while (token.kind == AMP) {
checkIntersectionTypesInCast();
checkSourceLevel(Feature.INTERSECTION_TYPES_IN_CAST);
accept(AMP);
targets = targets.prepend(parseType());
}
@ -1771,7 +1699,7 @@ public class JavacParser implements Parser {
}
JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) {
checkLambda();
checkSourceLevel(Feature.LAMBDA);
accept(ARROW);
return token.kind == LBRACE ?
@ -1890,7 +1818,7 @@ public class JavacParser implements Parser {
if (token.kind == LT) {
nextToken();
if (token.kind == GT && diamondAllowed) {
checkDiamond();
checkSourceLevel(Feature.DIAMOND);
mode |= DIAMOND;
nextToken();
return List.nil();
@ -2065,7 +1993,7 @@ public class JavacParser implements Parser {
}
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
checkMethodReferences();
checkSourceLevel(Feature.METHOD_REFERENCES);
mode = EXPR;
List<JCExpression> typeArgs = null;
if (token.kind == LT) {
@ -2568,7 +2496,7 @@ public class JavacParser implements Parser {
nextToken();
List<JCTree> resources = List.nil();
if (token.kind == LPAREN) {
checkTryWithResources();
checkSourceLevel(Feature.TRY_WITH_RESOURCES);
nextToken();
resources = resources();
accept(RPAREN);
@ -2584,7 +2512,7 @@ public class JavacParser implements Parser {
}
} else {
if (resources.isEmpty()) {
if (allowTWR) {
if (Feature.TRY_WITH_RESOURCES.allowedInSource(source)) {
error(pos, "try.without.catch.finally.or.resource.decls");
} else {
error(pos, "try.without.catch.or.finally");
@ -2701,7 +2629,7 @@ public class JavacParser implements Parser {
ListBuffer<JCExpression> catchTypes = new ListBuffer<>();
catchTypes.add(parseType());
while (token.kind == BAR) {
checkMulticatch();
checkSourceLevel(Feature.MULTICATCH);
nextToken();
// Instead of qualident this is now parseType.
// But would that allow too much, e.g. arrays or generics?
@ -2870,7 +2798,7 @@ public class JavacParser implements Parser {
case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break;
case STRICTFP : flag = Flags.STRICTFP; break;
case MONKEYS_AT : flag = Flags.ANNOTATION; break;
case DEFAULT : checkDefaultMethods(); flag = Flags.DEFAULT; break;
case DEFAULT : checkSourceLevel(Feature.DEFAULT_METHODS); flag = Flags.DEFAULT; break;
case ERROR : flag = 0; nextToken(); break;
default: break loop;
}
@ -2914,7 +2842,7 @@ public class JavacParser implements Parser {
JCAnnotation annotation(int pos, Tag kind) {
// accept(AT); // AT consumed by caller
if (kind == Tag.TYPE_ANNOTATION) {
checkTypeAnnotations();
checkSourceLevel(Feature.TYPE_ANNOTATIONS);
}
JCTree ident = qualident(false);
List<JCExpression> fieldValues = annotationFieldValuesOpt();
@ -3028,7 +2956,7 @@ public class JavacParser implements Parser {
boolean localDecl)
{
JCVariableDecl head = variableDeclaratorRest(pos, mods, type, name, reqInit, dc, localDecl);
boolean implicit = allowLocalVariableTypeInference && head.vartype == null;
boolean implicit = Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && head.vartype == null;
vdefs.append(head);
while (token.kind == COMMA) {
if (implicit) {
@ -3066,7 +2994,7 @@ public class JavacParser implements Parser {
else if (reqInit) syntaxError(token.pos, "expected", EQ);
JCTree elemType = TreeInfo.innermostType(type, true);
int startPos = Position.NOPOS;
if (allowLocalVariableTypeInference && elemType.hasTag(IDENT)) {
if (Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && elemType.hasTag(IDENT)) {
Name typeName = ((JCIdent)elemType).name;
if (isRestrictedLocalVarTypeName(typeName)) {
if (type.hasTag(TYPEARRAY)) {
@ -3100,7 +3028,7 @@ public class JavacParser implements Parser {
}
boolean isRestrictedLocalVarTypeName(Name name) {
return allowLocalVariableTypeInference && name == names.var;
return Feature.LOCAL_VARIABLE_TYPE_INFERENCE.allowedInSource(source) && name == names.var;
}
/** VariableDeclaratorId = Ident BracketsOpt
@ -3176,7 +3104,7 @@ public class JavacParser implements Parser {
JCModifiers mods = toP(F.at(startPos).Modifiers(Flags.FINAL));
return variableDeclaratorRest(token.pos, mods, t, ident(), true, null, true);
} else {
checkVariableInTryWithResources(startPos);
checkSourceLevel(Feature.EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES);
if (!t.hasTag(IDENT) && !t.hasTag(SELECT)) {
log.error(t.pos(), Errors.TryWithResourcesExprNeedsVar);
}
@ -3278,10 +3206,7 @@ public class JavacParser implements Parser {
JCModuleDecl moduleDecl(JCModifiers mods, ModuleKind kind, Comment dc) {
int pos = token.pos;
if (!allowModules) {
log.error(pos, Errors.ModulesNotSupportedInSource(source.name));
allowModules = true;
}
checkSourceLevel(Feature.MODULES);
nextToken();
JCExpression name = qualident(false);
@ -3700,7 +3625,7 @@ public class JavacParser implements Parser {
List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
if (annosAfterParams.nonEmpty()) {
checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
mods.annotations = mods.annotations.appendList(annosAfterParams);
if (mods.pos == Position.NOPOS)
mods.pos = mods.annotations.head.pos;
@ -3768,10 +3693,10 @@ public class JavacParser implements Parser {
Comment dc) {
if (isInterface) {
if ((mods.flags & Flags.STATIC) != 0) {
checkStaticInterfaceMethods();
checkSourceLevel(Feature.STATIC_INTERFACE_METHODS);
}
if ((mods.flags & Flags.PRIVATE) != 0) {
checkPrivateInterfaceMethods();
checkSourceLevel(Feature.PRIVATE_INTERFACE_METHODS);
}
}
JCVariableDecl prevReceiverParam = this.receiverParam;
@ -4226,64 +4151,13 @@ public class JavacParser implements Parser {
}
}
void checkDiamond() {
if (!allowDiamond) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.DiamondNotSupportedInSource(source.name));
}
void checkSourceLevel(Feature feature) {
checkSourceLevel(token.pos, feature);
}
void checkMulticatch() {
if (!allowMulticatch) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.MulticatchNotSupportedInSource(source.name));
}
}
void checkTryWithResources() {
if (!allowTWR) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.TryWithResourcesNotSupportedInSource(source.name));
}
}
void checkVariableInTryWithResources(int startPos) {
if (!allowEffectivelyFinalVariablesInTWR) {
log.error(DiagnosticFlag.SOURCE_LEVEL, startPos, Errors.VarInTryWithResourcesNotSupportedInSource(source.name));
}
}
void checkLambda() {
if (!allowLambda) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.LambdaNotSupportedInSource(source.name));
}
}
void checkMethodReferences() {
if (!allowMethodReferences) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.MethodReferencesNotSupportedInSource(source.name));
}
}
void checkDefaultMethods() {
if (!allowDefaultMethods) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.DefaultMethodsNotSupportedInSource(source.name));
}
}
void checkIntersectionTypesInCast() {
if (!allowIntersectionTypesInCast) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.IntersectionTypesInCastNotSupportedInSource(source.name));
}
}
void checkStaticInterfaceMethods() {
if (!allowStaticInterfaceMethods) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.StaticIntfMethodsNotSupportedInSource(source.name));
}
}
void checkTypeAnnotations() {
if (!allowTypeAnnotations) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, Errors.TypeAnnotationsNotSupportedInSource(source.name));
}
}
void checkPrivateInterfaceMethods() {
if (!allowPrivateInterfaceMethods) {
log.error(DiagnosticFlag.SOURCE_LEVEL, token.pos, CompilerProperties.Errors.PrivateIntfMethodsNotSupportedInSource(source.name));
}
}
protected void checkAnnotationsAfterTypeParams(int pos) {
if (!allowAnnotationsAfterTypeParams) {
log.error(DiagnosticFlag.SOURCE_LEVEL, pos, Errors.AnnotationsAfterTypeParamsNotSupportedInSource(source.name));
protected void checkSourceLevel(int pos, Feature feature) {
if (!feature.allowedInSource(source)) {
log.error(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name));
}
}

View File

@ -53,6 +53,7 @@ import com.sun.source.util.TaskEvent;
import com.sun.tools.javac.api.MultiTaskListener;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Types;
@ -116,7 +117,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
private final boolean fatalErrors;
private final boolean werror;
private final boolean showResolveErrors;
private final boolean allowModules;
private final JavacFiler filer;
private final JavacMessager messager;
@ -233,8 +233,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
initialCompleter = ClassFinder.instance(context).getCompleter();
chk = Check.instance(context);
initProcessorLoader();
allowModules = source.allowModules();
}
public void setProcessors(Iterable<? extends Processor> processors) {
@ -770,7 +768,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (psi.processorIterator.hasNext()) {
ProcessorState ps = new ProcessorState(psi.processorIterator.next(),
log, source, allowModules,
log, source, Feature.MODULES.allowedInSource(source),
JavacProcessingEnvironment.this);
psi.procStateList.add(ps);
return ps;
@ -837,7 +835,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
for(TypeElement a : annotationsPresent) {
ModuleElement mod = elementUtils.getModuleOf(a);
String moduleSpec = allowModules && mod != null ? mod.getQualifiedName() + "/" : "";
String moduleSpec = Feature.MODULES.allowedInSource(source) && mod != null ? mod.getQualifiedName() + "/" : "";
unmatchedAnnotations.put(moduleSpec + a.getQualifiedName().toString(),
a);
}

View File

@ -2601,38 +2601,87 @@ compiler.misc.inapplicable.method=\
({3})
########################################
# Diagnostics for language feature changes
# Diagnostics for language feature changes.
# Such diagnostics have a common template which can be customized by using a feature
# diagnostic fragment (one of those given below).
########################################
# 0: string
compiler.err.modules.not.supported.in.source=\
modules are not supported in -source {0}\n\
(use -source 9 or higher to enable modules)
# 0: message segment (feature), 1: string (found version), 2: string (expected version)
compiler.err.feature.not.supported.in.source=\
{0} is not supported in -source {1}\n\
(use -source {2} or higher to enable {0})
# 0: string
compiler.misc.diamond.and.anon.class.not.supported.in.source=\
cannot use ''<>'' with anonymous inner classes in -source {0}\n\
(use -source 9 or higher to enable ''<>'' with anonymous inner classes)
# 0: message segment (feature), 1: string (found version), 2: string (expected version)
compiler.err.feature.not.supported.in.source.plural=\
{0} are not supported in -source {1}\n\
(use -source {2} or higher to enable {0})
# 0: string
compiler.err.unsupported.binary.lit=\
binary literals are not supported in -source {0}\n\
(use -source 7 or higher to enable binary literals)
# 0: message segment (feature), 1: string (found version), 2: string (expected version)
compiler.misc.feature.not.supported.in.source=\
{0} is not supported in -source {1}\n\
(use -source {2} or higher to enable {0})
# 0: string
compiler.err.unsupported.underscore.lit=\
underscores in literals are not supported in -source {0}\n\
(use -source 7 or higher to enable underscores in literals)
# 0: message segment (feature), 1: string (found version), 2: string (expected version)
compiler.misc.feature.not.supported.in.source.plural=\
{0} are not supported in -source {1}\n\
(use -source {2} or higher to enable {0})
# 0: string
compiler.err.try.with.resources.not.supported.in.source=\
try-with-resources is not supported in -source {0}\n\
(use -source 7 or higher to enable try-with-resources)
compiler.misc.feature.modules=\
modules
# 0: string
compiler.err.var.in.try.with.resources.not.supported.in.source=\
variables in try-with-resources not supported in -source {0}\n\
(use -source 9 or higher to enable variables in try-with-resources)
compiler.misc.feature.diamond.and.anon.class=\
''<>'' with anonymous inner classes
compiler.misc.feature.binary.lit=\
binary literals
compiler.misc.feature.underscore.lit=\
underscores in literals
compiler.misc.feature.try.with.resources=\
try-with-resources
compiler.misc.feature.var.in.try.with.resources=\
variables in try-with-resources
compiler.misc.feature.type.annotations=\
type annotations
compiler.misc.feature.annotations.after.type.params=\
annotations after method type parameters
compiler.misc.feature.repeatable.annotations=\
repeated annotations
compiler.misc.feature.diamond=\
diamond operator
compiler.misc.feature.multicatch=\
multi-catch statements
compiler.misc.feature.string.switch=\
strings in switch
compiler.misc.feature.lambda=\
lambda expressions
compiler.misc.feature.method.references=\
method references
compiler.misc.feature.default.methods=\
default methods
compiler.misc.feature.intersection.types.in.cast=\
intersection types
compiler.misc.feature.static.intf.methods=\
static interface methods
compiler.misc.feature.static.intf.method.invoke=\
static interface method invocations
compiler.misc.feature.private.intf.methods=\
private interface methods
compiler.warn.underscore.as.identifier=\
as of release 9, ''_'' is a keyword, and may not be used as an identifier
@ -2694,71 +2743,6 @@ compiler.err.incorrect.constructor.receiver.name=\
compiler.err.no.annotations.on.dot.class=\
no annotations are allowed in the type of a class literal
# 0: string
compiler.err.type.annotations.not.supported.in.source=\
type annotations are not supported in -source {0}\n\
(use -source 8 or higher to enable type annotations)
# 0: string
compiler.err.annotations.after.type.params.not.supported.in.source=\
annotations after method type parameters are not supported in -source {0}\n\
(use -source 8 or higher to enable annotations after method type parameters)
# 0: string
compiler.err.repeatable.annotations.not.supported.in.source=\
repeated annotations are not supported in -source {0}\n\
(use -source 8 or higher to enable repeated annotations)
# 0: string
compiler.err.diamond.not.supported.in.source=\
diamond operator is not supported in -source {0}\n\
(use -source 7 or higher to enable diamond operator)
# 0: string
compiler.err.multicatch.not.supported.in.source=\
multi-catch statement is not supported in -source {0}\n\
(use -source 7 or higher to enable multi-catch statement)
# 0: string
compiler.err.string.switch.not.supported.in.source=\
strings in switch are not supported in -source {0}\n\
(use -source 7 or higher to enable strings in switch)
# 0: string
compiler.err.lambda.not.supported.in.source=\
lambda expressions are not supported in -source {0}\n\
(use -source 8 or higher to enable lambda expressions)
# 0: string
compiler.err.method.references.not.supported.in.source=\
method references are not supported in -source {0}\n\
(use -source 8 or higher to enable method references)
# 0: string
compiler.err.default.methods.not.supported.in.source=\
default methods are not supported in -source {0}\n\
(use -source 8 or higher to enable default methods)
# 0: string
compiler.err.intersection.types.in.cast.not.supported.in.source=\
intersection types in cast are not supported in -source {0}\n\
(use -source 8 or higher to enable intersection types in cast)
# 0: string
compiler.err.static.intf.methods.not.supported.in.source=\
static interface methods are not supported in -source {0}\n\
(use -source 8 or higher to enable static interface methods)
# 0: string
compiler.err.static.intf.method.invoke.not.supported.in.source=\
static interface method invocations are not supported in -source {0}\n\
(use -source 8 or higher to enable static interface method invocations)
# 0: string
compiler.err.private.intf.methods.not.supported.in.source=\
private interface methods are not supported in -source {0}\n\
(use -source 9 or higher to enable private interface methods)
########################################
# Diagnostics for verbose resolution
# used by Resolve (debug only)

View File

@ -426,7 +426,7 @@ public class Log extends AbstractLog {
/** A set of "not-supported-in-source-X" errors produced so far. This is used to only generate
* one such error per file.
*/
protected Set<Pair<JavaFileObject, String>> recordedSourceLevelErrors = new HashSet<>();
protected Set<Pair<JavaFileObject, List<String>>> recordedSourceLevelErrors = new HashSet<>();
public boolean hasDiagnosticListener() {
return diagListener != null;
@ -521,13 +521,29 @@ public class Log extends AbstractLog {
if (!d.isFlagSet(DiagnosticFlag.SOURCE_LEVEL))
return true;
Pair<JavaFileObject, String> coords = new Pair<>(file, d.getCode());
Pair<JavaFileObject, List<String>> coords = new Pair<>(file, getCode(d));
boolean shouldReport = !recordedSourceLevelErrors.contains(coords);
if (shouldReport)
recordedSourceLevelErrors.add(coords);
return shouldReport;
}
//where
private List<String> getCode(JCDiagnostic d) {
ListBuffer<String> buf = new ListBuffer<>();
getCodeRecursive(buf, d);
return buf.toList();
}
private void getCodeRecursive(ListBuffer<String> buf, JCDiagnostic d) {
buf.add(d.getCode());
for (Object o : d.getArgs()) {
if (o instanceof JCDiagnostic) {
getCodeRecursive(buf, (JCDiagnostic)o);
}
}
}
/** Prompt user after an error.
*/
public void prompt() {

View File

@ -34,6 +34,7 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import com.sun.javadoc.*;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
@ -388,7 +389,7 @@ public class RootDocImpl extends DocImpl implements RootDoc {
}
public boolean isFunctionalInterface(AnnotationDesc annotationDesc) {
return env.source.allowLambda()
return Feature.LAMBDA.allowedInSource(env.source)
&& annotationDesc.annotationType().qualifiedName().equals(
env.syms.functionalInterfaceType.toString());
}

View File

@ -55,6 +55,7 @@ import com.sun.tools.javac.api.BasicJavacTask;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
@ -187,7 +188,7 @@ public class WorkArounds {
// TODO: we need ElementUtils.getPackage to cope with input strings
// to return the proper unnamedPackage for all supported releases.
PackageElement getUnnamedPackage() {
return (toolEnv.source.allowModules())
return (Feature.MODULES.allowedInSource(toolEnv.source))
? toolEnv.syms.unnamedModule.unnamedPackage
: toolEnv.syms.noModule.unnamedPackage;
}

View File

@ -55,6 +55,7 @@ import javax.tools.StandardLocation;
import com.sun.tools.javac.code.Kinds.Kind;
import com.sun.tools.javac.code.Source;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.CompletionFailure;
@ -222,7 +223,7 @@ public class ElementsTable {
else
locs.add(StandardLocation.CLASS_PATH);
}
if (source.allowModules() && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
if (Feature.MODULES.allowedInSource(source) && toolEnv.fileManager.hasLocation(StandardLocation.PATCH_MODULE_PATH))
locs.add(StandardLocation.PATCH_MODULE_PATH);
this.locations = Collections.unmodifiableList(locs);

View File

@ -34,6 +34,7 @@ import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.JCDiagnostic.Error;
import com.sun.tools.javac.util.Log;
import java.io.PrintWriter;
import java.io.StringWriter;
@ -78,7 +79,7 @@ class CompletenessAnalyzer {
Context context = new Context();
Log log = CaLog.createLog(context);
context.put(Log.class, log);
context.put(Source.class, Source.JDK1_9);
context.put(Source.class, Source.JDK9);
scannerFactory = ScannerFactory.instance(context);
}
@ -137,6 +138,11 @@ class CompletenessAnalyzer {
die();
}
@Override
public void error(int pos, Error errorKey) {
die();
}
@Override
public void error(int pos, String key, Object... args) {
die();

View File

@ -25,6 +25,7 @@
package jdk.jshell;
import com.sun.tools.javac.code.Source.Feature;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.parser.JavacParser;
import com.sun.tools.javac.parser.ParserFactory;
@ -191,7 +192,7 @@ class ReplParser extends JavacParser {
List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
if (annosAfterParams.nonEmpty()) {
checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
mods.annotations = mods.annotations.appendList(annosAfterParams);
if (mods.pos == Position.NOPOS) {
mods.pos = mods.annotations.head.pos;

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
/*
* @test
* @bug 8186961
* @run main/othervm StaticFieldsOnInterface C
* @run main/othervm StaticFieldsOnInterface D
* @run main/othervm StaticFieldsOnInterface Y
*/
public class StaticFieldsOnInterface {
/*
A
/ \
B C
\ /
D
Interface A has a public field
Ensure B, C, D only report exactly one public field
A
/
X A
|/
Y
Ensure class Y, extending class X, reports exactly one public field
*/
public interface A {
public static final int CONSTANT = 42;
}
public interface B extends A {
}
public interface C extends A {
}
public interface D extends B, C {
}
static class X implements A {}
static class Y extends X implements A {}
public static void main(String[] args) throws Exception {
char first = 'C';
if (args.length > 0) {
first = args[0].charAt(0);
}
assertOneField(A.class);
// D first
if (first == 'D') {
assertOneField(D.class);
assertOneField(C.class);
}
// C first
else if (first == 'C') {
assertOneField(C.class);
assertOneField(D.class);
}
else {
assertOneField(Y.class);
}
}
static void assertOneField(Class<?> c) {
int nfs = c.getFields().length;
if (nfs != 1) {
throw new AssertionError(String.format(
"Class %s does not have exactly one field: %d", c.getName(), nfs));
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -57,6 +57,8 @@ public class UnsupportedOptionsTest {
Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions");
Field field = c.getField("SO_FLOW_SLA");
socketOptions.add((SocketOption<?>)field.get(null));
field = c.getField("TCP_QUICKACK");
socketOptions.add((SocketOption<?>)field.get(null));
} catch (ClassNotFoundException e) {
// ignore, jdk.net module not present
} catch (ReflectiveOperationException e) {

View File

@ -39,6 +39,7 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer;
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject;
@ -1283,4 +1284,57 @@ public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
sync.release();
}
/**
* Tests scenario for
* JDK-8191937: Lost interrupt in AbstractQueuedSynchronizer when tryAcquire methods throw
*/
public void testInterruptedFailingAcquire() throws InterruptedException {
final RuntimeException ex = new RuntimeException();
// A synchronizer only offering a choice of failure modes
class Sync extends AbstractQueuedLongSynchronizer {
boolean pleaseThrow;
@Override protected boolean tryAcquire(long ignored) {
if (pleaseThrow) throw ex;
return false;
}
@Override protected long tryAcquireShared(long ignored) {
if (pleaseThrow) throw ex;
return -1;
}
@Override protected boolean tryRelease(long ignored) {
return true;
}
@Override protected boolean tryReleaseShared(long ignored) {
return true;
}
}
final Sync s = new Sync();
final Thread thread = newStartedThread(new CheckedRunnable() {
public void realRun() {
try {
if (ThreadLocalRandom.current().nextBoolean())
s.acquire(1);
else
s.acquireShared(1);
shouldThrow();
} catch (Throwable t) {
assertSame(ex, t);
assertTrue(Thread.interrupted());
}
}});
waitForThreadToEnterWaitState(thread);
assertSame(thread, s.getFirstQueuedThread());
assertTrue(s.hasQueuedPredecessors());
assertTrue(s.hasQueuedThreads());
assertEquals(1, s.getQueueLength());
s.pleaseThrow = true;
thread.interrupt();
s.release(1);
awaitTermination(thread);
}
}

View File

@ -36,9 +36,11 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject;
@ -1286,4 +1288,105 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
sync.release();
}
/**
* Disabled demo test for (unfixed as of 2017-11)
* JDK-8191483: AbstractQueuedSynchronizer cancel/cancel race
* ant -Djsr166.tckTestClass=AbstractQueuedSynchronizerTest -Djsr166.methodFilter=testCancelCancelRace -Djsr166.runsPerTest=100 tck
*/
public void DISABLED_testCancelCancelRace() throws InterruptedException {
class Sync extends AbstractQueuedSynchronizer {
protected boolean tryAcquire(int acquires) {
return !hasQueuedPredecessors() && compareAndSetState(0, 1);
}
protected boolean tryRelease(int releases) {
return compareAndSetState(1, 0);
}
}
Sync s = new Sync();
s.acquire(1); // acquire to force other threads to enqueue
// try to trigger double cancel race with two background threads
ArrayList<Thread> threads = new ArrayList<>();
Runnable failedAcquire = () -> {
try {
s.acquireInterruptibly(1);
shouldThrow();
} catch (InterruptedException expected) {}
};
for (int i = 0; i < 2; i++) {
Thread thread = new Thread(failedAcquire);
thread.start();
threads.add(thread);
}
Thread.sleep(100);
for (Thread thread : threads) thread.interrupt();
for (Thread thread : threads) awaitTermination(thread);
s.release(1);
// no one holds lock now, we should be able to acquire
if (!s.tryAcquire(1))
throw new RuntimeException(
String.format(
"Broken: hasQueuedPredecessors=%s hasQueuedThreads=%s queueLength=%d firstQueuedThread=%s",
s.hasQueuedPredecessors(),
s.hasQueuedThreads(),
s.getQueueLength(),
s.getFirstQueuedThread()));
}
/**
* Tests scenario for
* JDK-8191937: Lost interrupt in AbstractQueuedSynchronizer when tryAcquire methods throw
*/
public void testInterruptedFailingAcquire() throws InterruptedException {
final RuntimeException ex = new RuntimeException();
// A synchronizer only offering a choice of failure modes
class Sync extends AbstractQueuedSynchronizer {
boolean pleaseThrow;
@Override protected boolean tryAcquire(int ignored) {
if (pleaseThrow) throw ex;
return false;
}
@Override protected int tryAcquireShared(int ignored) {
if (pleaseThrow) throw ex;
return -1;
}
@Override protected boolean tryRelease(int ignored) {
return true;
}
@Override protected boolean tryReleaseShared(int ignored) {
return true;
}
}
final Sync s = new Sync();
final Thread thread = newStartedThread(new CheckedRunnable() {
public void realRun() {
try {
if (ThreadLocalRandom.current().nextBoolean())
s.acquire(1);
else
s.acquireShared(1);
shouldThrow();
} catch (Throwable t) {
assertSame(ex, t);
assertTrue(Thread.interrupted());
}
}});
waitForThreadToEnterWaitState(thread);
assertSame(thread, s.getFirstQueuedThread());
assertTrue(s.hasQueuedPredecessors());
assertTrue(s.hasQueuedThreads());
assertEquals(1, s.getQueueLength());
s.pleaseThrow = true;
thread.interrupt();
s.release(1);
awaitTermination(thread);
}
}

View File

@ -614,7 +614,7 @@ public class StampedLockTest extends JSR166TestCase {
long s = lock.readLock();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
threadAssertEquals(0L, lock.tryWriteLock());
assertEquals(0L, lock.tryWriteLock());
}});
awaitTermination(t);

View File

@ -33,6 +33,7 @@
*/
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Flow;
@ -429,7 +430,8 @@ public class SubmissionPublisherTest extends JSR166TestCase {
* Cancelling a subscription eventually causes no more onNexts to be issued
*/
public void testCancel() {
SubmissionPublisher<Integer> p = basicPublisher();
SubmissionPublisher<Integer> p =
new SubmissionPublisher<Integer>(basicExecutor, 4); // must be < 20
TestSubscriber s1 = new TestSubscriber();
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s1);
@ -666,7 +668,6 @@ public class SubmissionPublisherTest extends JSR166TestCase {
p.subscribe(s1);
p.subscribe(s2);
for (int i = 1; i <= 20; ++i) {
assertTrue(p.estimateMinimumDemand() <= 1);
assertTrue(p.submit(i) >= 0);
}
p.close();
@ -1005,4 +1006,31 @@ public class SubmissionPublisherTest extends JSR166TestCase {
assertTrue(count.get() < n);
}
/**
* Tests scenario for
* JDK-8187947: A race condition in SubmissionPublisher
* cvs update -D '2017-11-25' src/main/java/util/concurrent/SubmissionPublisher.java && ant -Djsr166.expensiveTests=true -Djsr166.tckTestClass=SubmissionPublisherTest -Djsr166.methodFilter=testMissedSignal tck; cvs update -A src/main/java/util/concurrent/SubmissionPublisher.java
*/
public void testMissedSignal_8187947() throws Exception {
final int N = expensiveTests ? (1 << 20) : (1 << 10);
final CountDownLatch finished = new CountDownLatch(1);
final SubmissionPublisher<Boolean> pub = new SubmissionPublisher<>();
class Sub implements Subscriber<Boolean> {
int received;
public void onSubscribe(Subscription s) {
s.request(N);
}
public void onNext(Boolean item) {
if (++received == N)
finished.countDown();
else
CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
}
public void onError(Throwable t) { throw new AssertionError(t); }
public void onComplete() {}
}
pub.subscribe(new Sub());
CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
await(finished);
}
}

View File

@ -23,8 +23,9 @@
/**
* @test
* @bug 4206909 4813885
* @summary Test basic functionality of DeflaterOutputStream/InflaterInputStream and GZIPOutputStream/GZIPInputStream, including flush
* @bug 4206909 4813885 8191918
* @summary Test basic functionality of DeflaterOutputStream/InflaterInputStream
* and GZIPOutputStream/GZIPInputStream, including flush
* @key randomness
*/
@ -147,6 +148,36 @@ public class InflateIn_DeflateOut {
check(Arrays.equals(data, buf));
}
private static void TestFlushableGZIPOutputStream() throws Throwable {
var random = new Random(new Date().getTime());
var byteOutStream = new ByteArrayOutputStream();
var output = new FlushableGZIPOutputStream(byteOutStream);
var data = new byte[random.nextInt(1024 * 1024)];
var buf = new byte[data.length];
random.nextBytes(data);
output.write(data);
for (int i=0; i<data.length; i++) {
output.write(data[i]);
}
output.flush();
for (int i=0; i<data.length; i++) {
output.write(data[i]);
}
output.write(data);
output.close();
var baos = new ByteArrayOutputStream();
try (var gzis = new GZIPInputStream(new
ByteArrayInputStream(byteOutStream.toByteArray()))) {
gzis.transferTo(baos);
}
var decompressedBytes = baos.toByteArray();
check(decompressedBytes.length == data.length * 4);
}
private static void check(InputStream is, OutputStream os)
throws Throwable
{
@ -268,6 +299,7 @@ public class InflateIn_DeflateOut {
LineOrientedProtocol();
GZWriteFlushRead();
GZLineOrientedProtocol();
TestFlushableGZIPOutputStream();
}
//--------------------- Infrastructure ---------------------------
@ -285,3 +317,80 @@ public class InflateIn_DeflateOut {
System.out.println("\nPassed = " + passed + " failed = " + failed);
if (failed > 0) throw new AssertionError("Some tests failed");}
}
class FlushableGZIPOutputStream extends GZIPOutputStream {
public FlushableGZIPOutputStream(OutputStream os) throws IOException {
super(os);
}
private static final byte[] EMPTYBYTEARRAY = new byte[0];
private boolean hasData = false;
/**
* Here we make sure we have received data, so that the header has been for
* sure written to the output stream already.
*/
@Override
public synchronized void write(byte[] bytes, int i, int i1)
throws IOException {
super.write(bytes, i, i1);
hasData = true;
}
@Override
public synchronized void write(int i) throws IOException {
super.write(i);
hasData = true;
}
@Override
public synchronized void write(byte[] bytes) throws IOException {
super.write(bytes);
hasData = true;
}
@Override
public synchronized void flush() throws IOException {
if (!hasData) {
return; // do not allow the gzip header to be flushed on its own
}
// trick the deflater to flush
/**
* Now this is tricky: We force the Deflater to flush its data by
* switching compression level. As yet, a perplexingly simple workaround
* for
* http://developer.java.sun.com/developer/bugParade/bugs/4255743.html
*/
if (!def.finished()) {
def.setInput(EMPTYBYTEARRAY, 0, 0);
def.setLevel(Deflater.NO_COMPRESSION);
deflate();
def.setLevel(Deflater.DEFAULT_COMPRESSION);
deflate();
out.flush();
}
hasData = false; // no more data to flush
}
/*
* Keep on calling deflate until it runs dry. The default implementation
* only does it once and can therefore hold onto data when they need to be
* flushed out.
*/
@Override
protected void deflate() throws IOException {
int len;
do {
len = def.deflate(buf, 0, buf.length);
if (len > 0) {
out.write(buf, 0, len);
}
} while (len != 0);
}
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
/*
* @test
* @bug 8190843
* @summary can not set/get extendedOptions to ServerSocket
* @modules jdk.net
* @run main ExtOptionTest
*/
import java.io.IOException;
import java.net.ServerSocket;
import static jdk.net.ExtendedSocketOptions.TCP_QUICKACK;
import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
public class ExtOptionTest {
private static final String OS = "Linux";
public static void main(String args[]) throws IOException {
var operSys = System.getProperty("os.name");
try (ServerSocket ss = new ServerSocket(0)) {
// currently TCP_QUICKACK is available only on Linux.
if (operSys.equals(OS)) {
ss.setOption(TCP_QUICKACK, true);
if (!ss.getOption(TCP_QUICKACK)) {
throw new RuntimeException("Test failed, TCP_QUICKACK should"
+ " have been set");
}
} else if (operSys.equals("SunOS")) {
if (ss.supportedOptions().contains(SO_FLOW_SLA)) {
throw new RuntimeException("Test failed, SO_FLOW_SLA is not "
+ "applicable for ServerSocket");
}
} else {
if (ss.supportedOptions().contains(TCP_QUICKACK)) {
ss.setOption(TCP_QUICKACK, true);
if (!ss.getOption(TCP_QUICKACK)) {
throw new RuntimeException("Test failed, TCP_QUICKACK should"
+ " have been set");
}
}
}
}
}
}

View File

@ -51,6 +51,6 @@ public class CompilerOptionsTest extends KullaTesting {
public void testSourceVersion() {
assertEval("import java.util.function.*;", added(VALID));
assertDeclareFail("Function<Integer,Integer> f = x -> x*2;",
new ExpectedDiagnostic("compiler.err.lambda.not.supported.in.source", 32, 32, 32, -1, -1, Diagnostic.Kind.ERROR));
new ExpectedDiagnostic("compiler.err.feature.not.supported.in.source.plural", 32, 32, 32, -1, -1, Diagnostic.Kind.ERROR));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,28 +29,62 @@
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* @build toolbox.ToolBox
* @run compile -encoding iso-8859-1 -XD-printsource T6302184.java
* @build toolbox.ToolBox toolbox.JavacTask
* @run main HiddenOptionsShouldUseGivenEncodingTest
*/
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import toolbox.JavacTask;
import toolbox.ToolBox;
// Original test: test/tools/javac/6302184/T6302184.sh
public class HiddenOptionsShouldUseGivenEncodingTest {
public static void main(String[] args) throws Exception {
ToolBox tb = new ToolBox();
String encoding = "iso-8859-1";
Path path1 = Paths.get(ToolBox.testClasses, "T6302184.java");
Path src = Paths.get("src");
Files.createDirectories(src);
Files.write(src.resolve("T6302184.java"), source, Charset.forName(encoding));
Files.write(src.resolve("T6302184.out"), expect, Charset.forName(encoding));
Path out = Paths.get("out");
Files.createDirectories(out);
ToolBox tb = new ToolBox();
new JavacTask(tb)
.outdir("out")
.options("-encoding", encoding, "-XD-printsource")
.files(src.resolve("T6302184.java"))
.run();
Path path1 = Paths.get("out").resolve("T6302184.java");
List<String> file1 = tb.readAllLines(path1, encoding);
Path path2 = Paths.get(ToolBox.testSrc, "T6302184.out");
Path path2 = src.resolve("T6302184.out");
List<String> file2 = tb.readAllLines(path2, encoding);
tb.checkEqual(file1, file2);
}
static List<String> source = Arrays.asList(
"class T6302184 {",
" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",
"}"
);
static List<String> expect = Arrays.asList(
"",
"class T6302184 {",
" ",
" T6302184() {",
" super();",
" }",
" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",
"}"
);
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2005, 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.
*/
/**
* This is a test that uses ISO 8859 encoding.
*/
class T6302184 {
int ÀÁÂÃÄÅ = 1;
}

View File

@ -1,11 +0,0 @@
/**
* This is a test that uses ISO 8859 encoding.
*/
class T6302184 {
T6302184() {
super();
}
int ÀÁÂÃÄÅ = 1;
}

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
BadlyTypedLabel1.java:10:15: compiler.err.string.switch.not.supported.in.source: 1.6
BadlyTypedLabel1.java:10:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
BadlyTypedLabel1.java:13:14: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
2 errors
3 warnings

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
BadlyTypedLabel2.java:12:15: compiler.err.string.switch.not.supported.in.source: 1.6
BadlyTypedLabel2.java:12:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
BadlyTypedLabel2.java:15:14: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.math.RoundingMode, java.lang.String)
2 errors
3 warnings

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
NonConstantLabel.java:11:15: compiler.err.string.switch.not.supported.in.source: 1.6
NonConstantLabel.java:11:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
NonConstantLabel.java:14:14: compiler.err.string.const.req
2 errors
3 warnings

View File

@ -1,6 +1,6 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
OneCaseSwitches.java:23:15: compiler.err.string.switch.not.supported.in.source: 1.6
OneCaseSwitches.java:23:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
1 error
3 warnings
3 warnings

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
RepeatedStringCaseLabels1.java:10:15: compiler.err.string.switch.not.supported.in.source: 1.6
RepeatedStringCaseLabels1.java:10:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
RepeatedStringCaseLabels1.java:13:9: compiler.err.duplicate.case.label
2 errors
3 warnings

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
RepeatedStringCaseLabels2.java:11:15: compiler.err.string.switch.not.supported.in.source: 1.6
RepeatedStringCaseLabels2.java:11:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.string.switch), 6, 7
RepeatedStringCaseLabels2.java:14:9: compiler.err.duplicate.case.label
2 errors
3 warnings

View File

@ -1,6 +1,6 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
BadTwr.java:13:12: compiler.err.try.with.resources.not.supported.in.source: 1.6
BadTwr.java:13:12: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.try.with.resources), 6, 7
1 error
3 warnings

View File

@ -1,7 +1,7 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
BadTwrSyntax.java:14:12: compiler.err.try.with.resources.not.supported.in.source: 1.6
BadTwrSyntax.java:14:12: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.try.with.resources), 6, 7
BadTwrSyntax.java:14:43: compiler.err.illegal.start.of.expr
2 errors
3 warnings

View File

@ -1,2 +1,2 @@
TwrForVariable1.java:13:14: compiler.err.var.in.try.with.resources.not.supported.in.source: 1.8
TwrForVariable1.java:13:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.var.in.try.with.resources), 8, 9
1 error

View File

@ -1,6 +1,6 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
TwrOnNonResource.java:12:12: compiler.err.try.with.resources.not.supported.in.source: 1.6
TwrOnNonResource.java:12:12: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.try.with.resources), 6, 7
1 error
3 warnings

View File

@ -1,6 +1,6 @@
- compiler.warn.source.no.bootclasspath: 1.6
- compiler.warn.option.obsolete.source: 1.6
- compiler.warn.source.no.bootclasspath: 6
- compiler.warn.option.obsolete.source: 6
- compiler.warn.option.obsolete.suppression
WeirdTwr.java:14:12: compiler.err.try.with.resources.not.supported.in.source: 1.6
WeirdTwr.java:14:12: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.try.with.resources), 6, 7
1 error
3 warnings

View File

@ -1,2 +1,2 @@
WrongVersion.java:12:9: compiler.err.repeatable.annotations.not.supported.in.source: 1.6
WrongVersion.java:12:9: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.repeatable.annotations), 6, 8
1 error

View File

@ -1,2 +1,2 @@
WrongVersion.java:12:9: compiler.err.repeatable.annotations.not.supported.in.source: 1.7
WrongVersion.java:12:9: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.repeatable.annotations), 7, 8
1 error

View File

@ -1,2 +1,2 @@
AnnotationVersion.java:12:27: compiler.err.type.annotations.not.supported.in.source: 1.6
AnnotationVersion.java:12:27: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.type.annotations), 6, 8
1 error

View File

@ -1,2 +1,2 @@
AnnotationVersion.java:12:27: compiler.err.type.annotations.not.supported.in.source: 1.7
AnnotationVersion.java:12:27: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.type.annotations), 7, 8
1 error

View File

@ -135,7 +135,7 @@ public class CheckErrorsForSource7 {
boolean found = false;
for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERROR.equals(d.getCode())) {
if (found) {
throw new IllegalStateException("More than one expected error found.");
}
@ -149,10 +149,7 @@ public class CheckErrorsForSource7 {
}
}
static final Set<String> EXPECTED_ERRORS = new HashSet<>(Arrays.asList(
"compiler.err.type.annotations.not.supported.in.source",
"compiler.err.annotations.after.type.params.not.supported.in.source"
));
static final String EXPECTED_ERROR = "compiler.err.feature.not.supported.in.source.plural";
class TestFO extends SimpleJavaFileObject {
private final String content;

View File

@ -1,4 +1,4 @@
- compiler.warn.source.no.bootclasspath: 1.7
- compiler.warn.source.no.bootclasspath: 7
Conditional.java:16:38: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.util.List<? extends java.lang.Object>, java.util.List<java.lang.String>)
1 error
1 warning

View File

@ -1,2 +1,2 @@
StaticInvokeQualified.java:11:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6
StaticInvokeQualified.java:11:32: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.static.intf.method.invoke), 6, 8
1 error

View File

@ -1,2 +1,2 @@
StaticInvokeQualified.java:11:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7
StaticInvokeQualified.java:11:32: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.static.intf.method.invoke), 7, 8
1 error

View File

@ -1,2 +1,2 @@
StaticInvokeSimple.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6
StaticInvokeSimple.java:12:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.static.intf.method.invoke), 6, 8
1 error

View File

@ -1,2 +1,2 @@
StaticInvokeSimple.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7
1 error
StaticInvokeSimple.java:12:15: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.static.intf.method.invoke), 7, 8
1 error

View File

@ -1,4 +1,4 @@
- compiler.warn.source.no.bootclasspath: 1.8
- compiler.warn.source.no.bootclasspath: 8
SuppressDeprecation.java:83:10: compiler.warn.has.been.deprecated: g(), T
SuppressDeprecation.java:84:14: compiler.warn.has.been.deprecated: g(), T
SuppressDeprecation.java:85:9: compiler.warn.has.been.deprecated: var, T

View File

@ -61,6 +61,7 @@ compiler.misc.fatal.err.cant.locate.ctor # Resolve, from Lower
compiler.misc.fatal.err.cant.locate.field # Resolve, from Lower
compiler.misc.fatal.err.cant.locate.meth # Resolve, from Lower
compiler.misc.fatal.err.cant.close # JavaCompiler
compiler.misc.feature.not.supported.in.source.plural # cannot happen (for now)
compiler.misc.file.does.not.contain.package
compiler.misc.illegal.start.of.class.file
compiler.misc.inferred.do.not.conform.to.lower.bounds # cannot happen?

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.annotations.after.type.params.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.annotations.after.type.params
// key: compiler.warn.source.no.bootclasspath
// options: -source 7

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.default.methods.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.default.methods
// options: -source 7 -Xlint:-options
interface DefaultMethodNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.misc.diamond.and.anon.class.not.supported.in.source
// key: compiler.misc.feature.not.supported.in.source
// key: compiler.misc.feature.diamond.and.anon.class
// key: compiler.err.cant.apply.diamond.1
// key: compiler.warn.source.no.bootclasspath
// options: -source 8

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.diamond.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source
// key: compiler.misc.feature.diamond
// options: -source 6 -Xlint:-options
import java.util.*;

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.intersection.types.in.cast.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.intersection.types.in.cast
// options: -source 7 -Xlint:-options
interface IntersectionTypesInCastNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.lambda.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.lambda
// options: -source 7 -Xlint:-options
class LambdaNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.method.references.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.method.references
// options: -source 7 -Xlint:-options
class MethodReferencesNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.modules.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.modules
// key: compiler.warn.source.no.bootclasspath
// options: -source 8 -Xlint:-path

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.multicatch.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.multicatch
// options: -source 1.6 -Xlint:-options
class MulticatchNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.private.intf.methods.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.private.intf.methods
// key: compiler.warn.source.no.bootclasspath
// options: -source 8

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.repeatable.annotations.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.repeatable.annotations
// key: compiler.warn.source.no.bootclasspath
// options: -source 7

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.static.intf.method.invoke.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.static.intf.method.invoke
// options: -source 7 -Xlint:-options
import java.util.stream.Stream;

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.static.intf.methods.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.static.intf.methods
// options: -source 7 -Xlint:-options -XDallowStaticInterfaceMethods
interface StaticIntfMethodNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.string.switch.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.string.switch
// options: -source 6 -Xlint:-options
class StringSwitchNotSupported {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.try.with.resources.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source
// key: compiler.misc.feature.try.with.resources
// options: -source 1.6 -Xlint:-options
import java.io.*;

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.type.annotations.not.supported.in.source
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.type.annotations
// key: compiler.warn.source.no.bootclasspath
// options: -source 7

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.unsupported.binary.lit
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.binary.lit
// options: -source 6 -Xlint:-options
class UnsupportedBinaryLiteral {

View File

@ -21,7 +21,8 @@
* questions.
*/
// key: compiler.err.unsupported.underscore.lit
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.underscore.lit
// options: -source 6 -Xlint:-options
class UnsupportedUnderscoreLiteral {

Some files were not shown because too many files have changed in this diff Show More