diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index df7fe5f9fef..522204d78c7 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/make/autoconf/flags-cflags.m4 @@ -172,28 +172,53 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS], DISABLE_WARNING_PREFIX="-wd" BUILD_CC_DISABLE_WARNING_PREFIX="-wd" CFLAGS_WARNINGS_ARE_ERRORS="-WX" + + WARNINGS_ENABLE_ALL="-W3" + DISABLED_WARNINGS="4800" ;; + solstudio) DISABLE_WARNING_PREFIX="-erroff=" - CFLAGS_WARNINGS_ARE_ERRORS="-errtags -errwarn=%all" + CFLAGS_WARNINGS_ARE_ERRORS="-errwarn=%all" + + WARNINGS_ENABLE_ALL_CFLAGS="-v" + WARNINGS_ENABLE_ALL_CXXFLAGS="+w" + + DISABLED_WARNINGS_C="" + DISABLED_WARNINGS_CXX="" ;; + gcc) DISABLE_WARNING_PREFIX="-Wno-" BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-" CFLAGS_WARNINGS_ARE_ERRORS="-Werror" ;; + clang) DISABLE_WARNING_PREFIX="-Wno-" CFLAGS_WARNINGS_ARE_ERRORS="-Werror" + + WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2" + WARNINGS_ENABLE_ADDITIONAL_JVM="-Wpointer-arith -Wsign-compare -Wunused-function -Wundef -Wunused-value -Woverloaded-virtual -Wreorder" + + DISABLED_WARNINGS="unused-parameter unused" ;; + xlc) DISABLE_WARNING_PREFIX="-qsuppress=" CFLAGS_WARNINGS_ARE_ERRORS="-qhalt=w" + + # Possibly a better subset than "all" is "lan:trx:ret:zea:cmp:ret" + WARNINGS_ENABLE_ALL="-qinfo=all -qformat=all" + DISABLED_WARNINGS="" ;; esac AC_SUBST(DISABLE_WARNING_PREFIX) AC_SUBST(BUILD_CC_DISABLE_WARNING_PREFIX) AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS) + AC_SUBST(DISABLED_WARNINGS) + AC_SUBST(DISABLED_WARNINGS_C) + AC_SUBST(DISABLED_WARNINGS_CXX) ]) AC_DEFUN([FLAGS_SETUP_QUALITY_CHECKS], @@ -527,11 +552,14 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX fi elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then - TOOLCHAIN_CFLAGS_JDK="-mt" - TOOLCHAIN_CFLAGS_JDK_CONLY="-xCC -Xa -v -W0,-noglobal" # C only + TOOLCHAIN_FLAGS="-errtags -errfmt" + TOOLCHAIN_CFLAGS="-errshort=tags" + + TOOLCHAIN_CFLAGS_JDK="-mt $TOOLCHAIN_FLAGS" + TOOLCHAIN_CFLAGS_JDK_CONLY="-xc99=%none -xCC -Xa -W0,-noglobal $TOOLCHAIN_CFLAGS" # C only TOOLCHAIN_CFLAGS_JDK_CXXONLY="-features=no%except -norunpath -xnolib" # CXX only TOOLCHAIN_CFLAGS_JVM="-template=no%extdef -features=no%split_init \ - -library=stlport4 -mt -features=no%except" + -library=stlport4 -mt -features=no%except $TOOLCHAIN_FLAGS" if test "x$DEBUG_LEVEL" = xslowdebug; then # Previously -g was used instead of -g0 for slowdebug; this is equivalent # to setting +d. @@ -539,6 +567,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], fi elif test "x$TOOLCHAIN_TYPE" = xxlc; then + # Suggested additions: -qsrcmsg to get improved error reporting # set -qtbtable=full for a better traceback table/better stacks in hs_err when xlc16 is used TOOLCHAIN_CFLAGS_JDK="-qtbtable=full -qchars=signed -qfullpath -qsaveopt -qstackprotect" # add on both CFLAGS TOOLCHAIN_CFLAGS_JVM="-qtbtable=full -qtune=balanced \ @@ -550,37 +579,26 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], # CFLAGS WARNINGS STUFF # Set JVM_CFLAGS warning handling - if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then - # COMMON to gcc and clang - WARNING_CFLAGS_JVM="-Wpointer-arith -Wsign-compare -Wunused-function" - if ! HOTSPOT_CHECK_JVM_VARIANT(zero); then - # Non-zero builds have stricter warnings - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wundef -Wformat=2" - fi - - fi if test "x$TOOLCHAIN_TYPE" = xgcc; then - WARNING_CFLAGS_JDK="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2" - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wunused-value -Woverloaded-virtual" + WARNING_CFLAGS_JDK="$WARNINGS_ENABLE_ALL" + WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL $WARNINGS_ENABLE_ADDITIONAL_JVM" - if ! HOTSPOT_CHECK_JVM_VARIANT(zero); then - # Non-zero builds have stricter warnings - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wreturn-type" - fi elif test "x$TOOLCHAIN_TYPE" = xclang; then - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wno-deprecated" if test "x$OPENJDK_TARGET_OS" = xlinux; then - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wno-sometimes-uninitialized" - WARNING_CFLAGS_JDK="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2" + WARNING_CFLAGS_JDK="$WARNINGS_ENABLE_ALL" + else + WARNING_CFLAGS_JDK="" # currently left empty fi + WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL $WARNINGS_ENABLE_ADDITIONAL_JVM" + elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then - WARNING_CFLAGS_JDK_CONLY="-errshort=tags" - WARNING_CFLAGS_JDK_CXXONLY="+w" - WARNING_CFLAGS_JDK="-errtags=yes -errfmt" + WARNING_CFLAGS_JDK_CONLY="$WARNINGS_ENABLE_ALL_CFLAGS" + WARNING_CFLAGS_JDK_CXXONLY="$WARNINGS_ENABLE_ALL_CXXFLAGS" + WARNING_CFLAGS_JVM="" # currently left empty elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then - WARNING_CFLAGS="-W3" - WARNING_CFLAGS_JDK="-wd4800" - WARNING_CFLAGS_JVM="-wd4800" + WARNING_CFLAGS="$WARNINGS_ENABLE_ALL" + elif test "x$TOOLCHAIN_TYPE" = xxlc; then + WARNING_CFLAGS="" # currently left empty fi # Set some additional per-OS defines. diff --git a/make/autoconf/flags-ldflags.m4 b/make/autoconf/flags-ldflags.m4 index 2202bb69e96..9db09c38380 100644 --- a/make/autoconf/flags-ldflags.m4 +++ b/make/autoconf/flags-ldflags.m4 @@ -137,6 +137,14 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER], fi fi + # Setup warning flags + if test "x$TOOLCHAIN_TYPE" = xsolstudio; then + LDFLAGS_WARNINGS_ARE_ERRORS="-Wl,-z,fatal-warnings" + else + LDFLAGS_WARNINGS_ARE_ERRORS="" + fi + AC_SUBST(LDFLAGS_WARNINGS_ARE_ERRORS) + # Setup LDFLAGS for linking executables if test "x$TOOLCHAIN_TYPE" = xgcc; then EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -Wl,--allow-shlib-undefined" diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index 3787b126002..34a056ea63e 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -469,6 +469,10 @@ CXX_FLAG_DEPS:=@CXX_FLAG_DEPS@ DISABLE_WARNING_PREFIX := @DISABLE_WARNING_PREFIX@ CFLAGS_WARNINGS_ARE_ERRORS:=@CFLAGS_WARNINGS_ARE_ERRORS@ +LDFLAGS_WARNINGS_ARE_ERRORS:=@LDFLAGS_WARNINGS_ARE_ERRORS@ +DISABLED_WARNINGS := @DISABLED_WARNINGS@ +DISABLED_WARNINGS_C := @DISABLED_WARNINGS_C@ +DISABLED_WARNINGS_CXX := @DISABLED_WARNINGS_CXX@ # A global flag (true or false) determining if native warnings are considered errors. WARNINGS_AS_ERRORS := @WARNINGS_AS_ERRORS@ diff --git a/make/common/NativeCompilation.gmk b/make/common/NativeCompilation.gmk index 0710bf5bf97..d765b77ca90 100644 --- a/make/common/NativeCompilation.gmk +++ b/make/common/NativeCompilation.gmk @@ -747,9 +747,13 @@ define SetupNativeCompilationBody # Pick up disabled warnings, if possible on this platform. ifneq ($(DISABLE_WARNING_PREFIX), ) $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ + $$(DISABLED_WARNINGS) \ + $$(DISABLED_WARNINGS_C) \ $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE))) $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ + $$(DISABLED_WARNINGS) \ + $$(DISABLED_WARNINGS_CXX) \ $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE))) endif @@ -767,6 +771,7 @@ define SetupNativeCompilationBody ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true) $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) + $1_EXTRA_LDFLAGS += $(LDFLAGS_WARNINGS_ARE_ERRORS) endif ifeq (NONE, $$($1_OPTIMIZATION)) @@ -975,8 +980,8 @@ define SetupNativeCompilationBody # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables # for LDFLAGS and LIBS - $1_EXTRA_LDFLAGS := $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) - $1_EXTRA_LIBS := $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) + $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) + $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) ifneq ($$($1_REAL_MAPFILE), ) $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) endif diff --git a/make/hotspot/lib/CompileGtest.gmk b/make/hotspot/lib/CompileGtest.gmk index 891c540bb80..f6af4d3b0b4 100644 --- a/make/hotspot/lib/CompileGtest.gmk +++ b/make/hotspot/lib/CompileGtest.gmk @@ -77,11 +77,14 @@ $(eval $(call SetupNativeCompilation, BUILD_GTEST_LIBJVM, \ CFLAGS_windows := -EHsc, \ CFLAGS_solaris := -DGTEST_HAS_EXCEPTIONS=0 -library=stlport4 +d, \ CFLAGS_macosx := -DGTEST_OS_MAC=1, \ - DISABLED_WARNINGS_gcc := undef stringop-overflow, \ - DISABLED_WARNINGS_clang := undef switch format-nonliteral \ - tautological-undefined-compare $(BUILD_LIBJVM_DISABLED_WARNINGS_clang), \ - DISABLED_WARNINGS_solstudio := identexpected, \ - DISABLED_WARNINGS_microsoft := 4146, \ + DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc) \ + undef, \ + DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang) \ + undef switch format-nonliteral tautological-undefined-compare, \ + DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio) \ + identexpected, \ + DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft) \ + 4146, \ LDFLAGS := $(JVM_LDFLAGS), \ LDFLAGS_solaris := -library=stlport4 $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := $(JVM_LIBS), \ diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index bce8bf0c9d1..48e75e241c6 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -81,6 +81,25 @@ CFLAGS_VM_VERSION := \ -DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \ # +################################################################################ +# Disabled warnings + +DISABLED_WARNINGS_gcc := extra all +ifeq ($(call check-jvm-feature, zero), true) + DISABLED_WARNINGS_gcc += return-type +endif + +DISABLED_WARNINGS_clang := extra all tautological-compare deprecated-declarations + +DISABLED_WARNINGS_solstudio := + +DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 1540-1088 \ + 1500-010 + +DISABLED_WARNINGS_microsoft := + + + ################################################################################ # Platform specific setup @@ -117,7 +136,7 @@ ifeq ($(call isTargetOs, solaris), true) endif # Exclude warnings in devstudio 12.6 ifeq ($(CC_VERSION_NUMBER), 5.15) - DISABLED_WARNINGS_solstudio := SEC_ARR_OUTSIDE_BOUND_READ \ + DISABLED_WARNINGS_solstudio += SEC_ARR_OUTSIDE_BOUND_READ \ SEC_ARR_OUTSIDE_BOUND_WRITE endif endif @@ -162,11 +181,11 @@ $(eval $(call SetupNativeCompilation, BUILD_LIBJVM, \ CFLAGS := $(JVM_CFLAGS), \ abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ - DISABLED_WARNINGS_clang := tautological-compare, \ + DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \ + DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \ DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio), \ - DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 \ - 1540-1088 1500-010, \ - DISABLED_WARNINGS_microsoft := 4146, \ + DISABLED_WARNINGS_xlc := $(DISABLED_WARNINGS_xlc), \ + DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft) 4146, \ ASFLAGS := $(JVM_ASFLAGS), \ LDFLAGS := $(JVM_LDFLAGS), \ LIBS := $(JVM_LIBS), \ diff --git a/src/hotspot/share/legal/siphash.md b/src/java.base/share/legal/siphash.md similarity index 98% rename from src/hotspot/share/legal/siphash.md rename to src/java.base/share/legal/siphash.md index 1583f229e1e..a1183acf2b0 100644 --- a/src/hotspot/share/legal/siphash.md +++ b/src/java.base/share/legal/siphash.md @@ -4,12 +4,12 @@ SipHash reference C implementation ``` - Copyright (c) 2012-2021 Jean-Philippe Aumasson - - Copyright (c) 2012-2014 Daniel J. Bernstein + Copyright (c) 2016 Jean-Philippe Aumasson + To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. + You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see diff --git a/src/java.base/share/native/libjli/parse_manifest.c b/src/java.base/share/native/libjli/parse_manifest.c index 2889fab0686..a0d87b8bb9e 100644 --- a/src/java.base/share/native/libjli/parse_manifest.c +++ b/src/java.base/share/native/libjli/parse_manifest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2022, 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 @@ -288,8 +288,8 @@ find_positions(int fd, Byte *eb, jlong* base_offset, jlong* censtart) for (cp = &buffer[bytes - ENDHDR]; cp >= &buffer[0]; cp--) if (ENDSIG_AT(cp) && (cp + ENDHDR + ENDCOM(cp) == endpos)) { (void) memcpy(eb, cp, ENDHDR); - free(buffer); pos = flen - (endpos - cp); + free(buffer); return find_positions64(fd, eb, pos, base_offset, censtart); } free(buffer); diff --git a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java index 93f65327e08..edce4418919 100644 --- a/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java +++ b/src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java @@ -26,10 +26,8 @@ package sun.print; import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.IOException; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Vector; import java.security.AccessController; @@ -54,6 +52,8 @@ import java.net.URL; import java.nio.file.Files; +import sun.awt.util.ThreadGroupUtils; + /* * Remind: This class uses solaris commands. We also need a linux * version @@ -207,14 +207,18 @@ static int getBSDCommandIndex() { return BSD_LPD; } - + @SuppressWarnings("removal") public PrintServiceLookupProvider() { // start the printer listener thread if (pollServices) { - Thread thr = new Thread(null, new PrinterChangeListener(), - "PrinterListener", 0, false); - thr.setDaemon(true); - thr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new PrinterChangeListener(), + "PrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); IPPPrintService.debug_println(debugPrefix+"polling turned on"); } } diff --git a/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java b/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java index f82ca605324..cf488c4b162 100644 --- a/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java +++ b/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java @@ -25,6 +25,8 @@ package sun.print; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import javax.print.DocFlavor; @@ -41,6 +43,8 @@ import javax.print.attribute.PrintServiceAttributeSet; import javax.print.attribute.standard.PrinterName; +import sun.awt.util.ThreadGroupUtils; + public class PrintServiceLookupProvider extends PrintServiceLookup { private String defaultPrinter; @@ -78,22 +82,31 @@ public static PrintServiceLookupProvider getWin32PrintLUS() { return win32PrintLUS; } + @SuppressWarnings("removal") public PrintServiceLookupProvider() { if (win32PrintLUS == null) { win32PrintLUS = this; // start the local printer listener thread - Thread thr = new Thread(null, new PrinterChangeListener(), - "PrinterListener", 0, false); - thr.setDaemon(true); - thr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new PrinterChangeListener(), + "PrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); // start the remote printer listener thread - Thread remThr = new Thread(null, new RemotePrinterChangeListener(), - "RemotePrinterListener", 0, false); - remThr.setDaemon(true); - remThr.start(); + AccessController.doPrivileged((PrivilegedAction) () -> { + Thread thr = new Thread(ThreadGroupUtils.getRootThreadGroup(), + new RemotePrinterChangeListener(), + "RemotePrinterListener", 0, false); + thr.setContextClassLoader(null); + thr.setDaemon(true); + return thr; + }).start(); } /* else condition ought to never happen! */ } diff --git a/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java b/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java index 3dd060be231..b8e00e53848 100644 --- a/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java +++ b/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /** * @test TestJmapCoreMetaspace - * @summary Test verifies that jhsdb jmap could generate heap dump from core when metspace is full + * @summary Test verifies that jhsdb jmap could generate heap dump from core when metaspace is full * @requires vm.hasSA * @library /test/lib * @run driver/timeout=480 TestJmapCore run metaspace diff --git a/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java b/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java index 042d10ad57f..271c3fd2443 100644 --- a/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java +++ b/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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 @@ -52,7 +52,7 @@ private static enum MethodGroup { MODE("isInt", "isMixed", "isComp"), IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported", "areCustomLoadersSupportedForCDS", - "isHardenedOSX"); + "isHardenedOSX", "hasOSXPlistEntries"); public final List methodNames; diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr30st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr30st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr30st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp0mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr30st0t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr30st0t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr30st0t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp30mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp0rp70mr30st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr30st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr30st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr30st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp0mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr30st0t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr30st0t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr30st0t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp30mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp10rp70mr30st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr30st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr30st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr30st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp0mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr30st0t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr30st0t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr30st0t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp30mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp30yp25rp70mr30st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr30st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr30st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr30st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp0mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr30st0t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr30st0t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr30st0t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp30mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp0rp70mr30st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr30st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr30st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr30st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp0mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr30st0t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr30st0t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr30st0t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp30mr70st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st0/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st0/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st0/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st300t1/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st300t1/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp50yp10rp70mr30st300t1/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp60yp0rp30mr0st300/TEST.properties b/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp60yp0rp30mr0st300/TEST.properties deleted file mode 100644 index 04b22a107ac..00000000000 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/concurrent/lp60yp0rp30mr0st300/TEST.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# 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. -# -exclusiveAccess.dirs=. diff --git a/test/jdk/com/sun/jndi/ldap/Base64Test.java b/test/jdk/com/sun/jndi/ldap/Base64Test.java index b6c47414b82..900e04ad123 100644 --- a/test/jdk/com/sun/jndi/ldap/Base64Test.java +++ b/test/jdk/com/sun/jndi/ldap/Base64Test.java @@ -163,9 +163,6 @@ public static void main(String[] args) throws Exception { */ private static void deserialize(byte[] bytes) throws Exception { - //System.out.println("\nSerialized RefAddr object: "); - //System.out.println(new sun.security.util.HexDumpEncoder().encode(bytes)); - ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(bytes)); Object object = objectStream.readObject(); diff --git a/test/jdk/com/sun/security/sasl/ntlm/NTLMTest.java b/test/jdk/com/sun/security/sasl/ntlm/NTLMTest.java index aed713d598c..5b5841b0aae 100644 --- a/test/jdk/com/sun/security/sasl/ntlm/NTLMTest.java +++ b/test/jdk/com/sun/security/sasl/ntlm/NTLMTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,7 @@ /* * @test * @bug 6911951 7150092 + * @library /test/lib * @summary NTLM should be a supported Java SASL mechanism * @modules java.base/sun.security.util * java.security.sasl @@ -32,7 +33,7 @@ import javax.security.sasl.*; import javax.security.auth.callback.*; import java.util.*; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; public class NTLMTest { @@ -312,7 +313,7 @@ private static void handshake(SaslClient clnt, SaslServer srv) byte[] response = (clnt.hasInitialResponse() ? clnt.evaluateChallenge(EMPTY) : EMPTY); System.out.println("Initial:"); - new HexDumpEncoder().encodeBuffer(response, System.out); + HexPrinter.simple().format(response); byte[] challenge; while (!clnt.isComplete() || !srv.isComplete()) { @@ -320,12 +321,12 @@ private static void handshake(SaslClient clnt, SaslServer srv) response = null; if (challenge != null) { System.out.println("Challenge:"); - new HexDumpEncoder().encodeBuffer(challenge, System.out); + HexPrinter.simple().format(challenge); response = clnt.evaluateChallenge(challenge); } if (response != null) { System.out.println("Response:"); - new HexDumpEncoder().encodeBuffer(response, System.out); + HexPrinter.simple().format(response); } } diff --git a/test/jdk/java/awt/Focus/NoFocusOwnerAWTTest.java b/test/jdk/java/awt/Focus/NoFocusOwnerAWTTest.java new file mode 100644 index 00000000000..953c392e79f --- /dev/null +++ b/test/jdk/java/awt/Focus/NoFocusOwnerAWTTest.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2001, 2023, 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 4390019 + @summary REGRESSION: Alt-F4 keybinding no longer shuts down java application on Windows + @key headful + @requires (os.family == "windows") + @run main NoFocusOwnerAWTTest +*/ +import java.awt.Frame; +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.Label; +import java.awt.MenuBar; +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.MenuShortcut; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowAdapter; + +public class NoFocusOwnerAWTTest { + + static boolean actionFired = false; + static boolean closingWindowCalled = false; + static Frame frame; + + public static void main(String[] args) throws Exception { + try { + if (!System.getProperty("os.name").startsWith("Windows")) { + // this test is Win32 test only + return; + } + EventQueue.invokeAndWait(() -> { + + frame = new Frame("No Focus Owner AWT Test"); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.out.println("windowClosing() is called."); + closingWindowCalled = true; + } + }); + frame.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent fe) { + System.out.println("focus gained on frame"); + } + public void focusLost(FocusEvent fe) { + System.out.println("focus lost on frame"); + } + }); + MenuBar mb = new MenuBar(); + Menu m = new Menu("This is Menu"); + MenuItem mi = new MenuItem("Menu Item"); + mi.setShortcut(new MenuShortcut(KeyEvent.VK_A)); + mi.addActionListener( new ActionListener() { + public void actionPerformed(ActionEvent ae) { + System.out.println("action"); + actionFired = true; + } + }); + m.add(mi); + mb.add(m); + frame.setMenuBar(mb); + Label lb; + frame.add(lb = new Label("press")); + lb.addFocusListener(new FocusListener() { + public void focusGained(FocusEvent fe) { + System.out.println("focus gained on label"); + } + public void focusLost(FocusEvent fe) { + System.out.println("focus lost on label"); + } + }); + frame.pack(); + frame.toFront(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + + Robot robot = new Robot(); + robot.setAutoDelay(100); + robot.delay(1000); + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_A); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_CONTROL); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_ALT); + robot.keyPress(KeyEvent.VK_F4); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_F4); + robot.keyRelease(KeyEvent.VK_ALT); + robot.waitForIdle(); + robot.delay(1000); + + if (!actionFired || !closingWindowCalled) { + throw new RuntimeException("Test FAILED(actionFired="+actionFired+ + ";closingWindowCalled="+closingWindowCalled+")"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + } + }// class NoFocusOwnerAWTTest diff --git a/test/jdk/java/awt/Focus/NoFocusOwnerSwingTest.java b/test/jdk/java/awt/Focus/NoFocusOwnerSwingTest.java new file mode 100644 index 00000000000..23c898ae823 --- /dev/null +++ b/test/jdk/java/awt/Focus/NoFocusOwnerSwingTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2001, 2023, 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 4390019 + @summary REGRESSION: Alt-F4 keybinding no longer shuts down java application on Windows + @key headful + @requires (os.family == "windows") + @run main NoFocusOwnerSwingTest +*/ + +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.Label; +import java.awt.MenuBar; +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.MenuShortcut; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowAdapter; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +public class NoFocusOwnerSwingTest { + static boolean closingWindowCalled = false; + static JFrame frame; + + public static void main(String[] args) throws Exception { + try { + if (!System.getProperty("os.name").startsWith("Windows")) { + // this test is Win32 test only + return; + } + + SwingUtilities.invokeAndWait(() -> { + frame = new JFrame("No Focus Owner Swing Test"); + JButton btn; + frame.getContentPane().add(btn = new JButton("press")); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.out.println("windowClosing is called"); + closingWindowCalled = true; + } + }); + frame.pack(); + frame.toFront(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + + Robot robot = new Robot(); + robot.setAutoDelay(100); + robot.delay(1000); + robot.keyPress(KeyEvent.VK_ALT); + robot.keyPress(KeyEvent.VK_F4); + robot.waitForIdle(); + robot.keyRelease(KeyEvent.VK_F4); + robot.keyRelease(KeyEvent.VK_ALT); + robot.waitForIdle(); + + if (!closingWindowCalled) { + throw new RuntimeException("Test FAILED(closingWindowCalled=" + + closingWindowCalled + ")"); + } + } finally { + SwingUtilities.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } +}// class NoFocusOwnerSwingTest diff --git a/test/jdk/java/awt/Focus/QuickTypeTest.java b/test/jdk/java/awt/Focus/QuickTypeTest.java new file mode 100644 index 00000000000..0cfd0ef5f1d --- /dev/null +++ b/test/jdk/java/awt/Focus/QuickTypeTest.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2002, 2023, 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 4423838 + @summary KEY_TYPED and KEY_PRESSED generated by the same key are notified to + different TextFields + @key headful + @run main QuickTypeTest +*/ + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Panel; +import java.awt.Point; +import java.awt.Robot; +import java.awt.TextArea; +import java.awt.EventQueue; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import java.util.Properties; + +import javax.swing.JFrame; +import javax.swing.JTextField; + +public class QuickTypeTest { + static final int TEST_TIMEOUT=10000; + static JFrame frame1; + static JFrame frame2; + static JTextField tf1; + static JTextField tf2; + static SmartKeyAdapter ska; + static Object keyMonitor; + + public static void main(String[] args) throws Exception { + try { + EventQueue.invokeAndWait(() -> { + frame1 = new JFrame("First Frame"); + frame2 = new JFrame("Second Frame"); + tf1 = new JTextField("", 10); + tf2 = new JTextField("", 10); + frame1.getContentPane().add(tf1); + frame2.getContentPane().add(tf2); + frame1.setLocation(200,220); + frame2.setLocation(220,300); + frame1.pack(); + frame2.pack(); + keyMonitor = new Object(); + ska = new SmartKeyAdapter(frame2, keyMonitor); + tf1.addKeyListener(ska); + frame1.setVisible(true); + }); + + Robot robot = new Robot(); + robot.setAutoWaitForIdle(true); + robot.setAutoDelay(100); + robot.waitForIdle(); + robot.delay(1000); + Object tf1Monitor = new Object(); + MonitoredFocusListener monitorer = new MonitoredFocusListener(tf1Monitor); + tf1.addFocusListener(monitorer); + Point origin = tf1.getLocationOnScreen(); + Dimension dim = tf1.getSize(); + robot.mouseMove((int)origin.getX() + (int)dim.getWidth()/2, + (int)origin.getY() + (int)dim.getHeight()/2); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + + if (!tf1.isFocusOwner()) { + synchronized (tf1Monitor) { + tf1Monitor.wait(TEST_TIMEOUT); + } + } + if (!tf1.isFocusOwner()) { + throw new RuntimeException("TEST FAILED. tf1 doesn't receive focus."); + } + + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyPress(KeyEvent.VK_B); + robot.keyRelease(KeyEvent.VK_B); + if (!ska.isFrameShown) { + synchronized (keyMonitor) { + keyMonitor.wait(TEST_TIMEOUT); + } + } + if (!ska.isFrameShown) { + throw new RuntimeException("TEST FAILED. Second frame is not shown."); + } + + Object waitMonitor = new Object(); + ReleaseWaiter waiter = new ReleaseWaiter(waitMonitor, KeyEvent.VK_C); + tf1.addKeyListener(waiter); + tf2.addKeyListener(waiter); + robot.keyPress(KeyEvent.VK_C); + robot.keyRelease(KeyEvent.VK_C); + + synchronized (waitMonitor) { + waitMonitor.wait(2000); + } + + if ((tf1.getText().length() > 2) || (tf2.getText().length() < 1)) { + System.out.println("tf1's text = \"" + tf1.getText() + "\""); + System.out.println("tf2's text = \"" + tf2.getText() + "\""); + System.out.println("l1 = " + tf1.getText().length()); + System.out.println("l2 = " + tf2.getText().length()); + throw new RuntimeException("TEST FAILED."); + } + } finally { + EventQueue.invokeAndWait(() -> { + if (frame1 != null) { + frame1.dispose(); + } + if (frame2 != null) { + frame2.dispose(); + } + }); + } + } + + }// class QuickTypeTest + +class ReleaseWaiter extends KeyAdapter { + Object monitor; + int keycode; + public ReleaseWaiter(Object monitor, int keycode) { + this.monitor = monitor; + this.keycode = keycode; + } + + public void keyReleased(KeyEvent ke) { + System.out.println("keyReleased " + ke.getKeyCode()); + if (ke.getKeyCode() == keycode) { + synchronized (monitor) { + monitor.notify(); + } + } + } +} + +class SmartKeyAdapter implements KeyListener { + JFrame frame; + int charCounter = 0; + boolean isFrameShown = false; + Object monitor; + + public SmartKeyAdapter(JFrame frame, Object monitor) { + this.frame = frame; + this.monitor = monitor; + } + + public void keyReleased(KeyEvent ke) { + System.out.println(ke.toString()); + } + public void keyPressed(KeyEvent ke) { + System.out.println(ke.toString()); + charCounter++; + if (charCounter == 2) { + frame.setVisible(true); + isFrameShown = true; + synchronized (monitor) { + monitor.notify(); + } + } + } + public void keyTyped(KeyEvent ke) { + System.out.println(ke.toString()); + } +} + +class MonitoredFocusListener extends FocusAdapter { + Object monitor; + + public MonitoredFocusListener(Object monitor) { + this.monitor = monitor; + } + + public void focusLost(FocusEvent fe) { + System.out.println(fe.toString()); + } + public void focusGained(FocusEvent fe) { + System.out.println(fe.toString()); + synchronized (monitor) { + monitor.notify(); + } + } +} diff --git a/test/jdk/java/awt/Focus/RestoreFocusInfiniteLoopTest.java b/test/jdk/java/awt/Focus/RestoreFocusInfiniteLoopTest.java new file mode 100644 index 00000000000..64b1ae9477c --- /dev/null +++ b/test/jdk/java/awt/Focus/RestoreFocusInfiniteLoopTest.java @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2002, 2023, 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 4504665 + @summary MerlinBeta2 - vetoing a focus change causes infinite loop + @key headful + @run main RestoreFocusInfiniteLoopTest +*/ + +import java.awt.AWTException; +import java.awt.Button; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.KeyboardFocusManager; +import java.awt.Point; +import java.awt.Robot; +import java.awt.TextArea; + +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; + +public class RestoreFocusInfiniteLoopTest { + static final int TEST_TIMEOUT = 1000; + static final int DELAY = 100; + static Button b1; + static Frame frame; + static Object b1Monitor; + static Point origin; + static Dimension dim; + static MonitoredFocusListener monitorer; + + public static void main(String[] args) throws Exception { + try { + EventQueue.invokeAndWait(() -> { + + b1Monitor = new Object(); + frame = new Frame(); + b1 = new Button("1"); + Button b2 = new Button("2"); + b1.setName("b1"); + b2.setName("b2"); + + frame.setLayout(new FlowLayout()); + frame.add(b1); + frame.add(b2); + frame.pack(); + frame.setSize(100, 100); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + FocusVetoableChangeListener vetoer = new FocusVetoableChangeListener(b2); + KeyboardFocusManager.getCurrentKeyboardFocusManager(). + addVetoableChangeListener("focusOwner", vetoer); + + }); + Robot robot = new Robot(); + robot.setAutoDelay(DELAY); + robot.setAutoWaitForIdle(true); + robot.delay(1000); + EventQueue.invokeAndWait(() -> { + monitorer = new MonitoredFocusListener(b1Monitor); + b1.addFocusListener(monitorer); + origin = b1.getLocationOnScreen(); + dim = b1.getSize(); + }); + robot.mouseMove((int)origin.getX() + (int)dim.getWidth()/2, + (int)origin.getY() + (int)dim.getHeight()/2); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + + if (!b1.isFocusOwner()) { + synchronized (b1Monitor) { + b1Monitor.wait(TEST_TIMEOUT); + } + } + + monitorer.resetFocusLost(); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + + if (!monitorer.isFocusLostReceived() || !b1.isFocusOwner()) { + synchronized (b1Monitor) { + b1Monitor.wait(TEST_TIMEOUT); + } + } + if (!b1.isFocusOwner()) { + throw new RuntimeException("Test is FAILED"); + } else { + System.out.println("Test is PASSED"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + } + + }// class RestoreFocusInfiniteLoopTest + +class FocusVetoableChangeListener implements VetoableChangeListener { + Component vetoedComponent; + public FocusVetoableChangeListener(Component vetoedComponent) { + this.vetoedComponent = vetoedComponent; + } + public void vetoableChange(PropertyChangeEvent evt) + throws PropertyVetoException + { + Component oldComp = (Component)evt.getOldValue(); + Component newComp = (Component)evt.getNewValue(); + + boolean vetoFocusChange = (newComp == vetoedComponent); + process(evt.getPropertyName(), oldComp, newComp); + + if (vetoFocusChange) { + throw new PropertyVetoException("message", evt); + } + } + boolean process(String propName, Component o1, Component o2) { + System.out.println(propName + + " old=" + (o1 != null ? o1.getName() : "null") + + " new=" + (o2 != null ? o2.getName() : "null")); + return true; + } + } + +class MonitoredFocusListener extends FocusAdapter { + Object monitor; + boolean focuslost = false; + + public void resetFocusLost() { + focuslost = false; + } + public boolean isFocusLostReceived() { + return focuslost; + } + public MonitoredFocusListener(Object monitor) { + this.monitor = monitor; + } + + public void focusLost(FocusEvent fe) { + System.out.println(fe.toString()); + focuslost = true; + } + public void focusGained(FocusEvent fe) { + System.out.println(fe.toString()); + synchronized (monitor) { + monitor.notify(); + } + } +} diff --git a/test/jdk/java/awt/Focus/RowToleranceTransitivityTest.java b/test/jdk/java/awt/Focus/RowToleranceTransitivityTest.java new file mode 100644 index 00000000000..099e81a1ab0 --- /dev/null +++ b/test/jdk/java/awt/Focus/RowToleranceTransitivityTest.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2005, 2023, 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 5070991 + @key headful + @summary Tests for a transitivity problem with ROW_TOLERANCE in SortingFTP. + @run main RowToleranceTransitivityTest +*/ +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.KeyboardFocusManager; +import java.awt.Panel; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JFormattedTextField; +import javax.swing.JLabel; +import javax.swing.JPanel; +import java.util.concurrent.atomic.AtomicBoolean; +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.atomic.AtomicBoolean; + +public class RowToleranceTransitivityTest { + static JFrame frame; + static JPanel panel; + static JFormattedTextField ft; + static JCheckBox cb; + static GridBagConstraints gc; + static Robot robot; + + static AtomicBoolean focusGained = new AtomicBoolean(false); + + public static void main(String[] args) throws Exception { + robot = new Robot(); + robot.setAutoDelay(100); + robot.setAutoWaitForIdle(true); + try { + EventQueue.invokeAndWait(() -> { + gc = new GridBagConstraints(); + frame = new JFrame("JFrame"); + JPanel panel = new JPanel(new GridBagLayout()); + ft = new JFormattedTextField(); + cb = new JCheckBox("JCheckBox"); + Dimension dim = new Dimension(100, ft.getPreferredSize().height); + ft.setPreferredSize(dim); + ft.setMinimumSize(dim); + gc.gridx = 5; + gc.gridy = 1; + gc.gridwidth = 10; + panel.add(ft, gc); + + gc.gridy = 3; + panel.add(cb, gc); + + cb.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + System.out.println(e.toString()); + synchronized (focusGained) { + focusGained.set(true); + focusGained.notifyAll(); + } + } + }); + + gc.weightx = 1.0; + gc.gridwidth = 1; + gc.gridy = 0; + gc.gridx = 0; + for (int n = 0; n < 7; n++) { + panel.add(getlabel(), gc); + gc.gridy++; + } + + gc.gridx = 0; + gc.gridy = 0; + for (int n = 0; n < 7; n++) { + panel.add(getlabel(), gc); + gc.gridx++; + } + + frame.getContentPane().add(panel); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + frame.setAlwaysOnTop(true); + + }); + robot.waitForIdle(); + robot.delay(1000); + test(); + } finally { + if (frame != null) { + frame.dispose(); + } + } + } + + static void test() throws Exception { + robot.delay(500); + + // Set focus on the first component to start traversal + if (!setFocusOn(ft, new Runnable() { + public void run() { + clickOn(ft); + } + })) { + System.out.println("Couldn't set focus on " + ft); + throw new RuntimeException("Test couldn't be performed."); + } + + robot.delay(500); + + // Try to traverse + if (!setFocusOn(cb, new Runnable() { + public void run() { + robot.keyPress(KeyEvent.VK_TAB); + } + })) { + System.out.println("Focus got stuck while traversing."); + throw new RuntimeException("Test failed!"); + } + + System.out.println("Test passed."); + } + + static boolean setFocusOn(Component comp, Runnable action) { + + if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == comp) { + System.out.println("Already focus owner: " + comp); + return true; + } + + focusGained.set(false); + + System.out.println("Setting focus on " + comp); + + comp.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + System.out.println(e.toString()); + synchronized (focusGained) { + focusGained.set(true); + focusGained.notifyAll(); + } + } + }); + + action.run(); + + synchronized (focusGained) { + if (!focusGained.get()) { + try { + focusGained.wait(3000); + } catch (InterruptedException e) { + System.out.println("Unexpected exception caught!"); + throw new RuntimeException(e); + } + } + } + + return focusGained.get(); + } + + static JLabel getlabel(){ + Dimension dim = new Dimension(5, 9); // LayoutComparator.ROW_TOLERANCE = 10; + JLabel l = new JLabel("*"); + l.setMinimumSize(dim); + l.setMaximumSize(dim); + l.setPreferredSize(dim); + return l; + } + + static void clickOn(Component c) { + Point p = c.getLocationOnScreen(); + Dimension d = c.getSize(); + + System.out.println("Clicking " + c); + + if (c instanceof Frame) { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + ((Frame)c).getInsets().top/2); + } else { + robot.mouseMove(p.x + (int)(d.getWidth()/2), p.y + (int)(d.getHeight()/2)); + } + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + } + +} diff --git a/test/jdk/java/awt/Focus/SequencedLightweightRequestsTest.java b/test/jdk/java/awt/Focus/SequencedLightweightRequestsTest.java new file mode 100644 index 00000000000..9daa87a4263 --- /dev/null +++ b/test/jdk/java/awt/Focus/SequencedLightweightRequestsTest.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2002, 2023, 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 4648816 + @summary Sometimes focus requests on LW components are delayed + @key headful + @run main SequencedLightweightRequestsTest +*/ + +import java.awt.AWTException; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.TextArea; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.InputEvent; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +public class SequencedLightweightRequestsTest implements FocusListener { + final int WAIT_TIME = 5000; + + JFrame testFrame; + JButton testButton1; + JButton testButton2; + JTextField testField; + + public void focusGained(FocusEvent fe) { + System.err.println("FocusGained on " + fe.getComponent().getName()); + } + + public void focusLost(FocusEvent fe) { + System.err.println("FocusLost on " + fe.getComponent().getName()); + } + + public static void main(String[] args) throws Exception { + SequencedLightweightRequestsTest test = + new SequencedLightweightRequestsTest(); + test.start(); + } + + public void start() throws Exception { + try { + + SwingUtilities.invokeAndWait(() -> { + testFrame = new JFrame("See my components!"); + testButton1 = new JButton("Click me!"); + testButton2 = new JButton("Do I have focus?"); + testField = new JTextField("Do I have focus?"); + testFrame.getContentPane().setLayout(new FlowLayout()); + testFrame.getContentPane().add(testButton1); + testFrame.getContentPane().add(testField); + testFrame.getContentPane().add(testButton2); + + testButton1.setName("Button1"); + testButton2.setName("Button2"); + testField.setName("textField"); + testButton1.addFocusListener(this); + testButton2.addFocusListener(this); + testField.addFocusListener(this); + testFrame.addFocusListener(this); + + testFrame.setSize(300, 100); + testFrame.setLocationRelativeTo(null); + testFrame.setVisible(true); + }); + + Robot robot = new Robot(); + robot.setAutoDelay(100); + robot.setAutoWaitForIdle(true); + + // wait to give to frame time for showing + robot.delay(1000); + + // make sure that first button has focus + Object monitor = new Object(); + MonitoredFocusListener monitorer = + new MonitoredFocusListener(monitor); + Point origin = testButton1.getLocationOnScreen(); + Dimension dim = testButton1.getSize(); + robot.mouseMove((int)origin.getX() + (int)dim.getWidth()/2, + (int)origin.getY() + (int)dim.getHeight()/2); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + + if (!testButton1.isFocusOwner()) { + synchronized (monitor) { + testButton1.addFocusListener(monitorer); + monitor.wait(WAIT_TIME); + testButton1.removeFocusListener(monitorer); + } + } + + // if first button still doesn't have focus, test fails + if (!testButton1.isFocusOwner()) { + throw new RuntimeException("First button doesn't receive focus"); + } + + // two lightweight requests + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + testButton2.requestFocus(); + testField.requestFocus(); + } + }); + + // make sure third button receives focus + if (!testField.isFocusOwner()) { + synchronized (monitor) { + testField.addFocusListener(monitorer); + monitor.wait(WAIT_TIME); + testField.removeFocusListener(monitorer); + } + } + + // if the text field still doesn't have focus, test fails + if (!testField.isFocusOwner()) { + throw new RuntimeException("Text field doesn't receive focus"); + } + System.out.println("Test PASSED"); + } finally { + SwingUtilities.invokeAndWait(() -> { + if (testFrame != null) { + testFrame.dispose(); + } + }); + } + } +}// class SequencedLightweightRequestsTest + +class MonitoredFocusListener extends FocusAdapter { + Object monitor; + + public MonitoredFocusListener(Object monitor) { + this.monitor = monitor; + } + + public void focusGained(FocusEvent fe) { + synchronized (monitor) { + monitor.notify(); + } + } +} diff --git a/test/jdk/java/awt/Focus/SetFocusableTest.java b/test/jdk/java/awt/Focus/SetFocusableTest.java new file mode 100644 index 00000000000..371b8ff49ba --- /dev/null +++ b/test/jdk/java/awt/Focus/SetFocusableTest.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2002, 2023, 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 4597455 + @summary setFocusable(false) is not moving the focus to next Focusable Component + @key headful + @run main SetFocusableTest +*/ + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Color; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.TextArea; +import java.awt.TextField; + +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class SetFocusableTest implements KeyListener { + static Object buttonMonitor; + Object tfMonitor; + static final int TEST_TIMEOUT = 5000; + Button button; + Frame frame; + TextField textfield; + + public static void main(String[] args) throws Exception { + SetFocusableTest test = new SetFocusableTest(); + test.start(); + } + + public void start() throws Exception { + try { + EventQueue.invokeAndWait(() -> { + buttonMonitor = new Object(); + tfMonitor = new Object(); + frame = new Frame(); + frame.setTitle("Test Frame"); + frame.setLocation(100, 100); + frame.setLayout(new FlowLayout()); + + button = new Button("BUTTON"); + textfield = new TextField("First"); + + button.addKeyListener(this); + textfield.addKeyListener(this); + + frame.add(button); + frame.add(textfield); + + frame.setBackground(Color.red); + frame.setSize(500,200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + frame.toFront(); + button.addFocusListener(new MonitoredFocusListener(buttonMonitor)); + textfield.addFocusListener(new MonitoredFocusListener(tfMonitor)); + }); + + Robot robot; + robot = new Robot(); + robot.setAutoDelay(100); + robot.setAutoWaitForIdle(true); + robot.delay(1000); + + Point buttonOrigin = button.getLocationOnScreen(); + Dimension buttonSize = button.getSize(); + robot.mouseMove( + (int)buttonOrigin.getX() + (int)buttonSize.getWidth() / 2, + (int)buttonOrigin.getY() + (int)buttonSize.getHeight() / 2); + + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + + if (!button.isFocusOwner()) { + synchronized (buttonMonitor) { + buttonMonitor.wait(TEST_TIMEOUT); + } + } + System.out.println("\n\nBefore calling the method button.setFocusable(false)"); + System.out.println("===================================================="); + System.out.println("Button is Focusable(button.isFocusable()) :"+button.isFocusable()); + System.out.println("Button is Focus owner(button.isFocusOwner()) :"+button.isFocusOwner()); + System.out.println("Button has Focus (button.hasFocus) :"+button.hasFocus()); + System.out.println("===================================================="); + + button.setFocusable(false); + + if (!textfield.isFocusOwner()) { + synchronized (tfMonitor) { + tfMonitor.wait(TEST_TIMEOUT); + } + } + + System.out.println("\nAfter Calling button.setFocusable(false)"); + System.out.println("===================================================="); + System.out.println("Button is Focusable(button.isFocusable()) :"+button.isFocusable()); + System.out.println("Button is Focus owner(button.isFocusOwner()) :"+button.isFocusOwner()); + System.out.println("Button has Focus (button.hasFocus()) :"+button.hasFocus()); + System.out.println("TextField is Focusable(textfield.isFocusable()) :"+textfield.isFocusable()); + System.out.println("TextField is Focus owner(textfield.isFocusOwner()) :"+textfield.isFocusOwner()); + System.out.println("TextField has Focus (textfield.hasFocus()) :"+textfield.hasFocus()); + System.out.println("====================================================n\n\n\n"); + + if (!button.hasFocus() && !button.isFocusOwner() && + textfield.hasFocus() && textfield.isFocusOwner()){ + System.out.println("\n\n\nASSERTION :PASSED"); + System.out.println("========================="); + System.out.println("Textfield is having the Focus.Transfer of Focus has happend."); + } else { + System.out.println("\n\n\nASSERTION :FAILED"); + System.out.println("=========================="); + System.out.println("Button is still having the Focus instead of TextField"); + throw new RuntimeException("Test FIALED"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + }// start() + + public void keyPressed(KeyEvent e) { + System.out.println("Key Pressed "); + } + public void keyReleased(KeyEvent ke) { + System.out.println("keyReleased called "); + } + public void keyTyped(KeyEvent ke) { + System.out.println("keyTyped called "); + } +}// class SetFocusableTest + +class MonitoredFocusListener extends FocusAdapter { + Object monitor; + public MonitoredFocusListener(Object monitor) { + this.monitor = monitor; + } + + public void focusGained(FocusEvent fe) { + System.out.println(fe.toString()); + synchronized (monitor) { + monitor.notify(); + } + } +} diff --git a/test/jdk/java/awt/Focus/TemporaryLostComponentDeadlock.java b/test/jdk/java/awt/Focus/TemporaryLostComponentDeadlock.java new file mode 100644 index 00000000000..e14492ecf16 --- /dev/null +++ b/test/jdk/java/awt/Focus/TemporaryLostComponentDeadlock.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2003, 2023, 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 4794413 + * @summary Tests that access to temporaryLostComponent from two different threads doesn't cause a deadlock + * @key headful + * @run main TemporaryLostComponentDeadlock +*/ +import java.awt.Button; +import java.awt.Dialog; +import java.awt.EventQueue; +import java.awt.Frame; + +public class TemporaryLostComponentDeadlock { + static Dialog frame1; + static Frame frame; + + public static void main(String[] args) throws Exception { + EventQueue.invokeAndWait(() -> { + frame = new Frame("frame"); + frame1 = new Dialog(frame, "Frame 1", false); + frame1.add(new Button("focus owner")); + frame1.pack(); + frame1.setLocationRelativeTo(null); + frame1.setVisible(true); + }); + + Thread t1 = new Thread() { + public void run() { + synchronized(frame1) { + frame1.dispose(); + synchronized(frame1) { + frame1.notify(); + } + } + } + }; + try { + synchronized(frame1) { + t1.start(); + frame1.wait(); + } + } catch( InterruptedException ie) { + } finally { + if (frame != null) { + frame.dispose(); + } + } + System.out.println("Test PASSED"); + } + +}// class TemporaryLostComponentDeadlock diff --git a/test/jdk/java/awt/Focus/TraversalKeysPropertyNamesTest.java b/test/jdk/java/awt/Focus/TraversalKeysPropertyNamesTest.java new file mode 100644 index 00000000000..aec724e457d --- /dev/null +++ b/test/jdk/java/awt/Focus/TraversalKeysPropertyNamesTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2001, 2023, 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 4457455 + @summary Component and KeyboardFocusManager use wrong names of the properties + @run main TraversalKeysPropertyNamesTest +*/ + +import java.awt.AWTKeyStroke; +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.EventQueue; +import java.awt.KeyboardFocusManager; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.HashSet; + +public class TraversalKeysPropertyNamesTest implements PropertyChangeListener { + final String[] properties = { + "forwardDefaultFocusTraversalKeys", + "backwardDefaultFocusTraversalKeys", + "upCycleDefaultFocusTraversalKeys", + "downCycleDefaultFocusTraversalKeys", + "forwardFocusTraversalKeys", + "backwardFocusTraversalKeys", + "upCycleFocusTraversalKeys", + "downCycleFocusTraversalKeys" + }; + final int PROPERTIES_COUNT = properties.length; + boolean[] flags = new boolean[PROPERTIES_COUNT]; + + public static void main(String[] args) throws Exception { + TraversalKeysPropertyNamesTest test = new TraversalKeysPropertyNamesTest(); + test.start(); + } + + public void start() throws Exception { + EventQueue.invokeAndWait(() -> { + Container cont = new Container() {}; + HashSet forwardKeys = new HashSet(); + forwardKeys.add(AWTKeyStroke.getAWTKeyStroke("ctrl A")); + HashSet backwardKeys = new HashSet(); + backwardKeys.add(AWTKeyStroke.getAWTKeyStroke("ctrl B")); + HashSet upKeys = new HashSet(); + upKeys.add(AWTKeyStroke.getAWTKeyStroke("ctrl C")); + HashSet downKeys = new HashSet(); + downKeys.add(AWTKeyStroke.getAWTKeyStroke("ctrl D")); + + KeyboardFocusManager manager = + KeyboardFocusManager.getCurrentKeyboardFocusManager(); + manager.addPropertyChangeListener(this); + manager.setDefaultFocusTraversalKeys( + KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys); + manager.setDefaultFocusTraversalKeys( + KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys); + manager.setDefaultFocusTraversalKeys( + KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, downKeys); + manager.setDefaultFocusTraversalKeys( + KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, upKeys); + + cont.addPropertyChangeListener(this); + cont.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys); + cont.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys); + cont.setFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, downKeys); + cont.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, upKeys); + + for (int i = 0; i < PROPERTIES_COUNT; i++) { + if (!flags[i]) { + throw new RuntimeException( + "Notification on "+properties[i]+" change was not received"); + } + } + }); + }// start() + + public void propertyChange(PropertyChangeEvent pce) { + String property = pce.getPropertyName(); + System.err.println(property); + int index; + for (index = 0; index < PROPERTIES_COUNT; index++) { + if (property.equals(properties[index])) { + break; + } + } + + if (index < PROPERTIES_COUNT) { + flags[index] = true; + } + } + }// class TraversalKeysPropertyNamesTest diff --git a/test/jdk/java/awt/Focus/UpFocusCycleTest.java b/test/jdk/java/awt/Focus/UpFocusCycleTest.java new file mode 100644 index 00000000000..2c421ffe822 --- /dev/null +++ b/test/jdk/java/awt/Focus/UpFocusCycleTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2001, 2023, 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 4394789 + @summary KeyboardFocusManager.upFocusCycle is not working for Swing properly + @key headful + @run main UpFocusCycleTest +*/ +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.Color; +import java.awt.DefaultKeyboardFocusManager; +import java.awt.EventQueue; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.Robot; +import javax.swing.DefaultFocusManager; +import javax.swing.JButton; +import javax.swing.JFrame; + +public class UpFocusCycleTest { + static boolean isFailed = true; + static Object sema = new Object(); + static JFrame frame; + + public static void main(String[] args) throws Exception { + try { + Robot robot = new Robot(); + EventQueue.invokeAndWait(() -> { + + frame = new JFrame("Test frame"); + + Container container1 = frame.getContentPane(); + container1.setBackground(Color.yellow); + + JButton button = new JButton("Button"); + button.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent fe) { + DefaultKeyboardFocusManager manager = new DefaultFocusManager(); + manager.upFocusCycle(button); + System.out.println("Button receive focus"); + frame.addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent fe) { + System.out.println("Frame receive focus"); + synchronized (sema) { + isFailed = false; + sema.notifyAll(); + } + } + }); + } + }); + container1.add(button,BorderLayout.WEST); + button.requestFocus(); + frame.setSize(300,300); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + robot.waitForIdle(); + robot.delay(1000); + if (isFailed) { + System.out.println("Test FAILED"); + throw new RuntimeException("Test FAILED"); + } else { + System.out.println("Test PASSED"); + } + } finally { + if (frame != null) { + frame.dispose(); + } + } + } + }// class UpFocusCycleTest diff --git a/test/jdk/java/awt/Focus/VetoableChangeListenerLoopTest.java b/test/jdk/java/awt/Focus/VetoableChangeListenerLoopTest.java new file mode 100644 index 00000000000..b6449b16dbc --- /dev/null +++ b/test/jdk/java/awt/Focus/VetoableChangeListenerLoopTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004, 2023, 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 5074189 + @summary Tests that VetoableChangeListener doesn't initiate infinite loop. + @key headful + @run main VetoableChangeListenerLoopTest +*/ +import java.awt.AWTEvent; +import java.awt.Button; +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.KeyboardFocusManager; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Panel; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.AWTEventListener; +import java.awt.event.FocusEvent; +import java.awt.event.WindowEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; + +public class VetoableChangeListenerLoopTest { + static Button b1; + static Button b2; + static Frame frame; + static Robot robot; + + static int counter = 0; + + public static void main(String[] args) throws Exception { + try { + robot = new Robot(); + EventQueue.invokeAndWait(() -> { + KeyboardFocusManager.getCurrentKeyboardFocusManager(). + addVetoableChangeListener(new VetoableChangeListener () { + public void vetoableChange(PropertyChangeEvent evt) + throws PropertyVetoException { + if (b1.equals(evt.getNewValue())) { + System.out.println("VETOING: " + (counter++)); + if (counter > 2) { + throw new RuntimeException("Test failed!"); + } + throw new PropertyVetoException("Change in property", evt); + } + } + }); + + Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { + public void eventDispatched(AWTEvent e) { + System.out.println(e.toString()); + } + }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK); + + b1 = new Button("Button 1"); + b2 = new Button("Button 2"); + Frame frame = new Frame(); + frame.add(b1); + frame.add(b2); + frame.setSize(200, 100); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + + robot.delay(1000); + test(); + } finally { + if (frame != null) { + frame.dispose(); + } + } + } + + static void test() { + b2.requestFocusInWindow(); + waitTillFocus(b2); + b2.setVisible(false); + } + + + static void waitTillFocus(Component comp) { + while (!checkFocusOwner(comp)) { + robot.delay(100); + } + } + + static boolean checkFocusOwner(Component comp) { + return (comp == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()); + } +} diff --git a/test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java b/test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java index 6691aeba06b..4a45cb2b98e 100644 --- a/test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java +++ b/test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, 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,6 +33,7 @@ * @run main/othervm DTLSOverDatagram */ +import java.io.IOException; import java.nio.*; import java.net.*; import java.util.*; @@ -42,41 +43,41 @@ import jdk.test.lib.security.SSLContextBuilder; import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicBoolean; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; /** * An example to show the way to use SSLEngine in datagram connections. */ public class DTLSOverDatagram { - private static int MAX_HANDSHAKE_LOOPS = 200; - private static int MAX_APP_READ_LOOPS = 60; - private static int SOCKET_TIMEOUT = 10 * 1000; // in millis - private static int BUFFER_SIZE = 1024; - private static int MAXIMUM_PACKET_SIZE = 1024; + private static final int SOCKET_TIMEOUT = 10 * 1000; // in millis + private static final int BUFFER_SIZE = 1024; + private static final int MAXIMUM_PACKET_SIZE = 1024; /* * The following is to set up the keystores. */ - private static String pathToStores = "../etc"; - private static String keyStoreFile = "keystore"; - private static String trustStoreFile = "truststore"; - - private static String keyFilename = - System.getProperty("test.src", ".") + "/" + pathToStores + - "/" + keyStoreFile; - private static String trustFilename = - System.getProperty("test.src", ".") + "/" + pathToStores + - "/" + trustStoreFile; - private static Exception clientException = null; - private static Exception serverException = null; - - private static ByteBuffer serverApp = + private static final String PATH_TO_STORES = "../etc"; + private static final String KEY_STORE_FILE = "keystore"; + private static final String TRUST_STORE_FILE = "truststore"; + + private static final String KEY_FILENAME = + System.getProperty("test.src", ".") + "/" + PATH_TO_STORES + + "/" + KEY_STORE_FILE; + private static final String TRUST_FILENAME = + System.getProperty("test.src", ".") + "/" + PATH_TO_STORES + + "/" + TRUST_STORE_FILE; + + private static final ByteBuffer SERVER_APP = ByteBuffer.wrap("Hi Client, I'm Server".getBytes()); - private static ByteBuffer clientApp = + private static final ByteBuffer CLIENT_APP = ByteBuffer.wrap("Hi Server, I'm Client".getBytes()); + private final AtomicBoolean exceptionOccurred = new AtomicBoolean(false); + + private final CountDownLatch serverStarted = new CountDownLatch(1); /* * ============================================================= * The test case @@ -91,18 +92,19 @@ public static void main(String[] args) throws Exception { */ void doServerSide(DatagramSocket socket, InetSocketAddress clientSocketAddr) throws Exception { + String side = "Server"; // create SSLEngine SSLEngine engine = createSSLEngine(false); // handshaking - handshake(engine, socket, clientSocketAddr, "Server"); + handshake(engine, socket, clientSocketAddr, side); // read client application data - receiveAppData(engine, socket, clientApp); + receiveAppData(engine, socket, CLIENT_APP); // write server application data - deliverAppData(engine, socket, serverApp, clientSocketAddr); + deliverAppData(engine, socket, SERVER_APP, clientSocketAddr, side); } /* @@ -110,18 +112,19 @@ void doServerSide(DatagramSocket socket, InetSocketAddress clientSocketAddr) */ void doClientSide(DatagramSocket socket, InetSocketAddress serverSocketAddr) throws Exception { + String side = "Client"; // create SSLEngine SSLEngine engine = createSSLEngine(true); // handshaking - handshake(engine, socket, serverSocketAddr, "Client"); + handshake(engine, socket, serverSocketAddr, side); // write client application data - deliverAppData(engine, socket, clientApp, serverSocketAddr); + deliverAppData(engine, socket, CLIENT_APP, serverSocketAddr, side); // read server application data - receiveAppData(engine, socket, serverApp); + receiveAppData(engine, socket, SERVER_APP); } /* @@ -146,124 +149,96 @@ void handshake(SSLEngine engine, DatagramSocket socket, SocketAddress peerAddr, String side) throws Exception { boolean endLoops = false; - int loops = MAX_HANDSHAKE_LOOPS; + int loops = 0; engine.beginHandshake(); - while (!endLoops && - (serverException == null) && (clientException == null)) { - - if (--loops < 0) { - throw new RuntimeException( - "Too much loops to produce handshake packets"); - } + while (!endLoops && !exceptionOccurred.get()) { SSLEngineResult.HandshakeStatus hs = engine.getHandshakeStatus(); - log(side, "=======handshake(" + loops + ", " + hs + ")======="); - if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP || - hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN) { - - log(side, "Receive DTLS records, handshake status is " + hs); - - ByteBuffer iNet; - ByteBuffer iApp; - if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) { - byte[] buf = new byte[BUFFER_SIZE]; - DatagramPacket packet = new DatagramPacket(buf, buf.length); - try { - socket.receive(packet); - } catch (SocketTimeoutException ste) { - log(side, "Warning: " + ste); - - List packets = new ArrayList<>(); - boolean finished = onReceiveTimeout( - engine, peerAddr, side, packets); - - log(side, "Reproduced " + packets.size() + " packets"); - for (DatagramPacket p : packets) { - printHex("Reproduced packet", - p.getData(), p.getOffset(), p.getLength()); - socket.send(p); + log(side, "=======handshake(" + ++loops + ", " + hs + ")======="); + + switch (hs) { + case NEED_UNWRAP: + case NEED_UNWRAP_AGAIN: { + log(side, "Receive DTLS records, handshake status is " + hs); + + ByteBuffer iNet; + ByteBuffer iApp; + + if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) { + byte[] buf = new byte[BUFFER_SIZE]; + DatagramPacket packet = new DatagramPacket(buf, buf.length); + try { + socket.receive(packet); + } catch (SocketTimeoutException ste) { + log(side, "Warning: " + ste); + + List packets = new ArrayList<>(); + boolean finished = onReceiveTimeout( + engine, peerAddr, side, packets); + + log(side, "Reproduced " + packets.size() + " packets"); + for (DatagramPacket p : packets) { + printHex("Reproduced packet", + p.getData(), p.getOffset(), p.getLength()); + socket.send(p); + } + + if (finished) { + log(side, "Handshake status is FINISHED " + + "after calling onReceiveTimeout(), " + + "finish the loop"); + endLoops = true; + } + + log(side, "New handshake status is " + + engine.getHandshakeStatus()); + + continue; } - if (finished) { - log(side, "Handshake status is FINISHED " - + "after calling onReceiveTimeout(), " - + "finish the loop"); - endLoops = true; - } - - log(side, "New handshake status is " - + engine.getHandshakeStatus()); - - continue; + iNet = ByteBuffer.wrap(buf, 0, packet.getLength()); + } else { + iNet = ByteBuffer.allocate(0); } - iNet = ByteBuffer.wrap(buf, 0, packet.getLength()); iApp = ByteBuffer.allocate(BUFFER_SIZE); - } else { - iNet = ByteBuffer.allocate(0); - iApp = ByteBuffer.allocate(BUFFER_SIZE); - } - - SSLEngineResult r = engine.unwrap(iNet, iApp); - SSLEngineResult.Status rs = r.getStatus(); - hs = r.getHandshakeStatus(); - if (rs == SSLEngineResult.Status.OK) { - // OK - } else if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) { - log(side, "BUFFER_OVERFLOW, handshake status is " + hs); - // the client maximum fragment size config does not work? - throw new Exception("Buffer overflow: " + - "incorrect client maximum fragment size"); - } else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) { - log(side, "BUFFER_UNDERFLOW, handshake status is " + hs); + SSLEngineResult r = engine.unwrap(iNet, iApp); + hs = r.getHandshakeStatus(); - // bad packet, or the client maximum fragment size - // config does not work? - if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { - throw new Exception("Buffer underflow: " + - "incorrect client maximum fragment size"); - } // otherwise, ignore this packet - } else if (rs == SSLEngineResult.Status.CLOSED) { - throw new Exception( - "SSL engine closed, handshake status is " + hs); - } else { - throw new Exception("Can't reach here, result is " + rs); - } - - if (hs == SSLEngineResult.HandshakeStatus.FINISHED) { - log(side, "Handshake status is FINISHED, finish the loop"); - endLoops = true; - } - } else if (hs == SSLEngineResult.HandshakeStatus.NEED_WRAP) { - List packets = new ArrayList<>(); - boolean finished = produceHandshakePackets( - engine, peerAddr, side, packets); - - log(side, "Produced " + packets.size() + " packets"); - for (DatagramPacket p : packets) { - socket.send(p); - } + verifySSLEngineResultStatus(r, side); + if (hs == SSLEngineResult.HandshakeStatus.FINISHED) { + log(side, "Handshake status is FINISHED, finish the loop"); + endLoops = true; + } + } break; + case NEED_WRAP: { + List packets = new ArrayList<>(); + boolean finished = produceHandshakePackets( + engine, peerAddr, side, packets); + + log(side, "Produced " + packets.size() + " packets"); + for (DatagramPacket p : packets) { + socket.send(p); + } - if (finished) { - log(side, "Handshake status is FINISHED " - + "after producing handshake packets, " - + "finish the loop"); + if (finished) { + log(side, "Handshake status is FINISHED " + + "after producing handshake packets, " + + "finish the loop"); + endLoops = true; + } + } break; + case NEED_TASK: runDelegatedTasks(engine); break; + case NOT_HANDSHAKING: { + log(side, + "Handshake status is NOT_HANDSHAKING, finish the loop"); endLoops = true; - } - } else if (hs == SSLEngineResult.HandshakeStatus.NEED_TASK) { - runDelegatedTasks(engine); - } else if (hs == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { - log(side, - "Handshake status is NOT_HANDSHAKING, finish the loop"); - endLoops = true; - } else if (hs == SSLEngineResult.HandshakeStatus.FINISHED) { - throw new Exception( - "Unexpected status, SSLEngine.getHandshakeStatus() " - + "shouldn't return FINISHED"); - } else { - throw new Exception( - "Can't reach here, handshake status is " + hs); + } break; + case FINISHED: throw new Exception( "Unexpected status, " + + "SSLEngine.getHandshakeStatus() shouldn't return FINISHED"); + default: throw new Exception("Can't reach here, " + + "handshake status is " + hs); } } @@ -291,13 +266,39 @@ void handshake(SSLEngine engine, DatagramSocket socket, } } + void verifySSLEngineResultStatus(SSLEngineResult r, String side) throws Exception { + SSLEngineResult.Status rs = r.getStatus(); + SSLEngineResult.HandshakeStatus hs = r.getHandshakeStatus(); + switch (rs) { + case OK: log(side, "SSLEngineResult status OK"); break; + case BUFFER_OVERFLOW: { + log(side, "BUFFER_OVERFLOW, handshake status is " + hs); + // the client maximum fragment size config does not work? + throw new Exception("Buffer overflow: " + + "incorrect client maximum fragment size"); + } + case BUFFER_UNDERFLOW: { + log(side, "BUFFER_UNDERFLOW, handshake status is " + hs); + // bad packet, or the client maximum fragment size + // config does not work? + if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { + throw new Exception("Buffer underflow: " + + "incorrect client maximum fragment size"); + } // otherwise, ignore this packet + } break; + case CLOSED: throw new Exception( + "SSL engine closed, handshake status is " + hs); + default: throw new Exception("Can't reach here, result is " + rs); + } + } + // deliver application data void deliverAppData(SSLEngine engine, DatagramSocket socket, - ByteBuffer appData, SocketAddress peerAddr) throws Exception { + ByteBuffer appData, SocketAddress peerAddr, String side) throws Exception { // Note: have not consider the packet loses List packets = - produceApplicationPackets(engine, appData, peerAddr); + produceApplicationPackets(engine, appData, peerAddr, side); appData.flip(); for (DatagramPacket p : packets) { socket.send(p); @@ -308,16 +309,10 @@ void deliverAppData(SSLEngine engine, DatagramSocket socket, void receiveAppData(SSLEngine engine, DatagramSocket socket, ByteBuffer expectedApp) throws Exception { - int loops = MAX_APP_READ_LOOPS; - while ((serverException == null) && (clientException == null)) { - if (--loops < 0) { - throw new RuntimeException( - "Too much loops to receive application data"); - } - + while (!exceptionOccurred.get()) { byte[] buf = new byte[BUFFER_SIZE]; - DatagramPacket packet = new DatagramPacket(buf, buf.length); - socket.receive(packet); + DatagramPacket packet = readFromSocket(socket, buf); + ByteBuffer netBuffer = ByteBuffer.wrap(buf, 0, packet.getLength()); ByteBuffer recBuffer = ByteBuffer.allocate(BUFFER_SIZE); SSLEngineResult rs = engine.unwrap(netBuffer, recBuffer); @@ -333,19 +328,31 @@ void receiveAppData(SSLEngine engine, } } + /* + Some tests failed with receive time-out errors when the client tried to read + from the server. The server thread had exited normally so the read _should_ + succeed. So let's try to read a couple of times before giving up. + */ + DatagramPacket readFromSocket(DatagramSocket socket, byte[] buffer) throws IOException { + for (int i = 1 ; i <= 2 ; ++i) { + try { + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + socket.receive(packet); + return packet; + } catch (SocketTimeoutException exc) { + System.out.println("Attempt " + i + ": Timeout occurred reading from socket."); + } + } + throw new IOException("Did not receive data after 2 attempts."); + } + // produce handshake packets boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, String side, List packets) throws Exception { boolean endLoops = false; - int loops = MAX_HANDSHAKE_LOOPS / 2; - while (!endLoops && - (serverException == null) && (clientException == null)) { - - if (--loops < 0) { - throw new RuntimeException( - "Too much loops to produce handshake packets"); - } + int loops = 0; + while (!endLoops && !exceptionOccurred.get()) { ByteBuffer oNet = ByteBuffer.allocate(32768); ByteBuffer oApp = ByteBuffer.allocate(0); @@ -355,31 +362,10 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, SSLEngineResult.Status rs = r.getStatus(); SSLEngineResult.HandshakeStatus hs = r.getHandshakeStatus(); log(side, "----produce handshake packet(" + - loops + ", " + rs + ", " + hs + ")----"); - if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) { - // the client maximum fragment size config does not work? - throw new Exception("Buffer overflow: " + - "incorrect server maximum fragment size"); - } else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) { - log(side, - "Produce handshake packets: BUFFER_UNDERFLOW occured"); - log(side, - "Produce handshake packets: Handshake status: " + hs); - // bad packet, or the client maximum fragment size - // config does not work? - if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { - throw new Exception("Buffer underflow: " + - "incorrect server maximum fragment size"); - } // otherwise, ignore this packet - } else if (rs == SSLEngineResult.Status.CLOSED) { - throw new Exception("SSLEngine has closed"); - } else if (rs == SSLEngineResult.Status.OK) { - // OK - } else { - throw new Exception("Can't reach here, result is " + rs); - } + ++loops + ", " + rs + ", " + hs + ")----"); + + verifySSLEngineResultStatus(r, side); - // SSLEngineResult.Status.OK: if (oNet.hasRemaining()) { byte[] ba = new byte[oNet.remaining()]; oNet.get(ba); @@ -396,24 +382,22 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, boolean endInnerLoop = false; SSLEngineResult.HandshakeStatus nhs = hs; while (!endInnerLoop) { - if (nhs == SSLEngineResult.HandshakeStatus.NEED_TASK) { - runDelegatedTasks(engine); - } else if (nhs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP || - nhs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN || - nhs == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { - - endInnerLoop = true; - endLoops = true; - } else if (nhs == SSLEngineResult.HandshakeStatus.NEED_WRAP) { - endInnerLoop = true; - } else if (nhs == SSLEngineResult.HandshakeStatus.FINISHED) { - throw new Exception( + switch (nhs) { + case NEED_TASK: runDelegatedTasks(engine); break; + case NEED_UNWRAP: + case NEED_UNWRAP_AGAIN: + case NOT_HANDSHAKING: { + endInnerLoop = true; + endLoops = true; + } break; + case NEED_WRAP: endInnerLoop = true; break; + case FINISHED: throw new Exception( "Unexpected status, SSLEngine.getHandshakeStatus() " - + "shouldn't return FINISHED"); - } else { - throw new Exception("Can't reach here, handshake status is " + + "should not return FINISHED"); + default: throw new Exception("Can't reach here, handshake status is " + nhs); } + nhs = engine.getHandshakeStatus(); } } @@ -428,30 +412,15 @@ DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) { // produce application packets List produceApplicationPackets( SSLEngine engine, ByteBuffer source, - SocketAddress socketAddr) throws Exception { + SocketAddress socketAddr, String side) throws Exception { List packets = new ArrayList<>(); ByteBuffer appNet = ByteBuffer.allocate(32768); SSLEngineResult r = engine.wrap(source, appNet); appNet.flip(); - SSLEngineResult.Status rs = r.getStatus(); - if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) { - // the client maximum fragment size config does not work? - throw new Exception("Buffer overflow: " + - "incorrect server maximum fragment size"); - } else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) { - // unlikely - throw new Exception("Buffer underflow during wraping"); - } else if (rs == SSLEngineResult.Status.CLOSED) { - throw new Exception("SSLEngine has closed"); - } else if (rs == SSLEngineResult.Status.OK) { - // OK - } else { - throw new Exception("Can't reach here, result is " + rs); - } + verifySSLEngineResultStatus(r, side); - // SSLEngineResult.Status.OK: if (appNet.hasRemaining()) { byte[] ba = new byte[appNet.remaining()]; appNet.get(ba); @@ -472,7 +441,7 @@ static DatagramPacket getPacket( int offset = packet.getOffset(); int length = packet.getLength(); - // Normally, this pakcet should be a handshake message + // Normally, this packet should be a handshake message // record. However, even if the underlying platform // splits the record more, we don't really worry about // the improper packet loss because DTLS implementation @@ -490,12 +459,12 @@ static DatagramPacket getPacket( if (data[offset + 4] == 0x00) { // plaintext matched = (data[offset + 13] == handshakeType); - } else { // cipherext + } else { // ciphertext // The 1st ciphertext is a Finished message. // // If it is not proposed to loss the Finished // message, it is not necessary to check the - // following packets any mroe as a Finished + // following packets any more as a Finished // message is the last handshake message. matched = (handshakeType == 20); } @@ -540,8 +509,8 @@ boolean onReceiveTimeout(SSLEngine engine, SocketAddress socketAddr, SSLContext getDTLSContext() throws Exception { String passphrase = "passphrase"; return SSLContextBuilder.builder() - .trustStore(KeyStoreUtils.loadKeyStore(trustFilename, passphrase)) - .keyStore(KeyStoreUtils.loadKeyStore(keyFilename, passphrase)) + .trustStore(KeyStoreUtils.loadKeyStore(TRUST_FILENAME, passphrase)) + .keyStore(KeyStoreUtils.loadKeyStore(KEY_FILENAME, passphrase)) .kmfPassphrase(passphrase) .protocol("DTLS") .build(); @@ -553,147 +522,79 @@ SSLContext getDTLSContext() throws Exception { * The remainder is support stuff to kickstart the testing. */ - // Will the handshaking and application data exchange succeed? - public boolean isGoodJob() { - return true; - } public final void runTest(DTLSOverDatagram testCase) throws Exception { - try (DatagramSocket serverSocket = new DatagramSocket(); - DatagramSocket clientSocket = new DatagramSocket()) { + InetSocketAddress serverSocketAddress = new InetSocketAddress + (InetAddress.getLoopbackAddress(), 0); + InetSocketAddress clientSocketAddress = new InetSocketAddress + (InetAddress.getLoopbackAddress(), 0); + + try (DatagramSocket serverSocket = new DatagramSocket(serverSocketAddress); + DatagramSocket clientSocket = new DatagramSocket(clientSocketAddress)) { serverSocket.setSoTimeout(SOCKET_TIMEOUT); clientSocket.setSoTimeout(SOCKET_TIMEOUT); InetSocketAddress serverSocketAddr = new InetSocketAddress( - InetAddress.getLocalHost(), serverSocket.getLocalPort()); + InetAddress.getLoopbackAddress(), serverSocket.getLocalPort()); InetSocketAddress clientSocketAddr = new InetSocketAddress( - InetAddress.getLocalHost(), clientSocket.getLocalPort()); + InetAddress.getLoopbackAddress(), clientSocket.getLocalPort()); - ExecutorService pool = Executors.newFixedThreadPool(2); - Future server, client; + ExecutorService pool = Executors.newFixedThreadPool(1); + Future server; - try { - server = pool.submit(new ServerCallable( + server = pool.submit(() -> runServer( testCase, serverSocket, clientSocketAddr)); - client = pool.submit(new ClientCallable( - testCase, clientSocket, serverSocketAddr)); - } finally { - pool.shutdown(); - } - - boolean failed = false; - - // wait for client to finish - try { - System.out.println("Client finished: " + client.get()); - } catch (CancellationException | InterruptedException - | ExecutionException e) { - System.out.println("Exception on client side: "); - e.printStackTrace(System.out); - failed = true; - } - - // wait for server to finish - try { - System.out.println("Client finished: " + server.get()); - } catch (CancellationException | InterruptedException - | ExecutionException e) { - System.out.println("Exception on server side: "); - e.printStackTrace(System.out); - failed = true; - } + pool.shutdown(); - if (failed) { - throw new RuntimeException("Test failed"); - } + runClient(testCase, clientSocket, serverSocketAddr); + server.get(); } } - final static class ServerCallable implements Callable { - - private final DTLSOverDatagram testCase; - private final DatagramSocket socket; - private final InetSocketAddress clientSocketAddr; + Void runServer(DTLSOverDatagram testCase, DatagramSocket socket, + InetSocketAddress clientSocketAddr) throws Exception { + try { + serverStarted.countDown(); + testCase.doServerSide(socket, clientSocketAddr); - ServerCallable(DTLSOverDatagram testCase, DatagramSocket socket, - InetSocketAddress clientSocketAddr) { + } catch (Exception exc) { + exceptionOccurred.set(true); - this.testCase = testCase; - this.socket = socket; - this.clientSocketAddr = clientSocketAddr; + // log for debugging clarity + System.out.println("Unexpected exception in server"); + exc.printStackTrace(System.err); + throw exc; } - @Override - public String call() throws Exception { - try { - testCase.doServerSide(socket, clientSocketAddr); - } catch (Exception e) { - System.out.println("Exception in ServerCallable.call():"); - e.printStackTrace(System.out); - serverException = e; - - if (testCase.isGoodJob()) { - throw e; - } else { - return "Well done, server!"; - } - } - - if (testCase.isGoodJob()) { - return "Well done, server!"; - } else { - throw new Exception("No expected exception"); - } - } + return null; } - final static class ClientCallable implements Callable { - - private final DTLSOverDatagram testCase; - private final DatagramSocket socket; - private final InetSocketAddress serverSocketAddr; - - ClientCallable(DTLSOverDatagram testCase, DatagramSocket socket, - InetSocketAddress serverSocketAddr) { - - this.testCase = testCase; - this.socket = socket; - this.serverSocketAddr = serverSocketAddr; + private void runClient(DTLSOverDatagram testCase, DatagramSocket socket, + InetSocketAddress serverSocketAddr) throws Exception { + if(!serverStarted.await(5, TimeUnit.SECONDS)) { + throw new Exception("Server did not start within 5 seconds."); } - @Override - public String call() throws Exception { - try { - testCase.doClientSide(socket, serverSocketAddr); - } catch (Exception e) { - System.out.println("Exception in ClientCallable.call():"); - e.printStackTrace(System.out); - clientException = e; - - if (testCase.isGoodJob()) { - throw e; - } else { - return "Well done, client!"; - } - } + try { + testCase.doClientSide(socket, serverSocketAddr); + } catch (Exception exc) { + exceptionOccurred.set(true); - if (testCase.isGoodJob()) { - return "Well done, client!"; - } else { - throw new Exception("No expected exception"); - } + // log for debugging clarity + System.out.println("Unexpected exception in client."); + exc.printStackTrace(System.err); + throw exc; } } - final static void printHex(String prefix, ByteBuffer bb) { - HexDumpEncoder dump = new HexDumpEncoder(); + static void printHex(String prefix, ByteBuffer bb) { synchronized (System.out) { System.out.println(prefix); try { - dump.encodeBuffer(bb.slice(), System.out); + HexPrinter.simple().format(bb.slice()); } catch (Exception e) { // ignore } @@ -701,16 +602,13 @@ final static void printHex(String prefix, ByteBuffer bb) { } } - final static void printHex(String prefix, + static void printHex(String prefix, byte[] bytes, int offset, int length) { - HexDumpEncoder dump = new HexDumpEncoder(); - synchronized (System.out) { System.out.println(prefix); try { - ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length); - dump.encodeBuffer(bb, System.out); + HexPrinter.simple().format(bytes, offset, length); } catch (Exception e) { // ignore } diff --git a/test/jdk/javax/net/ssl/DTLS/InvalidRecords.java b/test/jdk/javax/net/ssl/DTLS/InvalidRecords.java index af5bdc36134..304cb0695d6 100644 --- a/test/jdk/javax/net/ssl/DTLS/InvalidRecords.java +++ b/test/jdk/javax/net/ssl/DTLS/InvalidRecords.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, 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 @@ -36,27 +36,32 @@ import java.net.DatagramPacket; import java.net.SocketAddress; +import java.util.concurrent.atomic.AtomicBoolean; /** - * Test that if handshake messages are crasged, the handshake would fail + * Test that if handshake messages are changed, the handshake would fail * because of handshaking hash verification. */ public class InvalidRecords extends DTLSOverDatagram { - boolean needInvalidRecords = true; + private static final AtomicBoolean needInvalidRecords = new AtomicBoolean(true); public static void main(String[] args) throws Exception { InvalidRecords testCase = new InvalidRecords(); testCase.runTest(testCase); - } - @Override - public boolean isGoodJob() { - return false; + if (needInvalidRecords.get()) { + // if this is true, the createHandshakePacket() method + // was NOT called twice to create ClientHello messages + throw new RuntimeException( + "The invalid handshake packet was not" + + " rejected as it should have been."); + } } + @Override DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) { - if ((ba.length >= 60) && + if (needInvalidRecords.get() && (ba.length >= 60) && (ba[0x00] == (byte)0x16) && (ba[0x0D] == (byte)0x01) && (ba[0x3B] == (byte)0x00) && (ba[0x3C] > 0)) { @@ -65,18 +70,8 @@ DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) { // ba[0x3B]: length of session ID // ba[0x3C]: length of cookie - if (!needInvalidRecords) { - // The 2nd ClientHello with cookie. The 1st one should be - // rejected as expected. - // - // This may happen if the last few bytes of the packet are - // for supported_version extension. - throw new RuntimeException( - "the crashed handshake message was rejected as expected"); - } - // ClientHello with cookie - needInvalidRecords = false; + needInvalidRecords.set(false); System.out.println("invalidate ClientHello message"); if (ba[ba.length - 1] == (byte)0xFF) { ba[ba.length - 1] = (byte)0xFE; diff --git a/test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java b/test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java index e0b94363913..f0b245d3279 100644 --- a/test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java +++ b/test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -84,7 +84,7 @@ public class PacketLossRetransmission extends DTLSOverDatagram { public static void main(String[] args) throws Exception { isClient = args[0].equals("client"); - handshakeType = Byte.valueOf(args[1]); + handshakeType = Byte.parseByte(args[1]); PacketLossRetransmission testCase = new PacketLossRetransmission(); testCase.runTest(testCase); @@ -97,7 +97,7 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, boolean finished = super.produceHandshakePackets( engine, socketAddr, side, packets); - if (needPacketLoss && (!(isClient ^ engine.getUseClientMode()))) { + if (needPacketLoss && (isClient == engine.getUseClientMode())) { DatagramPacket packet = getPacket(packets, handshakeType); if (packet != null) { needPacketLoss = false; diff --git a/test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.java b/test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.java index d61d4d9623e..72b7715805e 100644 --- a/test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.java +++ b/test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2021, 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 @@ -85,7 +85,7 @@ public class RespondToRetransmit extends DTLSOverDatagram { public static void main(String[] args) throws Exception { isClient = args[0].equals("client"); - handshakeType = Byte.valueOf(args[1]); + handshakeType = Byte.parseByte(args[1]); RespondToRetransmit testCase = new RespondToRetransmit(); testCase.runTest(testCase); @@ -98,7 +98,7 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, boolean finished = super.produceHandshakePackets( engine, socketAddr, side, packets); - if (needPacketDuplicate && (!(isClient ^ engine.getUseClientMode()))) { + if (needPacketDuplicate && (isClient == engine.getUseClientMode())) { DatagramPacket packet = getPacket(packets, handshakeType); if (packet != null) { needPacketDuplicate = false; diff --git a/test/jdk/javax/net/ssl/TLS/TestJSSE.java b/test/jdk/javax/net/ssl/TLS/TestJSSE.java index 2c5a2c6274d..29631064011 100644 --- a/test/jdk/javax/net/ssl/TLS/TestJSSE.java +++ b/test/jdk/javax/net/ssl/TLS/TestJSSE.java @@ -21,12 +21,13 @@ * questions. */ +import java.net.InetAddress; import java.security.Provider; import java.security.Security; public class TestJSSE { - private static final String LOCAL_IP = "127.0.0.1"; + private static final String LOCAL_IP = InetAddress.getLoopbackAddress().getHostAddress(); public static void main(String... args) throws Exception { // reset the security property to make sure that the algorithms diff --git a/test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java b/test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java index 69778aa0045..ca5742f37b2 100644 --- a/test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java +++ b/test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -30,13 +30,15 @@ * @test * @bug 8215790 8219389 * @summary Verify exception + * @library /test/lib * @modules java.base/sun.security.util * @run main/othervm ClientHelloBufferUnderflowException */ -import sun.security.util.HexDumpEncoder; import javax.net.ssl.SSLHandshakeException; +import jdk.test.lib.hexdump.HexPrinter; + public class ClientHelloBufferUnderflowException extends ClientHelloInterOp { /* * Main entry point for this test. @@ -75,7 +77,7 @@ protected byte[] createClientHelloMessage() { System.out.println("The ClientHello message used"); try { - (new HexDumpEncoder()).encodeBuffer(bytes, System.out); + HexPrinter.simple().format(bytes); } catch (Exception e) { // ignore } diff --git a/test/jdk/javax/net/ssl/interop/ClientHelloChromeInterOp.java b/test/jdk/javax/net/ssl/interop/ClientHelloChromeInterOp.java index 1157b6aeafc..f426cce33e3 100644 --- a/test/jdk/javax/net/ssl/interop/ClientHelloChromeInterOp.java +++ b/test/jdk/javax/net/ssl/interop/ClientHelloChromeInterOp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2020, 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 @@ -30,13 +30,15 @@ * @test * @bug 8169362 * @summary Interop automated testing with Chrome + * @library /test/lib * @modules jdk.crypto.ec * java.base/sun.security.util * @run main/othervm ClientHelloChromeInterOp */ import java.util.Base64; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; + public class ClientHelloChromeInterOp extends ClientHelloInterOp { // The ClientHello message. @@ -63,10 +65,9 @@ protected byte[] createClientHelloMessage() { // Dump the hex codes of the ClientHello message so that developers // can easily check whether the message is captured correct or not. - HexDumpEncoder dump = new HexDumpEncoder(); System.out.println("The ClientHello message used"); try { - dump.encodeBuffer(bytes, System.out); + HexPrinter.simple().format(bytes); } catch (Exception e) { // ignore } diff --git a/test/jdk/javax/net/ssl/sanity/interop/JSSEClient.java b/test/jdk/javax/net/ssl/sanity/interop/JSSEClient.java index 2207749302d..21416f0aaef 100644 --- a/test/jdk/javax/net/ssl/sanity/interop/JSSEClient.java +++ b/test/jdk/javax/net/ssl/sanity/interop/JSSEClient.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.security.cert.Certificate; import javax.net.ssl.KeyManager; @@ -52,7 +53,8 @@ void runTest(CipherTest.TestParameters params) throws Exception { new TrustManager[] { CipherTest.trustManager }, CipherTest.secureRandom); SSLSocketFactory factory = (SSLSocketFactory)sslContext.getSocketFactory(); - socket = (SSLSocket)factory.createSocket("127.0.0.1", CipherTest.serverPort); + socket = (SSLSocket)factory.createSocket( + InetAddress.getLoopbackAddress().getHostAddress(), CipherTest.serverPort); socket.setSoTimeout(CipherTest.TIMEOUT); socket.setEnabledCipherSuites(new String[] { params.cipherSuite.name() }); socket.setEnabledProtocols(new String[] { params.protocol.name }); diff --git a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java new file mode 100644 index 00000000000..6e0a25a69d0 --- /dev/null +++ b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java @@ -0,0 +1,84 @@ +/* + * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.EventQueue; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.net.URL; +import java.net.URLClassLoader; + +import javax.print.DocFlavor; +import javax.print.PrintServiceLookup; + +/** + * @test + * @bug 8273831 + * @summary Tests custom class loader cleanup + */ +public final class FlushCustomClassLoader { + + public static void main(String[] args) throws Exception { + Reference loader = getLoader("testMethod"); + + int attempt = 0; + while (loader.get() != null) { + if (++attempt > 10) { + throw new RuntimeException("Too many attempts: " + attempt); + } + System.gc(); + Thread.sleep(1000); + System.out.println("Not freed, attempt: " + attempt); + } + } + + public static void testMethod() { + DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; + PrintServiceLookup.lookupPrintServices(flavor, null); + } + + private static Reference getLoader(String m) throws Exception { + /* + * The print services are stored per the AppContext, and each AppContext + * caches the "current" class loader during creation. + * see javax.print.PrintServiceLookup. + * + * To prevent AppContext from cache our test loader we force AppContext + * creation early by the invokeAndWait. + * The "EventQueue.invokeAndWait(() -> {});" can be removed when the + * AppContext usage will be deleted in the PrintServiceLookup + */ + EventQueue.invokeAndWait(() -> {}); + + URL url = FlushCustomClassLoader.class.getProtectionDomain() + .getCodeSource().getLocation(); + URLClassLoader loader = new URLClassLoader(new URL[]{url}, null); + + Thread ct = Thread.currentThread(); + ct.setContextClassLoader(loader); + Class cls = Class.forName("FlushCustomClassLoader", true, loader); + cls.getDeclaredMethod(m).invoke(null); + ct.setContextClassLoader(null); + loader.close(); + return new WeakReference<>(loader); + } +} diff --git a/test/jdk/javax/swing/Action/bug4186951.java b/test/jdk/javax/swing/Action/bug4186951.java new file mode 100644 index 00000000000..3d3529f9470 --- /dev/null +++ b/test/jdk/javax/swing/Action/bug4186951.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1999, 2023, 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 4186951 + @summary Bulletproofing for AbstractAction.ArrayTable Serialization. + @run main bug4186951 +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.SwingUtilities; + +public class bug4186951 { + public static void main(String[] args) throws Exception { + AbstractAction ma = new MyAction(); + MyClassSer mcs = new MyClassSer(); + ma.putValue("serializable",mcs); + MyClassNonSer mcn = new MyClassNonSer(); + ma.putValue("non-serializable",mcn); + FileOutputStream fos = new FileOutputStream("file.test"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(ma); + FileInputStream fis = new FileInputStream("file.test"); + ObjectInputStream ois = new ObjectInputStream(fis); + ma = (MyAction)ois.readObject(); + File fil = new File("file.test"); + if (fil!=null) { + fil.delete(); + } + if (!((MyClassSer)ma.getValue("serializable")).equals(mcs)) { + throw new RuntimeException("Serialisable class " + + " wasn't serialized..."); + } + if ((MyClassNonSer)ma.getValue("non-serializable") != null) { + throw new RuntimeException("Serialisation occurs for " + + " non-serialisable class..."); + } + } + + static class MyAction extends AbstractAction { + public void actionPerformed(ActionEvent e) {} + } + + static class MyClassSer implements Serializable { + String str = "default_string"; + public boolean equals(MyClassSer s) { + return str.equals(s.str); + } + } + + static class MyClassNonSer { + String str = "default_string"; + } + +} diff --git a/test/jdk/javax/swing/Action/bug4211425.java b/test/jdk/javax/swing/Action/bug4211425.java new file mode 100644 index 00000000000..8046ab0a81c --- /dev/null +++ b/test/jdk/javax/swing/Action/bug4211425.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1999, 2023, 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 4211425 + @summary Verifies ClassCastException in AbstractAction + @run main bug4211425 +*/ + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; + +public class bug4211425 { + + public static void main(String[] args) { + AbstractAction at = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + System.out.println("Action!"); + } + }; + for (int i = 0; i < 10; i++) { + at.putValue("key " + i, "name"); + at.putValue("key " + i, "name"); // Adding another with same key + // tickles this bug + } + } +} diff --git a/test/jdk/javax/swing/Action/bug4211454.java b/test/jdk/javax/swing/Action/bug4211454.java new file mode 100644 index 00000000000..9db82ba0602 --- /dev/null +++ b/test/jdk/javax/swing/Action/bug4211454.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1999, 2023, 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 4211454 + @summary Verifies ClassCastException in AbstractAction + @run main bug4211454 +*/ + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; + +public class bug4211454 { + + public static void main(String[] args) { + AbstractAction at = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + System.out.println("Action!"); + } + }; + for (int i = 0; i<9; i++) { + at.putValue("key " + i, "name"); + } + for (int i = 9; i>3; i--) { + at.putValue("key " + i, null); + at.putValue("Not a key " + i, null); + } + } +} diff --git a/test/jdk/javax/swing/Action/bug4244034.java b/test/jdk/javax/swing/Action/bug4244034.java new file mode 100644 index 00000000000..9efb11c8204 --- /dev/null +++ b/test/jdk/javax/swing/Action/bug4244034.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1999, 2023, 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 4244034 + @summary Tests that AbstractAction has method getKeys() + @run main bug4244034 +*/ + +import java.util.Arrays; +import java.util.List; +import java.awt.event.ActionEvent; +import javax.swing.Action; +import javax.swing.AbstractAction; + +public class bug4244034 { + + /** Auxilliary class extending AbstractAction + */ + static class NullAction extends AbstractAction { + public void actionPerformed(ActionEvent e) {} + } + + public static void main(String[] args) { + AbstractAction action = new NullAction(); + action.putValue(Action.SHORT_DESCRIPTION, "my short descr"); + action.putValue(Action.LONG_DESCRIPTION, "my long descr"); + action.putValue(Action.NAME, "my name"); + + Object[] keys = action.getKeys(); + List keysList = Arrays.asList(keys); + if (! keysList.contains(Action.SHORT_DESCRIPTION) || + ! keysList.contains(Action.LONG_DESCRIPTION) || + ! keysList.contains(Action.NAME)) { + + throw new Error("Failed: getKeys() works improperly"); + } + } +} diff --git a/test/jdk/javax/swing/event/bug4143690.java b/test/jdk/javax/swing/event/bug4143690.java new file mode 100644 index 00000000000..971d1984656 --- /dev/null +++ b/test/jdk/javax/swing/event/bug4143690.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1999, 2023, 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 4143690 + @summary Tests that TreeSelectionEvent has isAddedPath(int) method + @run main bug4143690 +*/ + +import javax.swing.event.TreeSelectionEvent; +import javax.swing.tree.TreePath; + +public class bug4143690 { + + public static void main(String[] argv) throws Exception { + bug4143690 test = new bug4143690(); + TreePath p = new TreePath(""); + TreeSelectionEvent e = new TreeSelectionEvent(test, p, true, p, p); + + TreePath[] paths = e.getPaths(); + for(int i = 0; i < paths.length; i++) { + TreePath path = paths[i]; + if (e.isAddedPath(i) != true) { + throw new RuntimeException("Incorrect isAddedPath(int)..."); + } + } + } +} diff --git a/test/jdk/javax/swing/event/bug4160240.java b/test/jdk/javax/swing/event/bug4160240.java new file mode 100644 index 00000000000..4a3654271dc --- /dev/null +++ b/test/jdk/javax/swing/event/bug4160240.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999, 2023, 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 4160240 + @summary InternalFrameEvent has getInternalFrame() method. + @run main bug4160240 +*/ + +import javax.swing.JInternalFrame; +import javax.swing.event.InternalFrameEvent; + +public class bug4160240 { + + public static void main(String[] argv) throws Exception { + JInternalFrame jif = new JInternalFrame(); + InternalFrameEvent ife = new InternalFrameEvent(jif, + InternalFrameEvent.INTERNAL_FRAME_OPENED); + if (ife.getInternalFrame() != jif) { + throw new RuntimeException("JInternalFrame.getInternalFrame " + + " doesn't work correctly..."); + } + } +} diff --git a/test/jdk/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java b/test/jdk/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java index 22e055fbe8e..97ed058ff5a 100644 --- a/test/jdk/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java +++ b/test/jdk/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /** * @test - * @bug 6476665 7033534 6830714 8052162 8196572 + * @bug 6476665 7033534 6830714 8052162 8196572 8326661 * @summary Verifies color conversion of Component Color Model based images * @run main ColConvCCMTest */ @@ -59,8 +59,8 @@ public class ColConvCCMTest extends ColConvTest { 2.5, // sRGB (isOpenProfile() ? 45.0 : 10.1), // LINEAR_RGB 10.5, // GRAY - (isOpenProfile() ? 215.0 : 45.5), // PYCC - (isOpenProfile() ? 56.0 : 47.5) // CIEXYZ + (isOpenProfile() ? 215.0 : 64.5), // PYCC + (isOpenProfile() ? 56.0 : 55.5) // CIEXYZ }; final static String [] gldImgNames = { diff --git a/test/jdk/sun/security/krb5/auto/MSOID2.java b/test/jdk/sun/security/krb5/auto/MSOID2.java index 3a3b3cf6c26..0b7545ffbe2 100644 --- a/test/jdk/sun/security/krb5/auto/MSOID2.java +++ b/test/jdk/sun/security/krb5/auto/MSOID2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, 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 @@ -32,7 +32,7 @@ */ import sun.security.jgss.GSSUtil; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; // The basic krb5 test skeleton you can copy from public class MSOID2 { @@ -72,7 +72,7 @@ public static void main(String[] args) throws Exception { nt[pos] = (byte)newLen; } t = nt; - new HexDumpEncoder().encodeBuffer(t, System.out); + HexPrinter.simple().format(t); } if (t != null || !s.x().isEstablished()) t = s.take(t); if (c.x().isEstablished() && s.x().isEstablished()) break; diff --git a/test/jdk/sun/security/krb5/etype/KerberosAesSha2.java b/test/jdk/sun/security/krb5/etype/KerberosAesSha2.java index 79c8053bf0a..c738e063e02 100644 --- a/test/jdk/sun/security/krb5/etype/KerberosAesSha2.java +++ b/test/jdk/sun/security/krb5/etype/KerberosAesSha2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,7 @@ /* * @test * @bug 8014628 + * @library /test/lib * @modules java.base/sun.security.util * java.security.jgss/sun.security.krb5.internal.crypto.dk:+open * @summary https://tools.ietf.org/html/rfc8009 Test Vectors @@ -33,7 +34,7 @@ import java.util.Arrays; import sun.security.krb5.internal.crypto.dk.AesSha2DkCrypto; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; public class KerberosAesSha2 { @@ -204,6 +205,6 @@ private static void check(byte[] b1, byte[] b2) throws Exception { } private static void dump(byte[] data) throws Exception { - new HexDumpEncoder().encodeBuffer(data, System.err); + HexPrinter.simple().dest(System.err).format(data); } } diff --git a/test/jdk/sun/security/mscapi/PublicKeyInterop.java b/test/jdk/sun/security/mscapi/PublicKeyInterop.java index 85da7e041b1..f3b646bc372 100644 --- a/test/jdk/sun/security/mscapi/PublicKeyInterop.java +++ b/test/jdk/sun/security/mscapi/PublicKeyInterop.java @@ -35,7 +35,7 @@ import javax.crypto.*; import jdk.test.lib.SecurityTools; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; /* * Confirm interoperability of RSA public keys between SunMSCAPI and SunJCE @@ -84,29 +84,29 @@ static void run() throws Exception { System.out.println(); byte[] plain = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05}; - HexDumpEncoder hde = new HexDumpEncoder(); - System.out.println("Plaintext:\n" + hde.encode(plain) + "\n"); + HexPrinter hp = HexPrinter.simple(); + System.out.println("Plaintext:\n" + hp.toString(plain) + "\n"); Cipher rsa = Cipher.getInstance("RSA/ECB/PKCS1Padding"); rsa.init(Cipher.ENCRYPT_MODE, myPuKey); byte[] encrypted = rsa.doFinal(plain); System.out.println("Encrypted plaintext using RSA Cipher from " + rsa.getProvider().getName() + " JCE provider\n"); - System.out.println(hde.encode(encrypted) + "\n"); + System.out.println(hp.toString(encrypted) + "\n"); Cipher rsa2 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI"); rsa2.init(Cipher.ENCRYPT_MODE, myPuKey); byte[] encrypted2 = rsa2.doFinal(plain); System.out.println("Encrypted plaintext using RSA Cipher from " + rsa2.getProvider().getName() + " JCE provider\n"); - System.out.println(hde.encode(encrypted2) + "\n"); + System.out.println(hp.toString(encrypted2) + "\n"); Cipher rsa3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunMSCAPI"); rsa3.init(Cipher.DECRYPT_MODE, myPrKey); byte[] decrypted = rsa3.doFinal(encrypted); System.out.println("Decrypted first ciphertext using RSA Cipher from " + rsa3.getProvider().getName() + " JCE provider\n"); - System.out.println(hde.encode(decrypted) + "\n"); + System.out.println(hp.toString(decrypted) + "\n"); if (! Arrays.equals(plain, decrypted)) { throw new Exception("First decrypted ciphertext does not match " + "original plaintext"); @@ -115,7 +115,7 @@ static void run() throws Exception { decrypted = rsa3.doFinal(encrypted2); System.out.println("Decrypted second ciphertext using RSA Cipher from " + rsa3.getProvider().getName() + " JCE provider\n"); - System.out.println(hde.encode(decrypted) + "\n"); + System.out.println(hp.toString(decrypted) + "\n"); if (! Arrays.equals(plain, decrypted)) { throw new Exception("Second decrypted ciphertext does not match " + "original plaintext"); diff --git a/test/jdk/sun/security/pkcs/pkcs7/SignerOrder.java b/test/jdk/sun/security/pkcs/pkcs7/SignerOrder.java index ef247d5906a..875ca5935e4 100644 --- a/test/jdk/sun/security/pkcs/pkcs7/SignerOrder.java +++ b/test/jdk/sun/security/pkcs/pkcs7/SignerOrder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @test * @bug 8048357 * @summary test PKCS7 data signing, encoding and verification + * @library /test/lib * @modules java.base/sun.security.pkcs * java.base/sun.security.util * java.base/sun.security.x509 @@ -40,7 +41,6 @@ import java.security.SignatureException; import java.security.cert.X509Certificate; import java.util.Date; -import sun.security.util.HexDumpEncoder; import sun.security.pkcs.ContentInfo; import sun.security.pkcs.PKCS7; import sun.security.pkcs.SignerInfo; @@ -55,11 +55,10 @@ import sun.security.x509.X509CertImpl; import sun.security.x509.X509CertInfo; import sun.security.x509.X509Key; +import jdk.test.lib.hexdump.HexPrinter; public class SignerOrder { - static final HexDumpEncoder hexDump = new HexDumpEncoder(); - //signer infos static final byte[] data1 = "12345".getBytes(); static final byte[] data2 = "abcde".getBytes(); @@ -120,7 +119,7 @@ static void printSignerInfos(SignerInfo signerInfo) throws IOException { signerInfo.derEncode(strm); System.out.println("SignerInfo, length: " + strm.toByteArray().length); - System.out.println(hexDump.encode(strm.toByteArray())); + HexPrinter.simple().format(strm.toByteArray()); System.out.println("\n"); strm.reset(); } @@ -131,7 +130,7 @@ static void printSignerInfos(SignerInfo[] signerInfos) throws IOException { signerInfos[i].derEncode(strm); System.out.println("SignerInfo[" + i + "], length: " + strm.toByteArray().length); - System.out.println(hexDump.encode(strm.toByteArray())); + HexPrinter.simple().format(strm.toByteArray()); System.out.println("\n"); strm.reset(); } diff --git a/test/jdk/sun/security/pkcs/pkcs8/PKCS8Test.java b/test/jdk/sun/security/pkcs/pkcs8/PKCS8Test.java index 1bd9f0e54e1..f0555ce59db 100644 --- a/test/jdk/sun/security/pkcs/pkcs8/PKCS8Test.java +++ b/test/jdk/sun/security/pkcs/pkcs8/PKCS8Test.java @@ -25,6 +25,7 @@ * @test * @bug 8048357 * @summary PKCS8 Standards Conformance Tests + * @library /test/lib * @requires (os.family != "solaris") * @modules java.base/sun.security.pkcs * java.base/sun.security.util @@ -42,18 +43,16 @@ import java.math.BigInteger; import java.security.InvalidKeyException; import java.util.Arrays; -import sun.security.util.HexDumpEncoder; import sun.security.pkcs.PKCS8Key; import sun.security.provider.DSAPrivateKey; import sun.security.util.DerOutputStream; import sun.security.util.DerValue; import sun.security.x509.AlgorithmId; +import jdk.test.lib.hexdump.HexPrinter; import static java.lang.System.out; public class PKCS8Test { - static final HexDumpEncoder hexDump = new HexDumpEncoder(); - static final DerOutputStream derOutput = new DerOutputStream(); static final String FORMAT = "PKCS#8"; @@ -281,6 +280,6 @@ public static void main(String[] args) static void dumpByteArray(String nm, byte[] bytes) throws IOException { out.println(nm + " length: " + bytes.length); - hexDump.encodeBuffer(bytes, out); + HexPrinter.simple().dest(out).format(bytes); } } diff --git a/test/jdk/sun/security/pkcs/pkcs9/UnknownAttribute.java b/test/jdk/sun/security/pkcs/pkcs9/UnknownAttribute.java index dbac0ca772f..333550d2ace 100644 --- a/test/jdk/sun/security/pkcs/pkcs9/UnknownAttribute.java +++ b/test/jdk/sun/security/pkcs/pkcs9/UnknownAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @test * @bug 8011867 8242151 * @summary Accept unknown PKCS #9 attributes + * @library /test/lib * @modules java.base/sun.security.pkcs * java.base/sun.security.util */ @@ -32,10 +33,10 @@ import java.io.*; import java.util.Arrays; -import sun.security.util.HexDumpEncoder; import sun.security.pkcs.PKCS9Attribute; import sun.security.util.DerValue; import sun.security.util.ObjectIdentifier; +import jdk.test.lib.hexdump.HexPrinter; public class UnknownAttribute { @@ -58,7 +59,7 @@ public static void main(String[] args) throws Exception { } ByteArrayOutputStream bout = new ByteArrayOutputStream(); p2.derEncode(bout); - new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err); + HexPrinter.simple().dest(System.err).format(bout.toByteArray()); if (!Arrays.equals(data, bout.toByteArray())) { throw new Exception(); } diff --git a/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketKeyLimit.java b/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketKeyLimit.java index f87effe9dce..8b19d39af7e 100644 --- a/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketKeyLimit.java +++ b/test/jdk/sun/security/ssl/SSLSocketImpl/SSLSocketKeyLimit.java @@ -69,7 +69,7 @@ import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; import jdk.test.lib.Utils; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; public class SSLSocketKeyLimit { SSLSocket socket; @@ -227,7 +227,7 @@ void read(SSLSocket s) throws Exception { continue; } System.out.println("\nData invalid: " + - new HexDumpEncoder().encode(buf)); + HexPrinter.minimal().toString(buf)); break; } diff --git a/test/jdk/sun/security/x509/X500Name/NullX500Name.java b/test/jdk/sun/security/x509/X500Name/NullX500Name.java index fe0b1d3874c..37e12d8a892 100644 --- a/test/jdk/sun/security/x509/X500Name/NullX500Name.java +++ b/test/jdk/sun/security/x509/X500Name/NullX500Name.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,6 +24,7 @@ /* @test * @bug 4118818 * @summary allow null X.500 Names + * @library /test/lib * @modules java.base/sun.security.util * java.base/sun.security.x509 */ @@ -31,7 +32,7 @@ import java.util.Arrays; import sun.security.util.DerOutputStream; import sun.security.x509.*; -import sun.security.util.HexDumpEncoder; +import jdk.test.lib.hexdump.HexPrinter; public class NullX500Name { @@ -63,16 +64,16 @@ public static void main(String[] argv) throws Exception { subject.encode(dos); byte[] out = dos.toByteArray(); byte[] enc = subject.getEncoded(); - HexDumpEncoder e = new HexDumpEncoder(); + HexPrinter e = HexPrinter.simple(); if (Arrays.equals(out, enc)) - System.out.println("Sucess: out:" + e.encodeBuffer(out)); + System.out.println("Success: out:" + e.toString(out)); else { - System.out.println("Failed: encode:" + e.encodeBuffer(out)); - System.out.println("getEncoded:" + e.encodeBuffer(enc)); + System.out.println("Failed: encode:" + e.toString(out)); + System.out.println("getEncoded:" + e.toString(enc)); } X500Name x = new X500Name(enc); if (x.equals(subject)) - System.out.println("Sucess: X500Name(byte[]):" + x.toString()); + System.out.println("Success: X500Name(byte[]):" + x.toString()); else System.out.println("Failed: X500Name(byte[]):" + x.toString()); } diff --git a/test/lib-test/TEST.ROOT b/test/lib-test/TEST.ROOT new file mode 100644 index 00000000000..51dfcb33c4f --- /dev/null +++ b/test/lib-test/TEST.ROOT @@ -0,0 +1,9 @@ +# This file identifies the root of the test-suite hierarchy. +# It also contains test-suite configuration information. + +# Minimum jtreg version +requiredVersion=7.3.1+1 + +# Path to libraries in the topmost test directory. This is needed so @library +# does not need ../../ notation to reach them +external.lib.roots = ../../ diff --git a/test/lib-test/jdk/test/lib/hexdump/HexPrinterTest.java b/test/lib-test/jdk/test/lib/hexdump/HexPrinterTest.java new file mode 100644 index 00000000000..bad85a1e624 --- /dev/null +++ b/test/lib-test/jdk/test/lib/hexdump/HexPrinterTest.java @@ -0,0 +1,409 @@ +/* + * Copyright (c) 2019, 2020, 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. + */ + +package jdk.test.lib.hexdump; + +import jdk.test.lib.hexdump.HexPrinter; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + + +/* + * @test + * @summary Check HexPrinter formatting + * @library /test/lib + * @compile HexPrinterTest.java + * @run testng jdk.test.lib.hexdump.HexPrinterTest + */ +public class HexPrinterTest { + + @Test + static void testMinimalToStringByteArray() { + int len = 16; + byte[] bytes = genData(len); + StringBuilder expected = new StringBuilder(bytes.length * 2); + for (int i = 0; i < len; i++) + expected.append(String.format("%02x", bytes[i])); + String actual = HexPrinter.minimal().toString(bytes); + System.out.println(actual); + Assert.assertEquals(actual, expected.toString(), "Minimal format incorrect"); + } + + @DataProvider(name = "ColumnParams") + Object[][] columnParams() { + return new Object[][]{ + {"%4d: ", "%d ", 10, " ; ", 50, HexPrinter.Formatters.PRINTABLE, "\n"}, + {"%03o: ", "%d ", 16, " ; ", 50, HexPrinter.Formatters.ofPrimitive(byte.class, ""), "\n"}, + {"%5d: ", "%02x:", 16, " ; ", 50, HexPrinter.Formatters.ofPrimitive(byte.class, ""), "\n"}, + {"%5d: ", "%3d", 16, " ; ", 50, HexPrinter.Formatters.ofPrimitive(byte.class, ""), "\n"}, + {"%05o: ", "%3o", 8, " ; ", 50, HexPrinter.Formatters.ofPrimitive(byte.class, ""), "\n"}, + {"%6x: ", "%02x", 8, " | ", 50, HexPrinter.Formatters.ofPrimitive(byte.class, "%d "), "\n"}, + {"%2x: ", "%02x", 8, " | ", 50, HexPrinter.Formatters.PRINTABLE, "\n"}, + {"%5d: ", "%02x", 16, " | ", 50, HexPrinter.Formatters.ofPrimitive(short.class, "%d "), "\n"}, + }; + } + + @DataProvider(name = "BuiltinParams") + Object[][] builtinParams() { + return new Object[][]{ + {"minimal", "", "%02x", 16, "", 64, HexPrinter.Formatters.NONE, ""}, + {"canonical", "%08x ", "%02x ", 16, "|", 31, HexPrinter.Formatters.ASCII, "|\n"}, + {"simple", "%5d: ", "%02x ", 16, " // ", 64, HexPrinter.Formatters.PRINTABLE, "\n"}, + {"source", " ", "(byte)%3d, ", 8, " // ", 64, HexPrinter.Formatters.PRINTABLE, + "\n"}, + }; + } + + @Test(dataProvider = "BuiltinParams") + public void testBuiltins(String name, String offsetFormat, String binFormat, int colWidth, + String annoDelim, int annoWidth, + HexPrinter.Formatter mapper, String lineSep) { + HexPrinter f = switch (name) { + case "minimal" -> HexPrinter.minimal(); + case "simple" -> HexPrinter.simple(); + case "canonical" -> HexPrinter.canonical(); + case "source" -> HexPrinter.source(); + default -> throw new IllegalStateException("Unexpected value: " + name); + }; + + testParams(f, offsetFormat, binFormat, colWidth, annoDelim, annoWidth, mapper, lineSep); + + String actual = f.toString(); + HexPrinter f2 = HexPrinter.simple() + .withOffsetFormat(offsetFormat) + .withBytesFormat(binFormat, colWidth) + .formatter(mapper, annoDelim, annoWidth) + .withLineSeparator(lineSep); + String expected = f2.toString(); + Assert.assertEquals(actual, expected, "toString of " + name + " does not match"); + } + + @Test(dataProvider = "ColumnParams") + public void testToStringTwoLines(String offsetFormat, String binFormat, int colWidth, + String annoDelim, int annoWidth, + HexPrinter.Formatter mapper, String lineSep) { + HexPrinter f = HexPrinter.simple() + .withOffsetFormat(offsetFormat) + .withBytesFormat(binFormat, colWidth) + .formatter(mapper, annoDelim, annoWidth) + .withLineSeparator(lineSep); + testParams(f, offsetFormat, binFormat, colWidth, annoDelim, annoWidth, mapper, lineSep); + } + + public static void testParams(HexPrinter printer, String offsetFormat, String binFormat, int colWidth, + String annoDelim, int annoWidth, + HexPrinter.Formatter mapper, String lineSep) { + byte[] bytes = genData(colWidth * 2); + System.out.println("Params: " + printer.toString()); + String out = printer.toString(bytes); + System.out.println(out); + + // Compare the actual output with the expected output of each formatting element + int padToWidth = colWidth * String.format(binFormat, 0xff).length(); + int ndx = 0; + int valuesStart = 0; + int l; + for (int i = 0; i < bytes.length; i++) { + if (i % colWidth == 0) { + String offset = String.format(offsetFormat, i); + l = offset.length(); + Assert.assertEquals(out.substring(ndx, ndx + l), offset, + "offset format mismatch: " + ndx); + ndx += l; + valuesStart = ndx; + } + String value = String.format(binFormat, (0xff & bytes[i])); + l = value.length(); + Assert.assertEquals(out.substring(ndx, ndx + l), value, + "value format mismatch: " + ndx + ", i: " + i); + ndx += l; + if (((i + 1) % colWidth) == 0) { + // Rest of line is for padding, delimiter, formatter + String padding = " ".repeat(padToWidth - (ndx - valuesStart)); + Assert.assertEquals(out.substring(ndx, ndx + padding.length()), padding, "padding"); + ndx += padding.length(); + Assert.assertEquals(out.substring(ndx, ndx + annoDelim.length()), annoDelim, + "delimiter mismatch"); + ndx += annoDelim.length(); + + // Formatter output is tested separately + ndx = out.indexOf(lineSep, ndx) + lineSep.length(); + } + } + } + + @DataProvider(name = "PrimitiveFormatters") + Object[][] formatterParams() { + return new Object[][]{ + {byte.class, ""}, + {byte.class, "%02x: "}, + {short.class, "%d "}, + {int.class, "%08x, "}, + {long.class, "%16x "}, + {float.class, "%3.4f "}, + {double.class, "%6.3g "}, + {boolean.class, "%b "}, + }; + } + + @Test(dataProvider = "PrimitiveFormatters") + public void testFormatter(Class primClass, String fmtString) { + HexPrinter.Formatter formatter = HexPrinter.Formatters.ofPrimitive(primClass, fmtString); + // Create a byte array with data for two lines + int colWidth = 8; + byte[] bytes = genData(colWidth); + StringBuilder sb = new StringBuilder(); + DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)); + DataInputStream in2 = new DataInputStream(new ByteArrayInputStream(bytes)); + try { + while (true) { + formatter.annotate(in, sb); + Object n = readPrimitive(primClass, in2); + String expected = String.format(fmtString, n); + Assert.assertEquals(sb.toString(), expected, "mismatch"); + sb.setLength(0); + } + } catch (IOException ioe) { + // EOF is done + } + try { + Assert.assertEquals(in.available(), 0, "not all input consumed"); + Assert.assertEquals(in2.available(), 0, "not all 2nd stream input consumed"); + } catch (IOException ioe) { + // + } + } + + @Test(dataProvider = "PrimitiveFormatters") + static void testHexPrinterPrimFormatter(Class primClass, String fmtString) { + // Create a byte array with data for two lines + int colWidth = 8; + byte[] bytes = genData(colWidth); + + HexPrinter p = HexPrinter.simple() + .formatter(primClass, fmtString); + String actual = p.toString(bytes); + System.out.println(actual); + // The formatter should produce the same output as using the formatter method + // with an explicit formatter for the primitive + String expected = HexPrinter.simple() + .formatter(HexPrinter.Formatters.ofPrimitive(primClass, fmtString)) + .toString(bytes); + Assert.assertEquals(actual, expected, "mismatch"); + } + + private static Object readPrimitive(Class primClass, DataInputStream in) throws IOException { + if (int.class.equals(primClass)) { + return in.readInt(); + } else if (byte.class.equals(primClass)) { + return (int) in.readByte(); + } else if (short.class.equals(primClass)) { + return in.readShort(); + } else if (char.class.equals(primClass)) { + return in.readChar(); + } else if (long.class.equals(primClass)) { + return in.readLong(); + } else if (float.class.equals(primClass)) { + return in.readFloat(); + } else if (double.class.equals(primClass)) { + return in.readDouble(); + } else if (boolean.class.equals(primClass)) { + return in.readBoolean(); + } else { + throw new RuntimeException("unknown primitive class: " + primClass); + } + } + + @DataProvider(name = "sources") + Object[][] sources() { + return new Object[][]{ + {genBytes(21), 0, -1}, + {genBytes(21), 5, 12}, + }; + } + + public static byte[] genData(int len) { + // Create a byte array with data for two lines + byte[] bytes = new byte[len]; + for (int i = 0; i < len / 2; i++) { + bytes[i] = (byte) (i + 'A'); + bytes[i + len / 2] = (byte) (i + 'A' + 128); + } + return bytes; + } + + public static byte[] genFloat(int len) { + byte[] bytes = null; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(baos)) { + for (int i = 0; i < len; i++) { + out.writeFloat(i); + } + bytes = baos.toByteArray(); + } catch (IOException unused) { + } + return bytes; + } + + public static byte[] genDouble(int len) { + byte[] bytes = null; + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(baos)) { + for (int i = 0; i < len; i++) { + out.writeDouble(i); + } + bytes = baos.toByteArray(); + } catch (IOException unused) { + } + return bytes; + } + + public static byte[] genBytes(int len) { + byte[] bytes = new byte[len]; + for (int i = 0; i < len; i++) + bytes[i] = (byte) ('A' + i); + return bytes; + } + + public ByteBuffer genByteBuffer(int len) { + return ByteBuffer.wrap(genBytes(len)); + } + + public InputStream genInputStream(int len) { + return new ByteArrayInputStream(genBytes(len)); + } + + @Test + public void testNilPrinterBigBuffer() { + byte[] bytes = new byte[1024]; + HexPrinter p = HexPrinter.minimal(); + String r = p.toString(bytes); + Assert.assertEquals(r.length(), bytes.length * 2, "encoded byte wrong size"); + Assert.assertEquals(r.replace("00", "").length(), 0, "contents not all zeros"); + } + + @Test(dataProvider = "sources") + public void testToStringByteBuffer(byte[] bytes, int offset, int length) { + if (length < 0) + length = bytes.length - offset; + ByteBuffer bb = ByteBuffer.wrap(bytes, 0, bytes.length); + System.out.printf("Source: %s, off: %d, len: %d%n", + bytes.getClass().getName(), offset, length); + String actual; + if (offset == 0 && length < 0) { + bb.position(offset); + bb.limit(length); + actual = HexPrinter.simple().toString(bb); + } else + actual = HexPrinter.simple().toString(bb, offset, length); + System.out.println(actual); + String expected = HexPrinter.simple().toString(bytes, offset, length); + Assert.assertEquals(actual, expected, "mismatch in format()"); + } + + @Test(dataProvider = "sources") + public void testFormatBytes(byte[] bytes, int offset, int length) { + int len = length >= 0 ? length : bytes.length; + System.out.printf("Source: %s, off: %d, len: %d%n", + "bytes", offset, len); + StringBuilder sb = new StringBuilder(); + if (offset == 0 && length < 0) + HexPrinter.simple().dest(sb).format(bytes); + else + HexPrinter.simple().dest(sb).format(bytes, offset, len); + String actual = sb.toString(); + System.out.println(actual); + String expected = HexPrinter.simple().toString(bytes, offset, len); + Assert.assertEquals(actual, expected, "mismatch in format()"); + } + + @Test(dataProvider = "sources") + public void testFormatByteBuffer(byte[] bytes, int offset, int length) { + if (length < 0) + length = bytes.length - offset; + ByteBuffer bb = ByteBuffer.wrap(bytes, 0, bytes.length); + System.out.printf("Source: %s, off: %d, len: %d%n", + bytes.getClass().getName(), offset, length); + StringBuilder sb = new StringBuilder(); + if (offset == 0 && length < 0) { + bb.position(offset); + bb.limit(length); + HexPrinter.simple().dest(sb).format(bb); + } else + HexPrinter.simple().dest(sb).format(bb, offset, length); + String actual = sb.toString(); + System.out.println(actual); + String expected = HexPrinter.simple().toString(bytes, offset, length); + Assert.assertEquals(actual, expected, "mismatch in format()"); + } + + @Test(dataProvider = "sources") + public void testFormatInputStream(byte[] bytes, int offset, int length) { + // Offset is ignored + InputStream is = new ByteArrayInputStream(bytes, 0, length); + StringBuilder sb = new StringBuilder(); + System.out.printf("Source: %s, off: %d, len: %d%n", + bytes.getClass().getName(), offset, length); + HexPrinter.simple().dest(sb).format(is); + String actual = sb.toString(); + System.out.println(actual); + String expected = HexPrinter.simple().toString(bytes, 0, length); + Assert.assertEquals(actual, expected, "mismatch in format()"); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullByteArray() { + HexPrinter.simple().dest(System.out).format((byte[]) null); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullByteArrayOff() { + HexPrinter.simple().dest(System.out).format((byte[]) null, 0, 1); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullByteBuffer() { + HexPrinter.simple().dest(System.out).format((ByteBuffer) null); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullByteBufferOff() { + HexPrinter.simple().dest(System.out).format((ByteBuffer) null, 0, 1); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullInputStream() { + HexPrinter.simple().dest(System.out).format((InputStream) null); + } + +} diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index 620ddf781bf..371560956b8 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -255,28 +255,46 @@ public static boolean hasSA() { return true; } - /** - * Return true if the test JDK is hardened, otherwise false. Only valid on OSX. - */ - public static boolean isHardenedOSX() throws IOException { - // We only care about hardened binaries for 10.14 and later (actually 10.14.5, but - // for simplicity we'll also include earlier 10.14 versions). - if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { - return false; // assume not hardened - } - - // Find the path to the java binary. + private static Process launchCodesignOnJavaBinary() throws IOException { String jdkPath = System.getProperty("java.home"); Path javaPath = Paths.get(jdkPath + "/bin/java"); String javaFileName = javaPath.toAbsolutePath().toString(); if (!javaPath.toFile().exists()) { throw new FileNotFoundException("Could not find file " + javaFileName); } - - // Run codesign on the java binary. ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName); pb.redirectErrorStream(true); // redirect stderr to stdout Process codesignProcess = pb.start(); + return codesignProcess; + } + + public static boolean hasOSXPlistEntries() throws IOException { + Process codesignProcess = launchCodesignOnJavaBinary(); + BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); + String line; + while ((line = is.readLine()) != null) { + System.out.println("STDOUT: " + line); + if (line.indexOf("Info.plist=not bound") != -1) { + return false; + } + if (line.indexOf("Info.plist entries=") != -1) { + return true; + } + } + System.out.println("No matching Info.plist entry was found"); + return false; + } + + /** + * Return true if the test JDK is hardened, otherwise false. Only valid on OSX. + */ + public static boolean isHardenedOSX() throws IOException { + // We only care about hardened binaries for 10.14 and later (actually 10.14.5, but + // for simplicity we'll also include earlier 10.14 versions). + if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { + return false; // assume not hardened + } + Process codesignProcess = launchCodesignOnJavaBinary(); BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); String line; boolean isHardened = false; diff --git a/test/lib/jdk/test/lib/hexdump/HexPrinter.java b/test/lib/jdk/test/lib/hexdump/HexPrinter.java new file mode 100644 index 00000000000..ad4575d14e9 --- /dev/null +++ b/test/lib/jdk/test/lib/hexdump/HexPrinter.java @@ -0,0 +1,1181 @@ +/* + * Copyright (c) 2019, 2020, 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. + */ + +package jdk.test.lib.hexdump; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.CharArrayWriter; +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.UncheckedIOException; +import java.io.Writer; +import java.nio.ByteBuffer; +import java.util.Objects; + +/** + * Decode a sequence of bytes to a readable format. + *

+ * The predefined formats are: + *

+ *
{@link #minimal() Minimal format}: {@code "Now is the time for Java.\n"}
+ *
    {@code
+ *     4e6f77206973207468652074696d6520666f72204a6176612e0a} 
+ *
+ * + *
{@link #simple() Simple format}: {@code "Now is the time for Java.\n"}
+ *
{@code
+ *     0: 4e 6f 77 20 69 73 20 74 68 65 20 74 69 6d 65 20  // Now is the time for Java.\n
+ *    16: 66 6f 72 20 4a 61 76 61 2e 0a} 
+ *
+ * + *
{@link #canonical() Canonical format}: {@code "Now is the time for Java.\n"}
+ *
{@code
+ *     00000000  4e 6f 77 20 69 73 20 74 68 65 20 74 69 6d 65 20 |Now is the time |
+ *     00000010  66 6f 72 20 4a 61 76 61 2e 0a                   |for Java.|} 
+ *
+ *
{@link #source() Byte array initialization source}: {@code "Now is the time for Java.\n"}
+ *
{@code
+ *     (byte) 78, (byte)111, (byte)119, (byte) 32, (byte)105, (byte)115, (byte) 32, (byte)116,  // Now is t
+ *     (byte)104, (byte)101, (byte) 32, (byte)116, (byte)105, (byte)109, (byte)101, (byte) 32,  // he time
+ *     (byte)102, (byte)111, (byte)114, (byte) 32, (byte) 74, (byte) 97, (byte)118, (byte) 97,  // for Java
+ *     (byte) 46, (byte) 10,                                                                    // .\n}
+ *
+ *
+ *

+ * The static factories {@link #minimal minimal}, {@link #simple simple}, + * {@link #canonical canonical}, and {@link #source() Java source} + * return predefined {@code HexPrinter}s for the formats above. + * HexPrinter holds the formatting parameters that control the width and formatting + * of each of the offset, byte values, and formatted output. + * New HexPrinters with different parameters are created using an existing HexPrinter + * as a template with the methods {@link #formatter(Formatter)}, + * {@link #withBytesFormat(String, int)}, {@link #withOffsetFormat(String)}, + * and {@link #withLineSeparator(String)}. + *

+ * The source of the bytes includes byte arrays, InputStreams, and ByteBuffers. + * For example, {@link #toString(InputStream)} reads the input and returns a String. + * Each of the {@code toString(...)} methods immediately reads and + * formats all of the bytes from the source and returns a String. + *

+ * Each of the {@code format(...)} methods immediately reads and + * formats all of the bytes from the source and appends it to the destination. + * For example, {@link #format(InputStream)} reads the input and + * appends the output to {@link System#out System.out} unless the + * {@link #dest(Appendable) destination} is changed to an {@link Appendable} + * such as {@link PrintStream}, {@link StringBuilder}, or {@link Writer}. + *

+ * {@linkplain Formatter Formatter} functions read and interpret the bytes to show the + * structure and content of a protocol or data stream. + * Built-in formatters include {@link HexPrinter#formatter(Class, String) primitives}, + * {@link Formatters#PRINTABLE printable ascii}, + * and {@link Formatters#utf8Parser(DataInputStream, Appendable) UTF-8 strings}. + * The {@link #formatter(Formatter, String, int) formatter} method sets the + * formatting function, the delimiter, and the width. + * Custom formatter functions can be implemented as a lambda, a method, an inner class, or a concrete class. + *

+ * The format of each line is customizable. + * The {@link #withOffsetFormat(String) withOffsetFormat} method controls + * the format of the byte offset. + * The {@link #withBytesFormat(String, int) withBytesFormat} method controls + * the printing of each byte value including the separator, + * and the maximum number of byte values per line. + * The offset and byte values are formatted using the familiar + * {@link String#format String formats} with spacing + * and delimiters included in the format string. + * The {@link #withLineSeparator(String) withLineSeparator} method sets + * the line separator. + *

+ * Examples: + *

    + *
  • Encoding bytes to a minimal string. + *
    {@code
    + * byte[] bytes = new byte[] { ' ', 0x41, 0x42, '\n'};
    + * String s = HexPrinter.minimal().toString(bytes);
    + * Result: "2041420a"
    + * }
    + *
  • Simple formatting of a byte array. + *
    {@code
    + * byte[] bytes = new byte[] { ' ', 0x41, 0x42, '\n'};
    + * String s = HexPrinter.simple().toString(bytes);
    + * Result:    0: 20 41 42 0a                                      //  AB\n
    + * }
    + *
  • Simple formatting of a ByteBuffer. + *
    {@code
    + * ByteBuffer bb = ByteBuffer.wrap(bytes);
    + * String s = HexPrinter.simple().toString(bb);
    + * Result:    0: 20 41 42 0a                                      //  AB\n
    + * }
    + *
  • Simple formatting of ranges of a byte array to System.err. + *
    {@code
    + * byte[] bytes = new byte[] { ' ', 0x41, 0x42, 0x43, 0x44, '\n'};
    + * HexPrinter hex = HexPrinter.simple()
    + *                            .dest(System.err);
    + *                            .format(bytes, 1, 2)
    + *                            .format(bytes, 3, 2);
    + * Result:
    + * 1: 41 42                                            // AB
    + * 3: 43 44                                            // CD
    + * }
    + *
+ *

+ * This is a value-based + * class; use of identity-sensitive operations (including reference equality + * ({@code ==}), identity hash code, or synchronization) on instances + * may have unpredictable results and should be avoided. + * The {@code equals} method should be used for comparisons. + * + *

+ * This class is immutable and thread-safe. + */ +public final class HexPrinter { + + /** + * Mnemonics for control characters. + */ + static final String[] CONTROL_MNEMONICS = { + "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", + "b", "t", "n", "vt", "f", "r", "so", "si", + "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", + "can", "em", "sub", "esc", "fs", "gs", "rs", "us" + }; + private static final String initOffsetFormat = "%5d: "; + private static final int initBytesCount = 16; // 16 byte values + private static final String initBytesFormat = "%02x "; + private static final int initAnnoWidth = initBytesCount * 4; + private static final String initAnnoDelim = " // "; + + final Appendable dest; // Final output target + final String offsetFormat; // Byte offset Formatter String + final String bytesFormat; // Hex bytes Formatter string + final int bytesCount; // Maximum number of byte values per line + final String annoDelim; // Annotation delimiter + final int annoWidth; // Annotation field width (characters) + final String lineSeparator; // End of line separator + final Formatter annoFormatter; // formatter function + + /** + * Construct a new HexPrinter with all new values. + * + * @param printer the formatter + * @param offsetFormat the offset format + * @param bytesFormat the bytes format + * @param bytesCount the count of bytes per line + * @param annoDelim the delimiter before the annotation + * @param annoWidth the width of the annotation + * @param lineSeparator the line separator + * @param dest the destination + */ + private HexPrinter(Formatter printer, String offsetFormat, String bytesFormat, int bytesCount, + String annoDelim, int annoWidth, + String lineSeparator, Appendable dest) { + this.annoFormatter = Objects.requireNonNull(printer, "formatter"); + this.bytesCount = bytesCount; + this.bytesFormat = Objects.requireNonNull(bytesFormat, bytesFormat); + this.offsetFormat = Objects.requireNonNull(offsetFormat, "offsetFormat"); + this.annoDelim = Objects.requireNonNull(annoDelim, "annoDelim"); + this.annoWidth = annoWidth; + this.lineSeparator = Objects.requireNonNull(lineSeparator, "lineSeparator"); + this.dest = Objects.requireNonNull(dest, "dest"); + } + + /** + * Returns a new HexPrinter setting the parameters to produce a minimal string. + * The parameters are set to: + *

    + *
  • byte offset format: none {@code ""}, + *
  • each byte value is formatted as 2 hex digits: {@code "%02x"}, + *
  • maximum number of byte values per line: unbounded, + *
  • delimiter for the annotation: none {@code ""}, + *
  • formatter: {@link Formatters#NONE does not output a formatted byte}, and + *
  • destination: {@link System#out System.out}. + *
+ * Example, + *
+     * {@code     byte[] bytes = new byte[] { ' ', 0x41, 0x42, '\n'};
+     *     String s = HexPrinter.minimal()
+     *             .toString(bytes);
+     *     Result: "2041420a"
+     * }
+ * + * @return a new HexPrinter + */ + public static HexPrinter minimal() { + return new HexPrinter(Formatters.NONE, "", + "%02x", initBytesCount, + "", initAnnoWidth, "", + System.out); + } + + /** + * Returns a new HexPrinter setting the parameters to produce canonical output. + * The parameters are set to: + *
    + *
  • byte offset format: {@code "%08x "}, + *
  • each byte value is formatted as 2 hex digits and a space: {@code "%02x "}, + *
  • maximum number of byte values per line: {@value initBytesCount}, + *
  • delimiter for the annotation: {@code "|"}, + *
  • formatter: {@link Formatters#ASCII ASCII bytes}, and + *
  • line separator: "|" + {@link System#lineSeparator()}, + *
  • destination: {@link System#out System.out}. + *
+ * Example, + *
+     * {@code     byte[] bytes = new byte[] { ' ', 0x41, 0x42, '\n'};
+     *     String s = HexPrinter.canonical()
+     *             .toString(bytes);
+     *
+     *     Result: "00000000  20 41 42 0a                                     | AB|"
+     * }
+ * + * @return a new HexPrinter + */ + public static HexPrinter canonical() { + return new HexPrinter(Formatters.ASCII, "%08x ", + "%02x ", initBytesCount, + "|", 31, "|" + System.lineSeparator(), + System.out); + } + + /** + * Returns a new HexPrinter setting simple formatting parameters to output + * to a multi-line string. + * The parameters are set to: + *
    + *
  • byte offset format: signed decimal width 5 and a space, {@code "%5d: "}, + *
  • each byte value is formatted as 2 hex digits and a space: {@code "%02x "}, + *
  • maximum number of byte values per line: {@value initBytesCount}, + *
  • delimiter for the annotation: {@code " // "}, + *
  • width for the annotation: {@value initAnnoWidth}, + *
  • line separator: {@link System#lineSeparator()}, + *
  • formatter: {@link Formatters#PRINTABLE printable ASCII} + * showing printable characters, mnemonics for control chars, and + * otherwise the decimal byte values, + *
  • destination default: {@link System#out System.out}. + *
+ * Example, + *
+     * {@code    byte[] bytes = new byte[] { ' ', 0x41, 0x42, '\n'};
+     *    String s = HexPrinter.simple()
+     *            .toString(bytes);
+     *
+     *    Result: "    0: 20 41 42 0a                                      //  AB\n"
+     * }
+ * + * @return a new HexPrinter + */ + public static HexPrinter simple() { + return new HexPrinter(Formatters.PRINTABLE, initOffsetFormat, + initBytesFormat, initBytesCount, + initAnnoDelim, initAnnoWidth, System.lineSeparator(), + System.out); + } + + /** + * Returns a new HexPrinter setting formatting parameters to output + * to a multi-line string as a byte array initialization for Java source. + * The parameters are set to: + *
    + *
  • byte offset format: 4 space indent: {@code " "}, + *
  • each byte value is formatted as: {@code "(byte)%3d, "}, + *
  • maximum number of byte values per line: {@code 8}, + *
  • delimiter for the annotation: {@code " // "}, + *
  • width for the annotation: {@value initAnnoWidth}, + *
  • line separator: {@link System#lineSeparator()}, + *
  • formatter: {@link Formatters#PRINTABLE printable ASCII} + * showing printable characters, mnemonics for control chars, and + * otherwise the decimal byte values, + *
  • destination default: {@link System#out System.out}. + *
+ * + * @return a new HexPrinter + */ + public static HexPrinter source() { + return new HexPrinter(Formatters.PRINTABLE, " ", + "(byte)%3d, ", 8, + " // ", initAnnoWidth, System.lineSeparator(), + System.out); + } + + /** + * Returns a new HexPrinter setting the destination to the Appendable. + * {@code Appendable} classes include: {@link PrintStream}, {@link Writer}, + * {@link StringBuilder}, and {@link StringBuffer}. + * + * @param dest the Appendable destination for the output, non-null + * @return a new HexPrinter + * @throws UncheckedIOException if an I/O error occurs + */ + public HexPrinter dest(Appendable dest) { + Objects.requireNonNull(dest, "dest"); + return new HexPrinter(annoFormatter, offsetFormat, + bytesFormat, bytesCount, annoDelim, + annoWidth, lineSeparator, dest); + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * and append the output. + * All output is appended and flushed to the destination. + *

+ * The result is equivalent to calling + * {@code format(new ByteArrayInputStream(source))}. + * + * @param source a non-null array of bytes. + * @return this HexPrinter + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public HexPrinter format(byte[] source) { + Objects.requireNonNull(source, "byte array must be non-null"); + return format(new ByteArrayInputStream(source)); + } + + /** + * The formatter function is called repeatedly to read the bytes from offset + * for length and append the output. + * All output is appended and flushed to the destination. + * Only {@code length} bytes starting at the {@code offset} are formatted. + *

+ * The result is equivalent to calling + * {@code format(new ByteArrayInputStream(source, offset, len))}. + * + * @param source a non-null array of bytes. + * @param offset the offset into the array to start + * @param length the length of bytes in the array to format + * @return this HexPrinter + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public HexPrinter format(byte[] source, int offset, int length) { + Objects.requireNonNull(source, "byte array must be non-null"); + return format(new ByteArrayInputStream(source, offset, length), offset); + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * and append the output. + * All output is appended and flushed to the destination. + *

+ * The {@code format} method invokes the {@code formatter} to read bytes from the + * source and append the formatted sequence of byte values to the destination. + * As the bytes are read they are printed using the {@link #withBytesFormat} + * to fill the bytes values of the output destination. + * The output of the {@code formatter} fills the annotation field. + * A new line is started when either the byte values or annotation + * is filled to its respective width. The offset of the first byte on the line + * is inserted at the beginning of each line using {@link #withOffsetFormat(String)}. + *

+ * This method may block indefinitely reading from the input stream, + * or writing to the output stream. The behavior for the case where + * the input and/or output stream is asynchronously closed, + * or the thread interrupted during the transfer, is highly input + * and output stream specific, and therefore not specified. + *

+ * If an I/O error occurs reading from the input stream or + * writing to the output stream, then it may do so after some bytes + * have been read or written. Consequently the input stream + * may not be at end of stream and one, or both, streams may be + * in an inconsistent state. It is strongly recommended that both streams + * be promptly closed if an I/O error occurs. + * + * @param source an InputStream to read from, the stream not closed and + * is at end-of-file. + * @return this HexPrinter + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public HexPrinter format(InputStream source) { + return format(source, 0); + } + + /** + * Format an InputStream and supply the initial offset. + * + * @param source an InputStream + * @param offset an offset + * @return this HexPrinter + */ + private HexPrinter format(InputStream source, int offset) { + Objects.requireNonNull(source, "InputStream must be non-null"); + try (AnnotationWriter writer = + new AnnotationWriter(this, source, offset, dest)) { + writer.flush(); + return this; + } + } + + /** + * The formatter function is called repeatedly to read the bytes + * from the offset for the length and append the output. + * All annotation output is appended and flushed to the output destination. + * The ByteBuffer position and limit are unused and not modified. + * + * @param source a ByteBuffer + * @param offset the offset in the ByteBuffer + * @param length the length in the ByteBuffer + * @return this HexPrinter + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public HexPrinter format(ByteBuffer source, int offset, int length) { + Objects.requireNonNull(source, "ByteBuffer must be non-null"); + ByteArrayInputStream bais; + if (source.hasArray() && !source.isReadOnly()) { + bais = new ByteArrayInputStream(source.array(), offset, length); + } else { + int size = source.limit() - source.position(); + byte[] bytes = new byte[size]; + source.get(bytes, offset, length); + bais = new ByteArrayInputStream(bytes); + } + return format(bais, offset); + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * in the source and append the output. + * The source bytes are from the {@code ByteBuffer.position()} + * to the {@code ByteBuffer.limit()}. + * The position is not modified. + * All output is appended and flushed to the destination. + * + * @param source a ByteBuffer + * @return this HexPrinter + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public HexPrinter format(ByteBuffer source) { + return format(source, source.position(), source.limit()); + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * and return a String. + * + * @param source a non-null array of bytes. + * @return the output as a non-null {@code String} + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public String toString(byte[] source) { + Objects.requireNonNull(source, "byte array must be non-null"); + return toString(new ByteArrayInputStream(source)); + } + + /** + * The formatter function is called repeatedly to read the bytes from offset + * for length and return a String. + * Only {@code length} bytes starting at the {@code offset} are formatted. + * + * @param source a non-null array of bytes. + * @param offset the offset into the array to start + * @param length the length of bytes in the array to format + * @return the output as a non-null {@code String} + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public String toString(byte[] source, int offset, int length) { + Objects.requireNonNull(source, "byte array must be non-null"); + StringBuilder sb = new StringBuilder(); + try (AnnotationWriter writer = + new AnnotationWriter(this, new ByteArrayInputStream(source, offset, length), + offset, sb)) { + writer.flush(); + return sb.toString(); + } + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * and return a String. + *

+ * The {@code toString} method invokes the formatter to read bytes from the + * source and append the formatted sequence of byte values. + * As the bytes are read they are printed using the {@link #withBytesFormat} + * to fill the second field of the line. + * The output of the {@code formatter} fills the annotation field. + * A new line is started when either the byte values or annotation + * is filled to its respective width. The offset of the first byte on the line + * is inserted at the beginning of each line using {@link #withOffsetFormat(String)}. + *

+ * This method may block indefinitely reading from the input stream, + * or writing to the output stream. The behavior for the case where + * the input and/or output stream is asynchronously closed, + * or the thread interrupted during the transfer, is highly input + * and output stream specific, and therefore not specified. + *

+ * If an I/O error occurs reading from the input stream or + * writing to the output stream, then it may do so after some bytes + * have been read or written. Consequently the input stream + * may not be at end of stream and one, or both, streams may be + * in an inconsistent state. It is strongly recommended that both streams + * be promptly closed if an I/O error occurs. + * + * @param source an InputStream to read from, the stream not closed and + * is at end-of-file upon return. + * @return the output as a non-null {@code String} + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public String toString(InputStream source) { + Objects.requireNonNull(source, "InputStream must be non-null"); + StringBuilder sb = new StringBuilder(); + try (AnnotationWriter writer = + new AnnotationWriter(this, source, 0, sb)) { + writer.flush(); + return sb.toString(); + } + } + + /** + * The formatter function is called repeatedly to read the bytes + * from the offset for the length and return a String. + * The ByteBuffer position and limit are unused and not modified. + * + * @param source a ByteBuffer + * @param offset the offset in the ByteBuffer + * @param length the length in the ByteBuffer + * @return the output as a non-null {@code String} + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public String toString(ByteBuffer source, int offset, int length) { + Objects.requireNonNull(source, "ByteBuffer must be non-null"); + StringBuilder sb = new StringBuilder(); + ByteArrayInputStream bais; + if (source.hasArray() && !source.isReadOnly()) { + bais = new ByteArrayInputStream(source.array(), offset, length); + } else { + byte[] bytes = new byte[length]; + source.get(bytes, offset, length); + bais = new ByteArrayInputStream(bytes); + } + try (AnnotationWriter writer = + new AnnotationWriter(this, bais, offset, sb)) { + writer.flush(); + return sb.toString(); + } + } + + /** + * The formatter function is called repeatedly to read all of the bytes + * in the source and return a String. + * The source bytes are from the {@code ByteBuffer.position()} + * to the {@code ByteBuffer.limit()}. + * The position is not modified. + * + * @param source a ByteBuffer + * @return the output as a non-null {@code String} + * @throws java.io.UncheckedIOException if an I/O error occurs + */ + public String toString(ByteBuffer source) { + return toString(source, source.position(), source.limit()); + } + + /** + * Returns a new HexPrinter setting the format for the byte offset. + * The format string is specified by {@link String#format String format} + * including any delimiters. For example, {@code "%3x: "}. + * If the format is an empty string, there is no offset in the output. + * + * @param offsetFormat a new format string for the byte offset. + * @return a new HexPrinter + */ + public HexPrinter withOffsetFormat(String offsetFormat) { + Objects.requireNonNull(offsetFormat, "offsetFormat"); + return new HexPrinter(annoFormatter, offsetFormat, bytesFormat, bytesCount, + annoDelim, annoWidth, lineSeparator, dest); + } + + /** + * Returns a new HexPrinter setting the format for each byte value and + * the maximum number of byte values per line. + * The format string is specified by {@link String#format String format}, + * including any delimiters or padding. For example, {@code "%02x "}. + * If the byteFormat is an empty String, there are no byte values in the output. + * + * @param byteFormat a format string for each byte + * @param bytesCount the maximum number of byte values per line + * @return a new HexPrinter + */ + public HexPrinter withBytesFormat(String byteFormat, int bytesCount) { + Objects.requireNonNull(bytesFormat, "bytesFormat"); + return new HexPrinter(annoFormatter, offsetFormat, byteFormat, bytesCount, + annoDelim, annoWidth, lineSeparator, dest); + } + + /** + * Returns a new HexPrinter setting the line separator. + * The line separator can be set to an empty string or to + * a string to be added at the end of each line. It should include the line + * separator {@link System#lineSeparator()} if a line break is to be output. + * + * @param separator the line separator + * @return a new HexPrinter + */ + public HexPrinter withLineSeparator(String separator) { + return new HexPrinter(annoFormatter, offsetFormat, bytesFormat, bytesCount, + annoDelim, annoWidth, separator, dest); + } + + /** + * Returns a new HexPrinter setting the formatter. + * The widths, delimiters and other parameters are unchanged. + * + * @param formatter a non-null Formatter + * @return a new HexPrinter + */ + public HexPrinter formatter(Formatter formatter) { + Objects.requireNonNull(formatter, "Formatter must be non-null"); + return new HexPrinter(formatter, offsetFormat, bytesFormat, bytesCount, + annoDelim, annoWidth, lineSeparator, dest); + } + + /** + * Returns a new HexPrinter setting the formatter, delimiter, and width of the annotation. + * Note: The annotations may exceed the width. + * + * @param formatter a non-null Formatter + * @param delim a string delimiter for the annotation + * @param width the width of the annotation, non-negative + * @return a new HexPrinter + */ + public HexPrinter formatter(Formatter formatter, String delim, int width) { + Objects.requireNonNull(formatter, "formatter"); + Objects.requireNonNull(delim, "delim"); + return new HexPrinter(formatter, offsetFormat, bytesFormat, bytesCount, + delim, width, lineSeparator, dest); + } + + /** + * Returns a new HexPrinter setting the formatter to format a primitive type + * using the format string. + * The format string should include any pre or post spacing and delimiters. + *

+ * This is a convenience function equivalent to finding a formatter using + * {@link HexPrinter.Formatters#ofPrimitive}. + *

+ * + * @param primClass a primitive class, for example, {@code int.class} + * @param fmtString a {@link java.util.Formatter format string}. + * @return a new HexPrinter + * @throws IllegalArgumentException if the class is not a primitive class + */ + public HexPrinter formatter(Class primClass, String fmtString) { + Formatter formatter = getFormatter(primClass, fmtString); + return new HexPrinter(formatter, offsetFormat, bytesFormat, bytesCount, + annoDelim, annoWidth, lineSeparator, dest); + } + + /** + * Returns a formatter for the primitive type using the format string. + * The formatter reads a value of the primitive type from the stream + * and formats it using the format string. + * The format string includes any pre or post spacing and delimiters. + * + * @param primClass a primitive class, for example, {@code int.class} + * @param fmtString a {@link java.util.Formatter format string} + * @return a Formatter for the primitive type using the format string + */ + static Formatter getFormatter(Class primClass, String fmtString) { + return new PrimitiveFormatter(primClass, fmtString); + } + + /** + * Returns a string describing this HexPrinter. + * The string indicates the type of the destination and + * the formatting options. + * + * @return a String describing this HexPrinter + */ + public String toString() { + return "formatter: " + annoFormatter + + ", dest: " + dest.getClass().getName() + + ", offset: \"" + offsetFormat + + "\", bytes: " + bytesCount + + " x \"" + bytesFormat + "\"" + + ", delim: \"" + annoDelim + "\"" + + ", width: " + annoWidth + + ", nl: \"" + expand(lineSeparator) + "\""; + } + + private String expand(String sep) { + return sep.replace("\n", "\\n") + .replace("\r", "\\r"); + } + + private static class PrimitiveFormatter implements Formatter { + + private final Class primClass; + private final String fmtString; + + PrimitiveFormatter(Class primClass, String fmtString) { + Objects.requireNonNull(primClass, "primClass"); + Objects.requireNonNull(fmtString, "fmtString"); + if (!primClass.isPrimitive()) + throw new IllegalArgumentException("Not a primitive type: " + primClass.getName()); + this.primClass = primClass; + this.fmtString = fmtString; + } + + public void annotate(DataInputStream in, Appendable out) throws IOException { + if (primClass == byte.class) { + int v = in.readByte(); + out.append(String.format(fmtString, v)); + } else if (primClass == boolean.class) { + boolean v = in.readByte() != 0; + out.append(String.format(fmtString, v)); + } else if (primClass == short.class | primClass == char.class) { + int v = in.readShort(); + out.append(String.format(fmtString, v)); + } else if (primClass == float.class) { + float v = in.readFloat(); + out.append(String.format(fmtString, v)); + } else if (primClass == int.class) { + int v = in.readInt(); + out.append(String.format(fmtString, v)); + } else if (primClass == double.class) { + double v = in.readDouble(); + out.append(String.format(fmtString, v)); + } else if (primClass == long.class) { + long v = in.readLong(); + out.append(String.format(fmtString, v)); + } else { + throw new AssertionError("missing case on primitive class"); + } + } + + public String toString() { + return "(" + primClass.getName() + ", \"" + fmtString + "\")"; + } + } + + /** + * Formatter function reads bytes from a stream and + * appends a readable annotation to the output destination. + *

+ * Each invocation of the {@link #annotate annotate} method reads and annotates + * a single instance of its protocol or data type. + *

+ * Built-in formatting functions are provided in the {@link Formatters} class. + *

+ * As described by the {@link HexPrinter#toString(InputStream)} method, + * the {@link #annotate annotate} method is called to read bytes and produce + * the descriptive annotation. + *

+ * For example, a custom lambda formatter to read a float value (4 bytes) and + * print as a floating number could be written as a static method. + *

{@code
+     *     // Format 4 bytes read from the input as a float 3.4.
+     *     static void annotate(DataInputStream in, Appendable out) throws IOException {
+     *         float f = in.readFloat();
+     *         out.append(String.format("%3.4f, ", f));
+     *     }
+     *
+     *     byte[] bytes = new byte[] {00 00 00 00 3f 80 00 00 40 00 00 00 40 40 00 00};
+     *     HexPrinter pp = HexPrinter.simple()
+     *         .withBytesFormat("%02x ", 8)
+     *         .formatter(Example::annotate)
+     *         .format(bytes);
+     *
+     * Result:
+     *     0: 00 00 00 00 3f 80 00 00  // 0.0000, 1.0000,
+     *     8: 40 00 00 00 40 40 00 00  // 2.0000, 3.0000,
+     * }
+ * + *

+ * The details of the buffering and calling of the formatter {@code annotate} + * methods is roughly as follows. + * The bytes read by the {@code annotate} method are logically buffered + * for each line of output. + * The {@code annotate} method writes its description of the bytes read + * to the output, this output is also buffered. + * When the number of bytes read exceeds the + * {@link #withBytesFormat(String, int) byte values count per line}, + * the buffered output exceeds the + * {@link #formatter(Formatter, String, int) width of the annotation field}, + * or a new line {@code "\n"} character is found in the output then + * a line of output is assembled and written to the destination Appendable. + * The formatter's {@code annotate} method is called repeatedly + * until the input is completely consumed or an exception is thrown. + * Any remaining buffered bytes or description are flushed to the destination Appendable. + */ + @FunctionalInterface + public interface Formatter { + + /** + * Read bytes from the input stream and append a descriptive annotation + * to the output destination. + * + * @param in a DataInputStream + * @param out an Appendable for the output + * @throws IOException if an I/O error occurs + */ + void annotate(DataInputStream in, Appendable out) throws IOException; + } + + /** + * Built-in formatters for printable byte, ASCII, UTF-8 and primitive types. + * Formatters for primitive types and different formatting options + * can be found by calling {@link #ofPrimitive(Class, String)}. + */ + public enum Formatters implements Formatter { + /** + * Read a byte and if it is ASCII write it, + * otherwise, write its mnemonic or its decimal value. + */ + PRINTABLE, + /** + * Read a byte, if it is ASCII write it, otherwise write a ".". + */ + ASCII, + /** + * Read a modified UTF-8 string and write it. + */ + UTF8, + /** + * Read a byte and write nothing. + */ + NONE; + + public void annotate(DataInputStream in, Appendable out) throws IOException { + switch (this) { + case PRINTABLE: bytePrintable(in, out); break; + case ASCII: byteASCII(in, out); break; + case UTF8: utf8Parser(in, out); break; + case NONE: byteNoneParser(in, out); break; + } + } + + /** + * Read a byte and write it as ASCII if it is printable, + * print its mnemonic if it is a control character, + * and print its decimal value otherwise. + * A space separator character is appended for control and decimal values. + * + * @param in a DataInputStream + * @param out an Appendable to write to + * @throws IOException if an I/O error occurs + */ + static void bytePrintable(DataInputStream in, Appendable out) throws IOException { + int v = in.readUnsignedByte(); + if (v < 32) { + out.append("\\").append(CONTROL_MNEMONICS[v]); + } else if (v < 126 && Character.isDefined(v)) { + out.append((char) v); + } else { + out.append("\\").append(Integer.toString(v, 10)); + } + } + + /** + * Read a byte and write it as ASCII if it is printable, otherwise print ".". + * + * @param in a DataInputStream + * @param out an Appendable to write to + * @throws IOException if an I/O error occurs + */ + static void byteASCII(DataInputStream in, Appendable out) throws IOException { + int v = in.readUnsignedByte(); + if (Character.isDefined(v)) { + out.append((char) v); + } else { + out.append('.'); + } + } + + /** + * Read a modified UTF-8 string and write it to the output destination. + * + * @param in a DataInputStream + * @param out an Appendable to write the output to + * @throws IOException if an I/O error occurs + */ + static void utf8Parser(DataInputStream in, Appendable out) throws IOException { + out.append(in.readUTF()).append(" "); + } + + /** + * Read a a byte and write nothing. + * + * @param in a DataInputStream + * @param out an Appendable to write the output to + * @throws IOException if an I/O error occurs + */ + static void byteNoneParser(DataInputStream in, Appendable out) throws IOException { + in.readByte(); + } + + /** + * Returns a {@code Formatter} for a primitive using the format string. + * The format string includes any pre or post spacing or delimiters. + * A value of the primitive is read using the type specific methods + * of {@link DataInputStream}, formatted using the format string, and + * written to the output. + * + * @param primClass a primitive class, for example, {@code int.class} + * @param fmtString a {@link java.util.Formatter format string}. + * @return a Formatter + */ + public static Formatter ofPrimitive(Class primClass, String fmtString) { + Objects.requireNonNull(primClass, "primClass"); + Objects.requireNonNull(fmtString, "fmtString"); + return new PrimitiveFormatter(primClass, fmtString); + } + } + + /** + * Internal implementation of the annotation output and processor of annotated output. + * Created for each new input source and discarded after each use. + * An OffsetInputStream is created to buffer and count the input bytes. + * + */ + private static final class AnnotationWriter extends CharArrayWriter { + private final transient OffsetInputStream source; + private final transient DataInputStream in; + private final transient int baseOffset; + private final transient HexPrinter params; + private final transient int bytesColWidth; + private final transient int annoWidth; + private final transient Appendable dest; + + /** + * Construct a new AnnotationWriter to process the source into the destination. + * Initializes the DataInputStream and marking of the input to keep track + * of bytes as they are read by the formatter. + * @param params formatting parameters + * @param source source InputStream + * @param baseOffset initial offset + * @param dest destination Appendable + */ + AnnotationWriter(HexPrinter params, InputStream source, int baseOffset, Appendable dest) { + this.params = params; + this.baseOffset = baseOffset; + Objects.requireNonNull(source, "Source is null"); + this.source = new OffsetInputStream(source); + this.source.mark(1024); + this.in = new DataInputStream(this.source); + this.bytesColWidth = params.bytesCount * String.format(params.bytesFormat, 255).length(); + this.annoWidth = params.annoWidth; + this.dest = dest; + } + + @Override + public void write(int c) { + super.write(c); + checkFlush(); + } + + @Override + public void write(char[] c, int off, int len) { + super.write(c, off, len); + for (int i = 0; i < len; i++) { + if (c[off+i] == '\n') { + process(); + return; + } + } + checkFlush(); + } + + @Override + public void write(String str, int off, int len) { + super.write(str, off, len); + if (str.indexOf('\n') >=0 ) + process(); + else + checkFlush(); + } + + private void checkFlush() { + if (size() > annoWidth) + process(); + } + + /** + * The annotation printing function is called repeatedly to read all of the bytes + * in the source stream and annotate the stream. + * The annotated output is appended to the output dest or buffered. + *

+ * The HexPrinter is not closed and can be used as a template + * to create a new formatter with a new Source or different formatting + * options. + *

+ */ + @Override + public void flush() { + try { + while (true) { + if (source.markedByteCount() >= params.bytesCount) + process(); + params.annoFormatter.annotate(in, this); + if (source.markedByteCount() > 256) { + // Normally annotations would cause processing more often + // Guard against overrunning the mark/reset buffer. + process(); + } + } + } catch (IOException ioe) { + process(); + if (!(ioe instanceof EOFException)) { + throw new UncheckedIOException(ioe); + } + } catch (UncheckedIOException uio) { + process(); // clear out the buffers + throw uio; + } + } + + /** + * Merge the buffered stream of annotations with the formatted bytes + * and append them to the dest. + *

+ * The annotation mapping function has read some bytes and buffered + * some output that corresponds to those bytes. + * The un-formatted bytes are in the OffsetInputStream after the mark. + * The stream is reset and the bytes are read again. + * Each line of the produced one line at a time to the dest. + * The byte offset is formatted according to the offsetFormat. + * The bytes after the mark are read and formatted using the bytesFormat + * and written to the dest up to the bytesWidth. + * The annotation stream is appended to the dest, but only up to the + * first newline (if any). The alignment between the annotated stream + * and the formatted bytes is approximate. + * New line characters in the annotation cause a new line to be started + * without regard to the number of formatted bytes. The column of formatted + * bytes may be incomplete. + */ + private void process() { + String info = toString(); + reset(); + int count = source.markedByteCount(); + try { + source.reset(); + long binColOffset = source.byteOffset(); + while (count > 0 || info.length() > 0) { + dest.append(String.format(params.offsetFormat, binColOffset + baseOffset)); + int colWidth = 0; + int byteCount = Math.min(params.bytesCount, count); + for (int i = 0; i < byteCount; i++) { + int b = source.read(); + if (b == -1) + throw new IllegalStateException("BUG"); + String s = String.format(params.bytesFormat, b); + colWidth += s.length(); + dest.append(s); + } + binColOffset += byteCount; + count -= byteCount; + + // Pad out the bytes column to its width + dest.append(" ".repeat(Math.max(0, bytesColWidth - colWidth))); + dest.append(params.annoDelim); + + // finish a line and prepare for next line + // Add a line from annotation buffer + if (info.length() > 0) { + int nl = info.indexOf('\n'); + if (nl < 0) { + dest.append(info); + info = ""; + } else { + dest.append(info, 0, nl); + info = info.substring(nl + 1); + } + } + dest.append(params.lineSeparator); + } + } catch (IOException ioe) { + try { + dest.append("\nIOException during annotations: ") + .append(ioe.getMessage()) + .append("\n"); + } catch (IOException ignore) { + // ignore + } + } + // reset the mark for the next line + source.mark(1024); + } + } + + /** + * Buffered InputStream that keeps track of byte offset. + */ + private static final class OffsetInputStream extends BufferedInputStream { + private long byteOffset; + private long markByteOffset; + + OffsetInputStream(InputStream in) { + super(in); + byteOffset = 0; + markByteOffset = 0; + } + + long byteOffset() { + return byteOffset; + } + + @Override + public void reset() throws IOException { + super.reset(); + byteOffset = markByteOffset; + } + + @Override + public synchronized void mark(int readlimit) { + super.mark(readlimit); + markByteOffset = byteOffset; + } + + int markedByteCount() { + if (markpos < 0) + return 0; + return pos - markpos; + } + + @Override + public int read() throws IOException { + int b = super.read(); + if (b >= 0) + byteOffset++; + return b; + } + + @Override + public long skip(long n) throws IOException { + long size = super.skip(n); + byteOffset += size; + return size; + } + + @Override + public int read(byte[] b) throws IOException { + int size = super.read(b); + byteOffset += Math.max(size, 0); + return size; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int size = super.read(b, off, len); + byteOffset += Math.max(size, 0); + return size; + } + } +} diff --git a/test/lib/jdk/test/lib/util/CoreUtils.java b/test/lib/jdk/test/lib/util/CoreUtils.java index 6675c30973c..100b19e61f6 100644 --- a/test/lib/jdk/test/lib/util/CoreUtils.java +++ b/test/lib/jdk/test/lib/util/CoreUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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 @@ -110,6 +110,8 @@ public static String getCoreFileLocation(String crashOutputString) throws IOExce Asserts.assertGT(new File(coreFileLocation).length(), 0L, "Unexpected core size"); System.out.println("Found core file: " + coreFileLocation); return coreFileLocation; // success! + } else { + System.out.println("Core file not found. Trying to find a reason why..."); } // See if we can figure out the likely reason the core file was not found. @@ -130,6 +132,11 @@ public static String getCoreFileLocation(String crashOutputString) throws IOExce // We can't generate cores files with hardened binaries on OSX 10.15 and later. throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later"); } + } else { + // codesign has to add entitlements using the plist. If this is not present we might not generate a core file. + if (!Platform.hasOSXPlistEntries()) { + throw new SkippedException("Cannot produce core file with binary having no plist entitlement entries"); + } } } else if (Platform.isLinux()) { // Check if a crash report tool is installed.