提交 a5864f57 编写于 作者: C cgruszka

Merge

...@@ -157,3 +157,4 @@ ddfe5562f61f54ed2121ac0c73b688b94f3e66b5 jdk8-b32 ...@@ -157,3 +157,4 @@ ddfe5562f61f54ed2121ac0c73b688b94f3e66b5 jdk8-b32
78cea258caaba3980ba186c426da82c8fe41bfd7 jdk8-b33 78cea258caaba3980ba186c426da82c8fe41bfd7 jdk8-b33
29b680393f33bf953688c17d93aca7a870ca4024 jdk8-b34 29b680393f33bf953688c17d93aca7a870ca4024 jdk8-b34
2e3e1356ffbddb2ae95c08da72830ba9ab8b3181 jdk8-b35 2e3e1356ffbddb2ae95c08da72830ba9ab8b3181 jdk8-b35
45da9cb055ee258dc09e69c1718e27eadea38e45 jdk8-b36
# #
# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../../.. BUILDDIR = ../../../..
PACKAGE = com.sun.tools.attach PACKAGE = com.sun.tools.attach
LIBRARY = attach LIBRARY = attach
......
...@@ -131,8 +131,9 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ...@@ -131,8 +131,9 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
# Setting ENABLE_FULL_DEBUG_SYMBOLS=1 (and OBJCOPY) above enables the # Setting ENABLE_FULL_DEBUG_SYMBOLS=1 (and OBJCOPY) above enables the
# JDK build to import .debuginfo or .diz files from the HotSpot build. # JDK build to import .debuginfo or .diz files from the HotSpot build.
# However, adding FDS support to the JDK build will occur in phases # However, adding FDS support to the JDK build will occur in phases
# so a different make variable (LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS) # so a different make variable (LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS
# is used to indicate that a particular library supports FDS. # and PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS) is used to indicate that a
# particular library or program supports FDS.
ifeq ($(OBJCOPY),) ifeq ($(OBJCOPY),)
_JUNK_ := $(shell \ _JUNK_ := $(shell \
...@@ -156,9 +157,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ...@@ -156,9 +157,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
_JUNK_ := $(shell \ _JUNK_ := $(shell \
echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)") echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)")
# HACK: disable ZIP_DEBUGINFO_FILES by default until install repo ZIP_DEBUGINFO_FILES ?= 1
# changes are promoted
ZIP_DEBUGINFO_FILES ?= 0
_JUNK_ := $(shell \ _JUNK_ := $(shell \
echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)") echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)")
...@@ -261,6 +260,17 @@ ifeq ($(DEBUG_BINARIES), true) ...@@ -261,6 +260,17 @@ ifeq ($(DEBUG_BINARIES), true)
CFLAGS_REQUIRED += $(DEBUG_FLAG) CFLAGS_REQUIRED += $(DEBUG_FLAG)
endif endif
# If Full Debug Symbols is enabled, then we want the same debug and
# optimization flags as used by FASTDEBUG.
#
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
ifeq ($(VARIANT), OPT)
CC_OPT = $(DEBUG_FLAG) $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
endif
endif
endif
CFLAGS_OPT = $(CC_OPT) CFLAGS_OPT = $(CC_OPT)
CFLAGS_DBG = $(DEBUG_FLAG) CFLAGS_DBG = $(DEBUG_FLAG)
CFLAGS_COMMON += $(CFLAGS_REQUIRED) CFLAGS_COMMON += $(CFLAGS_REQUIRED)
......
...@@ -138,8 +138,9 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ...@@ -138,8 +138,9 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
# Setting ENABLE_FULL_DEBUG_SYMBOLS=1 (and OBJCOPY) above enables the # Setting ENABLE_FULL_DEBUG_SYMBOLS=1 (and OBJCOPY) above enables the
# JDK build to import .debuginfo or .diz files from the HotSpot build. # JDK build to import .debuginfo or .diz files from the HotSpot build.
# However, adding FDS support to the JDK build will occur in phases # However, adding FDS support to the JDK build will occur in phases
# so a different make variable (LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS) # so a different make variable (LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS
# is used to indicate that a particular library supports FDS. # and PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS) is used to indicate that a
# particular library or program supports FDS.
ifeq ($(OBJCOPY),) ifeq ($(OBJCOPY),)
_JUNK_ := $(shell \ _JUNK_ := $(shell \
...@@ -164,9 +165,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ...@@ -164,9 +165,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
_JUNK_ := $(shell \ _JUNK_ := $(shell \
echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)") echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)")
# HACK: disable ZIP_DEBUGINFO_FILES by default until install repo ZIP_DEBUGINFO_FILES ?= 1
# changes are promoted
ZIP_DEBUGINFO_FILES ?= 0
_JUNK_ := $(shell \ _JUNK_ := $(shell \
echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)") echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)")
...@@ -240,6 +239,21 @@ ifeq ($(FASTDEBUG), true) ...@@ -240,6 +239,21 @@ ifeq ($(FASTDEBUG), true)
CXXFLAGS_DEBUG_OPTION = -g0 $(CXX_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) CXXFLAGS_DEBUG_OPTION = -g0 $(CXX_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
endif endif
# If Full Debug Symbols is enabled, then we want the same debug and
# optimization flags as used by FASTDEBUG. We also want all the
# debug info in one place (-xs).
#
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
ifeq ($(VARIANT), OPT)
CC_OPT = -g -xs $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
CXX_OPT = -g0 -xs $(CXX_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL))
endif
CFLAGS_DEBUG_OPTION += -xs
CXXFLAGS_DEBUG_OPTION += -xs
endif
endif
CFLAGS_COMMON = -L$(OBJDIR) CFLAGS_COMMON = -L$(OBJDIR)
# Do not allow C99 language features like declarations in code etc. # Do not allow C99 language features like declarations in code etc.
......
...@@ -113,9 +113,7 @@ _JUNK_ := $(shell \ ...@@ -113,9 +113,7 @@ _JUNK_ := $(shell \
echo >&2 "INFO: ENABLE_FULL_DEBUG_SYMBOLS=$(ENABLE_FULL_DEBUG_SYMBOLS)") echo >&2 "INFO: ENABLE_FULL_DEBUG_SYMBOLS=$(ENABLE_FULL_DEBUG_SYMBOLS)")
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
# HACK: disable ZIP_DEBUGINFO_FILES by default until install repo ZIP_DEBUGINFO_FILES ?= 1
# changes are promoted
ZIP_DEBUGINFO_FILES ?= 0
else else
ZIP_DEBUGINFO_FILES=0 ZIP_DEBUGINFO_FILES=0
endif endif
......
...@@ -181,8 +181,17 @@ $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf ...@@ -181,8 +181,17 @@ $(ACTUAL_LIBRARY):: $(OBJDIR)/$(LIBRARY).lcf
$(CP) $(OBJDIR)/$(@F) $@ $(CP) $(OBJDIR)/$(@F) $@
@$(call binary_file_verification,$@) @$(call binary_file_verification,$@)
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(ZIP_DEBUGINFO_FILES),1)
(set -e ; \
$(CD) $(OBJDIR) ; \
$(ZIPEXE) -q $(LIBRARY).diz $(LIBRARY).map $(LIBRARY).pdb ; \
)
$(CP) $(OBJDIR)/$(LIBRARY).diz $(@D)
$(RM) $(OBJDIR)/$(LIBRARY).map $(OBJDIR)/$(LIBRARY).pdb
else
$(CP) $(OBJDIR)/$(LIBRARY).map $(@D) $(CP) $(OBJDIR)/$(LIBRARY).map $(@D)
$(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D) $(CP) $(OBJDIR)/$(LIBRARY).pdb $(@D)
endif
endif endif
endif # LIBRARY endif # LIBRARY
...@@ -248,6 +257,37 @@ else # LIBRARY ...@@ -248,6 +257,37 @@ else # LIBRARY
ifeq ($(WRITE_LIBVERSION),true) ifeq ($(WRITE_LIBVERSION),true)
$(MCS) -d -a "$(FULL_VERSION)" $@ $(MCS) -d -a "$(FULL_VERSION)" $@
endif # WRITE_LIBVERSION endif # WRITE_LIBVERSION
ifneq ($(PLATFORM), macosx)
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
(set -e ; \
$(CD) $(@D) ; \
$(OBJCOPY) --only-keep-debug $(@F) $(LIBRARY).debuginfo ; \
$(OBJCOPY) --add-gnu-debuglink=$(LIBRARY).debuginfo $(@F) ; \
)
ifeq ($(STRIP_POLICY),all_strip)
$(STRIP) $@
else
ifeq ($(STRIP_POLICY),min_strip)
ifeq ($(PLATFORM), solaris)
$(STRIP) -x $@
else
# assume Linux
$(STRIP) -g $@
endif
# implied else here is no stripping at all
endif
endif
ifeq ($(ZIP_DEBUGINFO_FILES),1)
(set -e ; \
$(CD) $(@D) ; \
$(ZIPEXE) -q $(LIBRARY).diz $(LIBRARY).debuginfo ; \
$(RM) $(LIBRARY).debuginfo ; \
)
endif
endif # LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS
endif # ENABLE_FULL_DEBUG_SYMBOLS
endif # PLATFORM-!macosx
endif # LIBRARY endif # LIBRARY
endif # PLATFORM endif # PLATFORM
......
...@@ -189,6 +189,15 @@ endif ...@@ -189,6 +189,15 @@ endif
$(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1 $(MT) /manifest $(OBJDIR)/$(PROGRAM).exe.manifest /outputresource:$@;#1
endif endif
@$(call binary_file_verification,$@) @$(call binary_file_verification,$@)
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(ZIP_DEBUGINFO_FILES),1)
(set -e ; \
$(CD) $(OBJDIR) ; \
$(ZIPEXE) -q $(PROGRAM).diz $(PROGRAM).map $(PROGRAM).pdb ; \
$(RM) $(PROGRAM).map $(PROGRAM).pdb ; \
)
endif
endif
else else
# #
# Note that we have to link -lthread even when USE_PTHREADS is true. # Note that we have to link -lthread even when USE_PTHREADS is true.
...@@ -232,6 +241,42 @@ else ...@@ -232,6 +241,42 @@ else
-codesign -s openjdk_codesign $@ -codesign -s openjdk_codesign $@
endif endif
@$(call binary_file_verification,$@) @$(call binary_file_verification,$@)
ifneq ($(PLATFORM), macosx)
ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
ifeq ($(PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS),1)
(set -e ; \
$(CD) $(@D) ; \
$(OBJCOPY) --only-keep-debug $(@F) $(@F).debuginfo ; \
$(OBJCOPY) --add-gnu-debuglink=$(@F).debuginfo $(@F) ; \
)
ifeq ($(STRIP_POLICY),all_strip)
$(STRIP) $@
else
ifeq ($(STRIP_POLICY),min_strip)
ifeq ($(PLATFORM), solaris)
$(STRIP) -x $@
else
# assume Linux
$(STRIP) -g $@
endif
# implied else here is no stripping at all
endif
endif
ifeq ($(ZIP_DEBUGINFO_FILES),1)
(set -e ; \
$(CD) $(@D) ; \
$(ZIPEXE) -q $(@F).diz $(@F).debuginfo ; \
$(RM) $(@F).debuginfo ; \
)
# save ZIP'ed debug info with rest of the program's build artifacts
$(MV) $@.diz $(OBJDIR)
else
# save debug info with rest of the program's build artifacts
$(MV) $@.debuginfo $(OBJDIR)
endif
endif # PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS
endif # ENABLE_FULL_DEBUG_SYMBOLS
endif # PLATFORM-!macosx
endif # PLATFORM endif # PLATFORM
clean:: clean::
...@@ -240,12 +285,16 @@ ifeq ($(PLATFORM), windows) ...@@ -240,12 +285,16 @@ ifeq ($(PLATFORM), windows)
$(RM) $(OBJDIR)/$(PROGRAM).ico $(RM) $(OBJDIR)/$(PROGRAM).ico
$(RM) $(OBJDIR)/$(PROGRAM).lcf $(RM) $(OBJDIR)/$(PROGRAM).lcf
$(RM) $(OBJDIR)/$(PROGRAM).map $(RM) $(OBJDIR)/$(PROGRAM).map
$(RM) $(OBJDIR)/$(PROGRAM).pdb
$(RM) $(OBJDIR)/$(PROGRAM).exp $(RM) $(OBJDIR)/$(PROGRAM).exp
$(RM) $(OBJDIR)/$(PROGRAM).lib $(RM) $(OBJDIR)/$(PROGRAM).lib
$(RM) $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX) $(RM) $(OBJDIR)/$(PROGRAM)$(EXE_SUFFIX)
$(RM) $(OBJDIR)/$(PROGRAM).ilk $(RM) $(OBJDIR)/$(PROGRAM).ilk
$(RM) *.pdb $(RM) *.pdb
else
$(RM) $(OBJDIR)/$(PROGRAM).debuginfo
endif endif
$(RM) $(OBJDIR)/$(PROGRAM).diz
clobber:: clobber::
......
...@@ -873,7 +873,9 @@ ifeq ($(PLATFORM), windows) ...@@ -873,7 +873,9 @@ ifeq ($(PLATFORM), windows)
-o -name \*.dll | $(EGREP) -v -i "$(MSVCRNN_DLL)" > $@ -o -name \*.dll | $(EGREP) -v -i "$(MSVCRNN_DLL)" > $@
else else
$(FIND) $(JRE_IMAGE_DIR)/lib -type f -name \*.$(LIB_SUFFIX) >> $@ $(FIND) $(JRE_IMAGE_DIR)/lib -type f -name \*.$(LIB_SUFFIX) >> $@
$(FILE) `$(FIND) $(JRE_IMAGE_DIR)/bin -type f -name \*$(EXE_SUFFIX)` \ # The FILE command reports .debuginfo files as "ELF", but we don't want
# those files in the JRE_BIN_LIST file. EXE_SUFFIX is empty on non-Windows.
$(FILE) `$(FIND) $(JRE_IMAGE_DIR)/bin -type f ! -name '*.debuginfo' -name \*$(EXE_SUFFIX)` \
| $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@ | $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@
endif endif
...@@ -1140,9 +1142,11 @@ ifeq ($(PLATFORM), windows) ...@@ -1140,9 +1142,11 @@ ifeq ($(PLATFORM), windows)
else else
$(RM) $@ $(RM) $@
$(FIND) $(JDK_IMAGE_DIR)/jre/lib -type f -name \*.$(LIB_SUFFIX) >> $@ $(FIND) $(JDK_IMAGE_DIR)/jre/lib -type f -name \*.$(LIB_SUFFIX) >> $@
$(FILE) `$(FIND) $(JDK_IMAGE_DIR)/jre/bin -type f -name \*$(EXE_SUFFIX)` \ # The FILE command reports .debuginfo files as "ELF", but we don't want
# those files in the JDK_BIN_LIST file. EXE_SUFFIX is empty on non-Windows.
$(FILE) `$(FIND) $(JDK_IMAGE_DIR)/jre/bin -type f ! -name '*.debuginfo' -name \*$(EXE_SUFFIX)` \
| $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@ | $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@
file `$(FIND) $(JDK_IMAGE_DIR)/bin -type f -name \*$(EXE_SUFFIX)` \ file `$(FIND) $(JDK_IMAGE_DIR)/bin -type f ! -name '*.debuginfo' -name \*$(EXE_SUFFIX)` \
| $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@ | $(EGREP) 'ELF' | $(CUT) -d':' -f1 >> $@
endif endif
......
# #
# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
# Makefile for building the Java Programming Language Instrumentation Services # Makefile for building the Java Programming Language Instrumentation Services
# agent, supporting java.lang.instrument # agent, supporting java.lang.instrument
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
PACKAGE = sun.instrument PACKAGE = sun.instrument
LIBRARY = instrument LIBRARY = instrument
......
...@@ -36,7 +36,7 @@ include $(BUILDDIR)/common/Defs.gmk ...@@ -36,7 +36,7 @@ include $(BUILDDIR)/common/Defs.gmk
# #
# Files to compile. # Files to compile.
# #
AUTO_FILES_JAVA_DIRS = java/lang/reflect sun/reflect AUTO_FILES_JAVA_DIRS = java/lang/reflect sun/reflect java/lang/annotation
# #
# Install .lib file. # Install .lib file.
......
# #
# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
LIBRARY = java_crw_demo LIBRARY = java_crw_demo
......
# #
# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
LIBRARY = hprof LIBRARY = hprof
PRODUCT = sun PRODUCT = sun
......
# #
# Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PROGRAM = java PROGRAM = java
PRODUCT = java PRODUCT = java
......
# #
# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
PACKAGE = java.lang.management PACKAGE = java.lang.management
LIBRARY = management LIBRARY = management
......
# #
# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
# It's currently used by jpda and hprof. Put it in base module for now. # It's currently used by jpda and hprof. Put it in base module for now.
......
# #
# Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# Build libverify.so # Build libverify.so
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
PRODUCT = java PRODUCT = java
LIBRARY = verify LIBRARY = verify
......
# #
# Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# Makefile for building JDWP # Makefile for building JDWP
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../.. BUILDDIR = ../..
PACKAGE = com.sun.tools.jdwp PACKAGE = com.sun.tools.jdwp
PRODUCT = jpda PRODUCT = jpda
......
# #
# Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# Makefile for building the JDI back-end implementation # Makefile for building the JDI back-end implementation
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
LIBRARY = dt_socket LIBRARY = dt_socket
PRODUCT = jbug PRODUCT = jbug
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# Makefile for building simple launchers # Makefile for building simple launchers
# #
PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = .. BUILDDIR = ..
PACKAGE = launcher PACKAGE = launcher
PRODUCT = sun PRODUCT = sun
......
# #
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = compiledMethodLoad DEMONAME = compiledMethodLoad
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = gctest DEMONAME = gctest
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = heapTracker DEMONAME = heapTracker
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = heapViewer DEMONAME = heapViewer
......
# #
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = hprof DEMONAME = hprof
......
# #
# Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = minst DEMONAME = minst
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = mtrace DEMONAME = mtrace
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = versionCheck DEMONAME = versionCheck
......
# #
# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
# questions. # questions.
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PRODUCT = demo/jvmti PRODUCT = demo/jvmti
DEMONAME = waiters DEMONAME = waiters
......
...@@ -62,7 +62,7 @@ FILES_export = \ ...@@ -62,7 +62,7 @@ FILES_export = \
java/text/Bidi.java \ java/text/Bidi.java \
sun/font/FileFont.java \ sun/font/FileFont.java \
sun/font/FileFontStrike.java \ sun/font/FileFontStrike.java \
sun/font/FontManager.java \ sun/font/SunFontManager.java \
sun/font/GlyphList.java \ sun/font/GlyphList.java \
sun/font/NativeFont.java \ sun/font/NativeFont.java \
sun/font/StrikeCache.java \ sun/font/StrikeCache.java \
......
...@@ -52,7 +52,6 @@ include FILES_c.gmk ...@@ -52,7 +52,6 @@ include FILES_c.gmk
FILES_export = \ FILES_export = \
java/awt/Font.java \ java/awt/Font.java \
sun/font/FileFont.java \ sun/font/FileFont.java \
sun/font/FontManager.java \
sun/font/GlyphList.java \ sun/font/GlyphList.java \
sun/font/NativeFont.java \ sun/font/NativeFont.java \
sun/font/StrikeCache.java \ sun/font/StrikeCache.java \
......
# #
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
# #
# Makefile for building dtrace extension # Makefile for building dtrace extension
# #
LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS=1
BUILDDIR = ../../.. BUILDDIR = ../../..
PACKAGE = sun.tracing.dtrace PACKAGE = sun.tracing.dtrace
LIBRARY = jsdt LIBRARY = jsdt
......
...@@ -213,16 +213,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -213,16 +213,8 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
SwingUtilities3.setDelegateRepaintManager(delegate, new RepaintManager() { SwingUtilities3.setDelegateRepaintManager(delegate, new RepaintManager() {
@Override @Override
public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) { public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) {
if (SunToolkit.isDispatchThreadForAppContext(getTarget())) { repaintPeer(SwingUtilities.convertRectangle(
synchronized (getDelegateLock()) { c, new Rectangle(x, y, w, h), getDelegate()));
if (getDelegate().isPaintingForPrint()) {
return;
}
}
}
Rectangle res = SwingUtilities.convertRectangle(
c, new Rectangle(x, y, w, h), getDelegate());
repaintPeer(res);
} }
}); });
} }
...@@ -616,6 +608,17 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -616,6 +608,17 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
windowLocation.y + locationInWindow.y); windowLocation.y + locationInWindow.y);
} }
/**
* Returns the cursor of the peer, which is cursor of the target by default,
* but peer can override this behavior.
*
* @param p Point relative to the peer.
* @return Cursor of the peer or null if default cursor should be used.
*/
protected Cursor getCursor(final Point p) {
return getTarget().getCursor();
}
@Override @Override
public void setBackground(final Color c) { public void setBackground(final Color c) {
final Color oldBg = getBackground(); final Color oldBg = getBackground();
...@@ -982,16 +985,23 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -982,16 +985,23 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
// DropTargetPeer Method // DropTargetPeer Method
@Override @Override
public void addDropTarget(DropTarget dt) { public void addDropTarget(DropTarget dt) {
synchronized (dropTargetLock){ LWWindowPeer winPeer = getWindowPeerOrSelf();
// 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only if (winPeer != null && winPeer != this) {
// if it's the first (or last) one for the component. Otherwise this call is a no-op. // We need to register the DropTarget in the
if (++fNumDropTargets == 1) { // peer of the window ancestor of the component
// Having a non-null drop target would be an error but let's check just in case: winPeer.addDropTarget(dt);
if (fDropTarget != null) } else {
System.err.println("CComponent.addDropTarget(): current drop target is non-null."); synchronized (dropTargetLock) {
// 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
// Create a new drop target: // if it's the first (or last) one for the component. Otherwise this call is a no-op.
fDropTarget = CDropTarget.createDropTarget(dt, target, this); if (++fNumDropTargets == 1) {
// Having a non-null drop target would be an error but let's check just in case:
if (fDropTarget != null)
System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
// Create a new drop target:
fDropTarget = CDropTarget.createDropTarget(dt, target, this);
}
} }
} }
} }
...@@ -999,17 +1009,24 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -999,17 +1009,24 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
// DropTargetPeer Method // DropTargetPeer Method
@Override @Override
public void removeDropTarget(DropTarget dt) { public void removeDropTarget(DropTarget dt) {
synchronized (dropTargetLock){ LWWindowPeer winPeer = getWindowPeerOrSelf();
// 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only if (winPeer != null && winPeer != this) {
// if it's the first (or last) one for the component. Otherwise this call is a no-op. // We need to unregister the DropTarget in the
if (--fNumDropTargets == 0) { // peer of the window ancestor of the component
// Having a null drop target would be an error but let's check just in case: winPeer.removeDropTarget(dt);
if (fDropTarget != null) { } else {
// Dispose of the drop target: synchronized (dropTargetLock){
fDropTarget.dispose(); // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
fDropTarget = null; // if it's the first (or last) one for the component. Otherwise this call is a no-op.
} else if (--fNumDropTargets == 0) {
System.err.println("CComponent.removeDropTarget(): current drop target is null."); // Having a null drop target would be an error but let's check just in case:
if (fDropTarget != null) {
// Dispose of the drop target:
fDropTarget.dispose();
fDropTarget = null;
} else
System.err.println("CComponent.removeDropTarget(): current drop target is null.");
}
} }
} }
} }
......
...@@ -36,32 +36,34 @@ import sun.awt.SunToolkit; ...@@ -36,32 +36,34 @@ import sun.awt.SunToolkit;
public abstract class LWCursorManager { public abstract class LWCursorManager {
// A flag to indicate if the update is scheduled, so we don't /**
// process it twice * A flag to indicate if the update is scheduled, so we don't process it
private AtomicBoolean updatePending = new AtomicBoolean(false); * twice.
*/
private final AtomicBoolean updatePending = new AtomicBoolean(false);
protected LWCursorManager() { protected LWCursorManager() {
} }
/* /**
* Sets the cursor to correspond the component currently under mouse. * Sets the cursor to correspond the component currently under mouse.
* *
* This method should not be executed on the toolkit thread as it * This method should not be executed on the toolkit thread as it
* calls to user code (e.g. Container.findComponentAt). * calls to user code (e.g. Container.findComponentAt).
*/ */
public void updateCursor() { public final void updateCursor() {
updatePending.set(false); updatePending.set(false);
updateCursorImpl(); updateCursorImpl();
} }
/* /**
* Schedules updating the cursor on the corresponding event dispatch * Schedules updating the cursor on the corresponding event dispatch
* thread for the given window. * thread for the given window.
* *
* This method is called on the toolkit thread as a result of a * This method is called on the toolkit thread as a result of a
* native update cursor request (e.g. WM_SETCURSOR on Windows). * native update cursor request (e.g. WM_SETCURSOR on Windows).
*/ */
public void updateCursorLater(LWWindowPeer window) { public final void updateCursorLater(final LWWindowPeer window) {
if (updatePending.compareAndSet(false, true)) { if (updatePending.compareAndSet(false, true)) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
...@@ -74,45 +76,58 @@ public abstract class LWCursorManager { ...@@ -74,45 +76,58 @@ public abstract class LWCursorManager {
} }
private void updateCursorImpl() { private void updateCursorImpl() {
LWWindowPeer windowUnderCursor = LWWindowPeer.getWindowUnderCursor(); final Point cursorPos = getCursorPosition();
Point cursorPos = getCursorPosition(); final Component c = findComponent(cursorPos);
LWComponentPeer<?, ?> componentUnderCursor = null; final Cursor cursor;
// TODO: it's possible to get the component under cursor directly as final Object peer = LWToolkit.targetToPeer(c);
// it's stored in LWWindowPee anyway (lastMouseEventPeer) if (peer instanceof LWComponentPeer) {
if (windowUnderCursor != null) { final LWComponentPeer<?, ?> lwpeer = (LWComponentPeer<?, ?>) peer;
componentUnderCursor = windowUnderCursor.findPeerAt(cursorPos.x, cursorPos.y); final Point p = lwpeer.getLocationOnScreen();
cursor = lwpeer.getCursor(new Point(cursorPos.x - p.x,
cursorPos.y - p.y));
} else {
cursor = (c != null) ? c.getCursor() : null;
} }
Cursor cursor = null; // TODO: default cursor for modal blocked windows
if (componentUnderCursor != null) { setCursor(cursor);
Component c = componentUnderCursor.getTarget(); }
/**
* Returns the first visible, enabled and showing component under cursor.
*
* @param cursorPos Current cursor position.
* @return Component
*/
private static final Component findComponent(final Point cursorPos) {
final LWComponentPeer<?, ?> peer = LWWindowPeer.getPeerUnderCursor();
Component c = null;
if (peer != null) {
c = peer.getTarget();
if (c instanceof Container) { if (c instanceof Container) {
Point p = componentUnderCursor.getLocationOnScreen(); final Point p = peer.getLocationOnScreen();
c = ((Container)c).findComponentAt(cursorPos.x - p.x, cursorPos.y - p.y); c = ((Container) c).findComponentAt(cursorPos.x - p.x,
cursorPos.y - p.y);
} }
// Traverse up to the first visible, enabled and showing component
while (c != null) { while (c != null) {
if (c.isVisible() && c.isEnabled() && (c.getPeer() != null)) { if (c.isVisible() && c.isEnabled() && (c.getPeer() != null)) {
break; break;
} }
c = c.getParent(); c = c.getParent();
} }
if (c != null) {
cursor = c.getCursor();
}
} }
// TODO: default cursor for modal blocked windows return c;
setCursor(windowUnderCursor, cursor);
} }
/* /**
* Returns the current cursor position. * Returns the current cursor position.
*/ */
// TODO: make it public to reuse for MouseInfo // TODO: make it public to reuse for MouseInfo
protected abstract Point getCursorPosition(); protected abstract Point getCursorPosition();
/* /**
* Sets a cursor. The cursor can be null if the mouse is not over a Java window. * Sets a cursor. The cursor can be null if the mouse is not over a Java
* window.
* @param cursor the new {@code Cursor}.
*/ */
protected abstract void setCursor(LWWindowPeer windowUnderCursor, Cursor cursor); protected abstract void setCursor(Cursor cursor);
} }
...@@ -39,12 +39,8 @@ final class LWRepaintArea extends RepaintArea { ...@@ -39,12 +39,8 @@ final class LWRepaintArea extends RepaintArea {
@Override @Override
protected void updateComponent(final Component comp, final Graphics g) { protected void updateComponent(final Component comp, final Graphics g) {
if (comp != null) { if (comp != null) {
final LWComponentPeer peer = (LWComponentPeer) comp.getPeer();
if (peer != null) {
peer.paintPeer(g);
}
super.updateComponent(comp, g); super.updateComponent(comp, g);
flushBuffers(peer); flushBuffers((LWComponentPeer) comp.getPeer());
} }
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
package sun.lwawt; package sun.lwawt;
import java.awt.Component; import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.TextArea; import java.awt.TextArea;
...@@ -71,6 +72,15 @@ final class LWTextAreaPeer ...@@ -71,6 +72,15 @@ final class LWTextAreaPeer
return getDelegate().getView(); return getDelegate().getView();
} }
@Override
protected Cursor getCursor(final Point p) {
final boolean isContains;
synchronized (getDelegateLock()) {
isContains = getDelegate().getViewport().getBounds().contains(p);
}
return isContains ? super.getCursor(p) : null;
}
@Override @Override
protected Component getDelegateFocusOwner() { protected Component getDelegateFocusOwner() {
return getTextComponent(); return getTextComponent();
......
...@@ -31,6 +31,7 @@ import java.awt.Point; ...@@ -31,6 +31,7 @@ import java.awt.Point;
import java.awt.TextField; import java.awt.TextField;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.peer.TextFieldPeer; import java.awt.peer.TextFieldPeer;
import javax.swing.JPasswordField; import javax.swing.JPasswordField;
...@@ -97,6 +98,21 @@ final class LWTextFieldPeer ...@@ -97,6 +98,21 @@ final class LWTextFieldPeer
getText(), e.getWhen(), e.getModifiers())); getText(), e.getWhen(), e.getModifiers()));
} }
/**
* Restoring native behavior. We should sets the selection range to zero,
* when component lost its focus.
*
* @param e the focus event
*/
@Override
protected void handleJavaFocusEvent(final FocusEvent e) {
if (e.getID() == FocusEvent.FOCUS_LOST) {
// In order to de-select the selection
setCaretPosition(0);
}
super.handleJavaFocusEvent(e);
}
private final class JTextAreaDelegate extends JPasswordField { private final class JTextAreaDelegate extends JPasswordField {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
......
...@@ -784,9 +784,8 @@ public class LWWindowPeer ...@@ -784,9 +784,8 @@ public class LWWindowPeer
} }
mouseClickButtons &= ~eventButtonMask; mouseClickButtons &= ~eventButtonMask;
} }
notifyUpdateCursor();
} }
notifyUpdateCursor();
} }
public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers, public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
...@@ -1057,6 +1056,10 @@ public class LWWindowPeer ...@@ -1057,6 +1056,10 @@ public class LWWindowPeer
return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null; return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
} }
public static LWComponentPeer<?, ?> getPeerUnderCursor() {
return lastMouseEventPeer;
}
public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
if (focusLog.isLoggable(PlatformLogger.FINE)) { if (focusLog.isLoggable(PlatformLogger.FINE)) {
focusLog.fine("requesting native focus to " + this); focusLog.fine("requesting native focus to " + this);
......
...@@ -25,24 +25,26 @@ ...@@ -25,24 +25,26 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.awt.*; import sun.lwawt.LWCursorManager;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import sun.lwawt.*; final class CCursorManager extends LWCursorManager {
public class CCursorManager extends LWCursorManager {
private static native Point2D nativeGetCursorPosition(); private static native Point2D nativeGetCursorPosition();
private static native void nativeSetBuiltInCursor(final int type, final String name); private static native void nativeSetBuiltInCursor(final int type, final String name);
private static native void nativeSetCustomCursor(final long imgPtr, final double x, final double y); private static native void nativeSetCustomCursor(final long imgPtr, final double x, final double y);
private static final int NAMED_CURSOR = -1; private static final int NAMED_CURSOR = -1;
private final static CCursorManager theInstance = new CCursorManager(); private static final CCursorManager theInstance = new CCursorManager();
public static CCursorManager getInstance() { public static CCursorManager getInstance() {
return theInstance; return theInstance;
} }
Cursor currentCursor; private volatile Cursor currentCursor;
private CCursorManager() { } private CCursorManager() { }
...@@ -62,8 +64,11 @@ public class CCursorManager extends LWCursorManager { ...@@ -62,8 +64,11 @@ public class CCursorManager extends LWCursorManager {
} }
@Override @Override
protected void setCursor(final LWWindowPeer windowUnderCursor, final Cursor cursor) { protected void setCursor(final Cursor cursor) {
if (cursor == currentCursor) return; if (cursor == currentCursor) {
return;
}
currentCursor = cursor;
if (cursor == null) { if (cursor == null) {
nativeSetBuiltInCursor(Cursor.DEFAULT_CURSOR, null); nativeSetBuiltInCursor(Cursor.DEFAULT_CURSOR, null);
...@@ -71,10 +76,12 @@ public class CCursorManager extends LWCursorManager { ...@@ -71,10 +76,12 @@ public class CCursorManager extends LWCursorManager {
} }
if (cursor instanceof CCustomCursor) { if (cursor instanceof CCustomCursor) {
final CCustomCursor customCursor = ((CCustomCursor)cursor); final CCustomCursor customCursor = (CCustomCursor) cursor;
final long imagePtr = customCursor.getImageData(); final long imagePtr = customCursor.getImageData();
final Point hotSpot = customCursor.getHotSpot(); if (imagePtr != 0L) {
if(imagePtr != 0L) nativeSetCustomCursor(imagePtr, hotSpot.x, hotSpot.y); final Point hotSpot = customCursor.getHotSpot();
nativeSetCustomCursor(imagePtr, hotSpot.x, hotSpot.y);
}
return; return;
} }
...@@ -94,13 +101,6 @@ public class CCursorManager extends LWCursorManager { ...@@ -94,13 +101,6 @@ public class CCursorManager extends LWCursorManager {
throw new RuntimeException("Unimplemented"); throw new RuntimeException("Unimplemented");
} }
static long getNativeWindow(final LWWindowPeer window) {
if (window == null) return 0;
final CPlatformWindow platformWindow = (CPlatformWindow)window.getPlatformWindow();
if (platformWindow == null) return 0;
return platformWindow.getNSWindowPtr();
}
// package private methods to handle cursor change during drag-and-drop // package private methods to handle cursor change during drag-and-drop
private boolean isDragging = false; private boolean isDragging = false;
private Point dragPos = null; private Point dragPos = null;
...@@ -109,9 +109,7 @@ public class CCursorManager extends LWCursorManager { ...@@ -109,9 +109,7 @@ public class CCursorManager extends LWCursorManager {
if (isDragging) { if (isDragging) {
throw new RuntimeException("Invalid Drag state in CCursorManager!"); throw new RuntimeException("Invalid Drag state in CCursorManager!");
} }
isDragging = true; isDragging = true;
dragPos = new Point(x, y); dragPos = new Point(x, y);
} }
......
...@@ -88,13 +88,20 @@ public class CEmbeddedFrame extends EmbeddedFrame { ...@@ -88,13 +88,20 @@ public class CEmbeddedFrame extends EmbeddedFrame {
responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY); responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY);
} }
public void handleKeyEvent(int eventType, int modifierFlags, String characters,
String charsIgnoringMods, boolean isRepeat, short keyCode,
boolean needsKeyTyped) {
responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode, needsKeyTyped);
}
// REMIND: delete this method once 'deploy' changes for 7156194 is pushed
public void handleKeyEvent(int eventType, int modifierFlags, String characters, public void handleKeyEvent(int eventType, int modifierFlags, String characters,
String charsIgnoringMods, boolean isRepeat, short keyCode) { String charsIgnoringMods, boolean isRepeat, short keyCode) {
responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode); handleKeyEvent(eventType, modifierFlags, characters, charsIgnoringMods, isRepeat, keyCode, true);
} }
public void handleInputEvent(String text) { public void handleInputEvent(String text) {
new RuntimeException("Not implemented"); responder.handleInputEvent(text);
} }
public void handleFocusEvent(boolean focused) { public void handleFocusEvent(boolean focused) {
......
...@@ -29,10 +29,14 @@ import java.awt.*; ...@@ -29,10 +29,14 @@ import java.awt.*;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.awt.image.*; import java.awt.image.*;
import java.util.Arrays;
import java.util.List;
import sun.awt.image.SunWritableRaster; import sun.awt.image.SunWritableRaster;
public class CImage extends CFRetainedResource { public class CImage extends CFRetainedResource {
private static native long nativeCreateNSImageFromArray(int[] buffer, int w, int h); private static native long nativeCreateNSImageFromArray(int[] buffer, int w, int h);
private static native long nativeCreateNSImageFromArrays(int[][] buffers, int w[], int h[]);
private static native long nativeCreateNSImageFromFileContents(String file); private static native long nativeCreateNSImageFromFileContents(String file);
private static native long nativeCreateNSImageOfFileFromLaunchServices(String file); private static native long nativeCreateNSImageOfFileFromLaunchServices(String file);
private static native long nativeCreateNSImageFromImageName(String name); private static native long nativeCreateNSImageFromImageName(String name);
...@@ -93,8 +97,7 @@ public class CImage extends CFRetainedResource { ...@@ -93,8 +97,7 @@ public class CImage extends CFRetainedResource {
return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name)); return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name));
} }
// This is used to create a CImage from a Image private static int[] imageToArray(Image image) {
public CImage createFromImage(final Image image) {
if (image == null) return null; if (image == null) return null;
MediaTracker mt = new MediaTracker(new Label()); MediaTracker mt = new MediaTracker(new Label());
...@@ -117,8 +120,50 @@ public class CImage extends CFRetainedResource { ...@@ -117,8 +120,50 @@ public class CImage extends CFRetainedResource {
g2.setComposite(AlphaComposite.Src); g2.setComposite(AlphaComposite.Src);
g2.drawImage(image, 0, 0, null); g2.drawImage(image, 0, 0, null);
g2.dispose(); g2.dispose();
int[] buffer = ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData(); return ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData();
return new CImage(nativeCreateNSImageFromArray(buffer, w, h)); }
// This is used to create a CImage from a Image
public CImage createFromImage(final Image image) {
int[] buffer = imageToArray(image);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
public CImage createFromImages(List<Image> images) {
if (images == null || images.isEmpty()) {
return null;
}
int num = images.size();
int[][] buffers = new int[num][];
int[] w = new int[num];
int[] h = new int[num];
num = 0;
for (Image img : images) {
buffers[num] = imageToArray(img);
if (buffers[num] == null) {
// Unable to process the image
continue;
}
w[num] = img.getWidth(null);
h[num] = img.getHeight(null);
num++;
}
if (num == 0) {
return null;
}
return new CImage(nativeCreateNSImageFromArrays(
Arrays.copyOf(buffers, num),
Arrays.copyOf(w, num),
Arrays.copyOf(h, num)));
} }
static int getSelectorAsInt(final String fromString) { static int getSelectorAsInt(final String fromString) {
......
...@@ -117,7 +117,7 @@ final class CPlatformResponder { ...@@ -117,7 +117,7 @@ final class CPlatformResponder {
* Handles key events. * Handles key events.
*/ */
void handleKeyEvent(int eventType, int modifierFlags, String chars, void handleKeyEvent(int eventType, int modifierFlags, String chars,
short keyCode) { short keyCode, boolean needsKeyTyped) {
boolean isFlagsChangedEvent = boolean isFlagsChangedEvent =
isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) : isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) :
(eventType == CocoaConstants.NSFlagsChanged); (eventType == CocoaConstants.NSFlagsChanged);
...@@ -158,11 +158,24 @@ final class CPlatformResponder { ...@@ -158,11 +158,24 @@ final class CPlatformResponder {
NSEvent.nsToJavaEventType(eventType); NSEvent.nsToJavaEventType(eventType);
} }
char javaChar = NSEvent.nsToJavaChar(testChar, modifierFlags);
// Some keys may generate a KEY_TYPED, but we can't determine
// what that character is. That's likely a bug, but for now we
// just check for CHAR_UNDEFINED.
if (javaChar == KeyEvent.CHAR_UNDEFINED) {
postsTyped = false;
}
int jmodifiers = NSEvent.nsToJavaKeyModifiers(modifierFlags); int jmodifiers = NSEvent.nsToJavaKeyModifiers(modifierFlags);
long when = System.currentTimeMillis(); long when = System.currentTimeMillis();
peer.dispatchKeyEvent(jeventType, when, jmodifiers, peer.dispatchKeyEvent(jeventType, when, jmodifiers,
jkeyCode, testChar, jkeyLocation); jkeyCode, javaChar, jkeyLocation);
// Current browser may be sending input events, so don't
// post the KEY_TYPED here.
postsTyped &= needsKeyTyped;
// That's the reaction on the PRESSED (not RELEASED) event as it comes to // That's the reaction on the PRESSED (not RELEASED) event as it comes to
// appear in MacOSX. // appear in MacOSX.
...@@ -172,8 +185,23 @@ final class CPlatformResponder { ...@@ -172,8 +185,23 @@ final class CPlatformResponder {
boolean isMetaDown = (jmodifiers & KeyEvent.META_DOWN_MASK) != 0; boolean isMetaDown = (jmodifiers & KeyEvent.META_DOWN_MASK) != 0;
if (jeventType == KeyEvent.KEY_PRESSED && postsTyped && !isMetaDown) { if (jeventType == KeyEvent.KEY_PRESSED && postsTyped && !isMetaDown) {
peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, when, jmodifiers, peer.dispatchKeyEvent(KeyEvent.KEY_TYPED, when, jmodifiers,
KeyEvent.VK_UNDEFINED, testChar, KeyEvent.VK_UNDEFINED, javaChar,
KeyEvent.KEY_LOCATION_UNKNOWN); KeyEvent.KEY_LOCATION_UNKNOWN);
} }
} }
void handleInputEvent(String text) {
if (text != null) {
int index = 0, length = text.length();
char c;
while (index < length) {
c = text.charAt(index);
peer.dispatchKeyEvent(KeyEvent.KEY_TYPED,
System.currentTimeMillis(),
0, KeyEvent.VK_UNDEFINED, c,
KeyEvent.KEY_LOCATION_UNKNOWN);
index++;
}
}
}
} }
...@@ -199,7 +199,7 @@ public class CPlatformView extends CFRetainedResource { ...@@ -199,7 +199,7 @@ public class CPlatformView extends CFRetainedResource {
private void deliverKeyEvent(NSEvent event) { private void deliverKeyEvent(NSEvent event) {
responder.handleKeyEvent(event.getType(), event.getModifierFlags(), responder.handleKeyEvent(event.getType(), event.getModifierFlags(),
event.getCharactersIgnoringModifiers(), event.getKeyCode()); event.getCharactersIgnoringModifiers(), event.getKeyCode(), true);
} }
private void deliverWindowDidExposeEvent() { private void deliverWindowDidExposeEvent() {
......
...@@ -661,11 +661,19 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -661,11 +661,19 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public void setResizable(boolean resizable) { public void setResizable(boolean resizable) {
setStyleBits(RESIZABLE, resizable); setStyleBits(RESIZABLE, resizable);
// Re-apply the size constraints and the size to ensure the space
// occupied by the grow box is counted properly
setMinimumSize(1, 1); // the method ignores its arguments
Rectangle bounds = peer.getBounds();
setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
} }
@Override @Override
public void setMinimumSize(int width, int height) { public void setMinimumSize(int width, int height) {
//TODO width, height should be used //TODO width, height should be used
//NOTE: setResizable() calls setMinimumSize(1,1) relaying on the logic below
final long nsWindowPtr = getNSWindowPtr(); final long nsWindowPtr = getNSWindowPtr();
final Dimension min = target.getMinimumSize(); final Dimension min = target.getMinimumSize();
final Dimension max = target.getMaximumSize(); final Dimension max = target.getMaximumSize();
...@@ -802,11 +810,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -802,11 +810,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (icons == null || icons.size() == 0) { if (icons == null || icons.size() == 0) {
return null; return null;
} }
return CImage.getCreator().createFromImages(icons);
// TODO: need a walk-through to find the best image.
// The best mean with higher resolution. Otherwise an icon looks bad.
final Image image = icons.get(0);
return CImage.getCreator().createFromImage(image);
} }
/* /*
......
...@@ -647,6 +647,15 @@ public class LWCToolkit extends LWToolkit { ...@@ -647,6 +647,15 @@ public class LWCToolkit extends LWToolkit {
return InputEvent.CTRL_MASK | InputEvent.ALT_MASK; return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
} }
/**
* Tests whether specified key modifiers mask can be used to enter a printable
* character.
*/
@Override
public boolean isPrintableCharacterModifiersMask(int mods) {
return ((mods & (InputEvent.META_MASK | InputEvent.CTRL_MASK)) == 0);
}
// Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early // Extends PeerEvent because we want to pass long an ObjC mediator object and because we want these events to be posted early
// Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop // Typically, rather than relying on the notifier to call notifyAll(), we use the mediator to stop the runloop
public static class CPeerEvent extends PeerEvent { public static class CPeerEvent extends PeerEvent {
......
...@@ -245,6 +245,12 @@ public final class NSEvent { ...@@ -245,6 +245,12 @@ public final class NSEvent {
*/ */
public static native void nsKeyModifiersToJavaKeyInfo(int[] in, int[] out); public static native void nsKeyModifiersToJavaKeyInfo(int[] in, int[] out);
/*
* There is a small number of NS characters that need to be converted
* into other characters before we pass them to AWT.
*/
public static native char nsToJavaChar(char nsChar, int modifierFlags);
public static boolean isPopupTrigger(int jmodifiers) { public static boolean isPopupTrigger(int jmodifiers) {
final boolean isRightButtonDown = ((jmodifiers & InputEvent.BUTTON3_DOWN_MASK) != 0); final boolean isRightButtonDown = ((jmodifiers & InputEvent.BUTTON3_DOWN_MASK) != 0);
final boolean isLeftButtonDown = ((jmodifiers & InputEvent.BUTTON1_DOWN_MASK) != 0); final boolean isLeftButtonDown = ((jmodifiers & InputEvent.BUTTON1_DOWN_MASK) != 0);
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
...@@ -40,7 +42,7 @@ public class DefaultSelectorProvider { ...@@ -40,7 +42,7 @@ public class DefaultSelectorProvider {
* Returns the default SelectorProvider. * Returns the default SelectorProvider.
*/ */
public static SelectorProvider create() { public static SelectorProvider create() {
return new sun.nio.ch.PollSelectorProvider(); return new sun.nio.ch.KQueueSelectorProvider();
} }
} }
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
...@@ -64,8 +66,8 @@ class KQueueArrayWrapper { ...@@ -64,8 +66,8 @@ class KQueueArrayWrapper {
static short FD_OFFSET; static short FD_OFFSET;
static short FILTER_OFFSET; static short FILTER_OFFSET;
// kevent array size (just under 1K bytes) // kevent array size
static final int NUM_KEVENTS = 50; static final int NUM_KEVENTS = 128;
// Are we in a 64-bit VM? // Are we in a 64-bit VM?
static boolean is64bit = false; static boolean is64bit = false;
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
...@@ -49,8 +51,8 @@ class KQueueSelectorImpl ...@@ -49,8 +51,8 @@ class KQueueSelectorImpl
// Count of registered descriptors (including interrupt) // Count of registered descriptors (including interrupt)
private int totalChannels; private int totalChannels;
// Map from file descriptors to selection keys // Map from a file descriptor to an entry containing the selection key
private HashMap<Integer,SelectionKeyImpl> fdToKey; private HashMap<Integer,MapEntry> fdMap;
// True if this Selector has been closed // True if this Selector has been closed
private boolean closed = false; private boolean closed = false;
...@@ -59,6 +61,20 @@ class KQueueSelectorImpl ...@@ -59,6 +61,20 @@ class KQueueSelectorImpl
private Object interruptLock = new Object(); private Object interruptLock = new Object();
private boolean interruptTriggered = false; private boolean interruptTriggered = false;
// used by updateSelectedKeys to handle cases where the same file
// descriptor is polled by more than one filter
private long updateCount;
// Used to map file descriptors to a selection key and "update count"
// (see updateSelectedKeys for usage).
private static class MapEntry {
SelectionKeyImpl ski;
long updateCount;
MapEntry(SelectionKeyImpl ski) {
this.ski = ski;
}
}
/** /**
* Package private constructor called by factory method in * Package private constructor called by factory method in
* the abstract superclass Selector. * the abstract superclass Selector.
...@@ -70,7 +86,7 @@ class KQueueSelectorImpl ...@@ -70,7 +86,7 @@ class KQueueSelectorImpl
fd1 = (int)fds; fd1 = (int)fds;
kqueueWrapper = new KQueueArrayWrapper(); kqueueWrapper = new KQueueArrayWrapper();
kqueueWrapper.initInterrupt(fd0, fd1); kqueueWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap<>(); fdMap = new HashMap<>();
totalChannels = 1; totalChannels = 1;
} }
...@@ -82,8 +98,6 @@ class KQueueSelectorImpl ...@@ -82,8 +98,6 @@ class KQueueSelectorImpl
if (closed) if (closed)
throw new ClosedSelectorException(); throw new ClosedSelectorException();
processDeregisterQueue(); processDeregisterQueue();
if (timeout == 0 && totalChannels == 1)
return 0;
try { try {
begin(); begin();
entries = kqueueWrapper.poll(timeout); entries = kqueueWrapper.poll(timeout);
...@@ -94,10 +108,9 @@ class KQueueSelectorImpl ...@@ -94,10 +108,9 @@ class KQueueSelectorImpl
return updateSelectedKeys(entries); return updateSelectedKeys(entries);
} }
/** /**
* Update the keys whose fd's have been selected by the devpoll * Update the keys whose fd's have been selected by kqueue.
* driver. Add the ready keys to the ready queue. * Add the ready keys to the selected key set.
* If the interrupt fd has been selected, drain it and clear the interrupt. * If the interrupt fd has been selected, drain it and clear the interrupt.
*/ */
private int updateSelectedKeys(int entries) private int updateSelectedKeys(int entries)
...@@ -106,24 +119,42 @@ class KQueueSelectorImpl ...@@ -106,24 +119,42 @@ class KQueueSelectorImpl
int numKeysUpdated = 0; int numKeysUpdated = 0;
boolean interrupted = false; boolean interrupted = false;
// A file descriptor may be registered with kqueue with more than one
// filter and so there may be more than one event for a fd. The update
// count in the MapEntry tracks when the fd was last updated and this
// ensures that the ready ops are updated rather than replaced by a
// second or subsequent event.
updateCount++;
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
int nextFD = kqueueWrapper.getDescriptor(i); int nextFD = kqueueWrapper.getDescriptor(i);
if (nextFD == fd0) { if (nextFD == fd0) {
interrupted = true; interrupted = true;
} else { } else {
SelectionKeyImpl ski = fdToKey.get(new Integer(nextFD)); MapEntry me = fdMap.get(Integer.valueOf(nextFD));
// ski is null in the case of an interrupt
if (ski != null) { // entry is null in the case of an interrupt
if (me != null) {
int rOps = kqueueWrapper.getReventOps(i); int rOps = kqueueWrapper.getReventOps(i);
SelectionKeyImpl ski = me.ski;
if (selectedKeys.contains(ski)) { if (selectedKeys.contains(ski)) {
if (ski.channel.translateAndSetReadyOps(rOps, ski)) { // first time this file descriptor has been encountered on this
numKeysUpdated++; // update?
if (me.updateCount != updateCount) {
if (ski.channel.translateAndSetReadyOps(rOps, ski)) {
numKeysUpdated++;
me.updateCount = updateCount;
}
} else {
// ready ops have already been set on this update
ski.channel.translateAndUpdateReadyOps(rOps, ski);
} }
} else { } else {
ski.channel.translateAndSetReadyOps(rOps, ski); ski.channel.translateAndSetReadyOps(rOps, ski);
if ((ski.readyOps() & ski.interestOps()) != 0) { if ((ski.nioReadyOps() & ski.nioInterestOps()) != 0) {
selectedKeys.add(ski); selectedKeys.add(ski);
numKeysUpdated++; numKeysUpdated++;
me.updateCount = updateCount;
} }
} }
} }
...@@ -137,7 +168,6 @@ class KQueueSelectorImpl ...@@ -137,7 +168,6 @@ class KQueueSelectorImpl
interruptTriggered = false; interruptTriggered = false;
} }
} }
return numKeysUpdated; return numKeysUpdated;
} }
...@@ -145,6 +175,12 @@ class KQueueSelectorImpl ...@@ -145,6 +175,12 @@ class KQueueSelectorImpl
protected void implClose() throws IOException { protected void implClose() throws IOException {
if (!closed) { if (!closed) {
closed = true; closed = true;
// prevent further wakeup
synchronized (interruptLock) {
interruptTriggered = true;
}
FileDispatcherImpl.closeIntFD(fd0); FileDispatcherImpl.closeIntFD(fd0);
FileDispatcherImpl.closeIntFD(fd1); FileDispatcherImpl.closeIntFD(fd1);
if (kqueueWrapper != null) { if (kqueueWrapper != null) {
...@@ -172,8 +208,10 @@ class KQueueSelectorImpl ...@@ -172,8 +208,10 @@ class KQueueSelectorImpl
protected void implRegister(SelectionKeyImpl ski) { protected void implRegister(SelectionKeyImpl ski) {
if (closed)
throw new ClosedSelectorException();
int fd = IOUtil.fdVal(ski.channel.getFD()); int fd = IOUtil.fdVal(ski.channel.getFD());
fdToKey.put(new Integer(fd), ski); fdMap.put(Integer.valueOf(fd), new MapEntry(ski));
totalChannels++; totalChannels++;
keys.add(ski); keys.add(ski);
} }
...@@ -181,7 +219,7 @@ class KQueueSelectorImpl ...@@ -181,7 +219,7 @@ class KQueueSelectorImpl
protected void implDereg(SelectionKeyImpl ski) throws IOException { protected void implDereg(SelectionKeyImpl ski) throws IOException {
int fd = ski.channel.getFDVal(); int fd = ski.channel.getFDVal();
fdToKey.remove(new Integer(fd)); fdMap.remove(Integer.valueOf(fd));
kqueueWrapper.release(fd); kqueueWrapper.release(fd);
totalChannels--; totalChannels--;
keys.remove(ski); keys.remove(ski);
...@@ -194,6 +232,8 @@ class KQueueSelectorImpl ...@@ -194,6 +232,8 @@ class KQueueSelectorImpl
public void putEventOps(SelectionKeyImpl ski, int ops) { public void putEventOps(SelectionKeyImpl ski, int ops) {
if (closed)
throw new ClosedSelectorException();
int fd = IOUtil.fdVal(ski.channel.getFD()); int fd = IOUtil.fdVal(ski.channel.getFD());
kqueueWrapper.setInterest(fd, ops); kqueueWrapper.setInterest(fd, ops);
} }
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
......
...@@ -124,7 +124,7 @@ const keyTable[] = ...@@ -124,7 +124,7 @@ const keyTable[] =
{0x32, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE}, {0x32, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_QUOTE},
{0x33, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SPACE}, {0x33, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_BACK_SPACE},
{0x34, YES, KL_NUMPAD, java_awt_event_KeyEvent_VK_ENTER}, {0x34, YES, KL_NUMPAD, java_awt_event_KeyEvent_VK_ENTER},
{0x35, NO, KL_STANDARD, java_awt_event_KeyEvent_VK_ESCAPE}, {0x35, YES, KL_STANDARD, java_awt_event_KeyEvent_VK_ESCAPE},
{0x36, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_UNDEFINED}, {0x36, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_UNDEFINED},
{0x37, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_META}, // **** {0x37, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_META}, // ****
{0x38, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_SHIFT}, // **** {0x38, NO, KL_UNKNOWN, java_awt_event_KeyEvent_VK_SHIFT}, // ****
...@@ -308,6 +308,9 @@ const nsKeyToJavaModifierTable[] = ...@@ -308,6 +308,9 @@ const nsKeyToJavaModifierTable[] =
* Almost all unicode characters just go from NS to Java with no translation. * Almost all unicode characters just go from NS to Java with no translation.
* For the few exceptions, we handle it here with this small table. * For the few exceptions, we handle it here with this small table.
*/ */
#define ALL_NS_KEY_MODIFIERS_MASK \
(NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
static struct _char { static struct _char {
NSUInteger modifier; NSUInteger modifier;
unichar nsChar; unichar nsChar;
...@@ -315,17 +318,17 @@ static struct _char { ...@@ -315,17 +318,17 @@ static struct _char {
} }
const charTable[] = { const charTable[] = {
// map enter on keypad to same as return key // map enter on keypad to same as return key
{0, NSEnterCharacter, NSNewlineCharacter}, {0, NSEnterCharacter, NSNewlineCharacter},
// [3134616] return newline instead of carriage return // [3134616] return newline instead of carriage return
{0, NSCarriageReturnCharacter, NSNewlineCharacter}, {0, NSCarriageReturnCharacter, NSNewlineCharacter},
// "delete" means backspace in Java // "delete" means backspace in Java
{0, NSDeleteCharacter, NSBackspaceCharacter}, {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteCharacter, NSBackspaceCharacter},
{0, NSDeleteFunctionKey, NSDeleteCharacter}, {ALL_NS_KEY_MODIFIERS_MASK, NSDeleteFunctionKey, NSDeleteCharacter},
// back-tab is only differentiated from tab by Shift flag // back-tab is only differentiated from tab by Shift flag
{NSShiftKeyMask, NSBackTabCharacter, NSTabCharacter}, {NSShiftKeyMask, NSBackTabCharacter, NSTabCharacter},
{0, 0, 0} {0, 0, 0}
}; };
...@@ -334,12 +337,8 @@ static unichar ...@@ -334,12 +337,8 @@ static unichar
NsCharToJavaChar(unichar nsChar, NSUInteger modifiers) NsCharToJavaChar(unichar nsChar, NSUInteger modifiers)
{ {
const struct _char *cur; const struct _char *cur;
NSUInteger keyModifierFlags =
NSShiftKeyMask | NSControlKeyMask |
NSAlternateKeyMask | NSCommandKeyMask;
// Mask off just the keyboard modifiers from the event modifier mask. // Mask off just the keyboard modifiers from the event modifier mask.
NSUInteger testableFlags = (modifiers & keyModifierFlags); NSUInteger testableFlags = (modifiers & ALL_NS_KEY_MODIFIERS_MASK);
// walk through table & find the match // walk through table & find the match
for (cur = charTable; cur->nsChar != 0 ; cur++) { for (cur = charTable; cur->nsChar != 0 ; cur++) {
...@@ -507,189 +506,6 @@ NsKeyModifiersToJavaModifiers(NSUInteger nsFlags) ...@@ -507,189 +506,6 @@ NsKeyModifiersToJavaModifiers(NSUInteger nsFlags)
return javaModifiers; return javaModifiers;
} }
/*
* Returns the correct java character for a key event. Most unicode
* characters don't require any fussing, but a few seem to need adjusting,
* see nsCharToJavaChar.
*/
static unichar
GetJavaCharacter(NSEvent *event, unsigned int index)
{
unichar returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
NSString *chars = nil;
unichar testChar = 0, testDeadChar = 0;
jint javaModifiers = NsKeyModifiersToJavaModifiers([event modifierFlags]);
switch ([event type]) {
case NSFlagsChanged:
// no character for modifier keys
returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
break;
case NSKeyDown:
case NSKeyUp:
chars = [event characters];
if ([chars length] > 0) {
testChar = [chars characterAtIndex:index];
}
if (javaModifiers == 0) {
// TODO: uses SPI...
//if (TSMGetDeadKeyState() != 0) {
// testDeadChar = [self deadKeyCharacter];
//}
}
if (testChar != 0) {
returnValue = NsCharToJavaChar(testChar, [event modifierFlags]);
} else if (testDeadChar != 0) {
returnValue = NsCharToJavaChar(testDeadChar, [event modifierFlags]);
} else {
returnValue = java_awt_event_KeyEvent_CHAR_UNDEFINED;
}
break;
default:
//[NSException raise:@"AWT error" format:@"Attempt to get character code from non-key event!"];
break;
}
return returnValue;
}
/*
static jchar
GetDeadKeyCharacter(NSEvent *event)
{
// If the current event is not a dead key, return 0.
// TODO: this uses SPI; it's an optimization but not strictly necessary
//if (TSMGetDeadKeyState() == 0) {
// return 0;
//}
// AppKit does not track dead-key states directly, but TSM does. Even then,
// it's not necessarily all that accurate, because the dead key can change
// given some combination of modifier keys on certain layouts.
// As a result, finding the unicode value for the front end of the dead
// key is a bit of a heuristic.
// This algorithm was suggested by Aki Inoue.
// When you get a dead key, you need to simiulate what would happen in
// the current dead-key and modifier state if the user hit the spacebar.
// That will tell you the front end of the dead-key combination.
unichar returnValue = 0;
const UInt16 VIRTUAL_KEY_SPACE = 49;
UInt32 deadKeyState = 0;
UInt32 appkitFlags = [event modifierFlags];
UniCharCount actualStringLength;
UniChar unicodeInputString[16];
TISInputSourceRef keyLayout;
const void *chrData;
keyLayout = TISCopyCurrentKeyboardLayoutInputSource();
CFDataRef cfUchrData =
TISGetInputSourceProperty(keyLayout, kTISPropertyUnicodeKeyLayoutData);
if (cfUchrData == NULL) {
return returnValue;
}
// The actual 'uchr' table is inside the CFDataRef.
chrData = CFDataGetBytePtr(cfUchrData);
UInt8 keyboardType = LMGetKbdType();
UInt32 keyEventModifiers = 0;
if (appkitFlags & NSShiftKeyMask) keyEventModifiers |= shiftKey;
if (appkitFlags & NSCommandKeyMask) keyEventModifiers |= cmdKey;
if (appkitFlags & NSAlphaShiftKeyMask) keyEventModifiers |= alphaLock;
if (appkitFlags & NSControlKeyMask) keyEventModifiers |= controlKey;
if (appkitFlags & NSAlternateKeyMask) keyEventModifiers |= optionKey;
if (noErr == UCKeyTranslate(chrData,
VIRTUAL_KEY_SPACE,
([event type] == NSKeyDown ? kUCKeyActionDown : kUCKeyActionUp),
keyEventModifiers,
keyboardType,
kUCKeyTranslateNoDeadKeysMask,
&deadKeyState,
16,
&actualStringLength,
unicodeInputString))
{
if (actualStringLength > 0) {
returnValue = unicodeInputString[0];
}
}
return returnValue;
}
*/
// REMIND: The fix for MACOSX_PORT-539 introduces Java-level implementation
// of the function below (see CPlatformResponder). Consider removing this code.
void
DeliverJavaKeyEvent(JNIEnv *env, NSEvent *event, jobject peer)
{
jint javaKeyType = java_awt_event_KeyEvent_KEY_PRESSED;
jint javaKeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
jint javaKeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
NSString *chars = nil;
BOOL postsTyped;
unichar testChar = java_awt_event_KeyEvent_CHAR_UNDEFINED;
unichar testDeadChar = 0;
jint javaModifiers = 0;
switch ([event type]) {
case NSFlagsChanged:
NsKeyModifiersToJavaKeyInfo([event modifierFlags],
[event keyCode],
&javaKeyCode,
&javaKeyLocation,
&javaKeyType);
break;
case NSKeyDown:
case NSKeyUp:
chars = [event charactersIgnoringModifiers];
if ([chars length] > 0) {
testChar = [chars characterAtIndex:0];
}
javaModifiers = NsKeyModifiersToJavaModifiers([event modifierFlags]);
if (javaModifiers == 0) {
// TODO: dead key chars
// testDeadChar = GetDeadKeyCharacter(event);
}
NsCharToJavaVirtualKeyCode(testChar, testDeadChar,
[event modifierFlags], [event keyCode],
&javaKeyCode, &javaKeyLocation, &postsTyped);
if( !postsTyped ) {
testChar = java_awt_event_KeyEvent_CHAR_UNDEFINED;
}
javaKeyType = ([event type] == NSKeyDown) ?
java_awt_event_KeyEvent_KEY_PRESSED :
java_awt_event_KeyEvent_KEY_RELEASED;
break;
default:
//[NSException raise:@"AWT error" format:@"Attempt to get virtual key code from non-key event!"];
break;
}
if (env != NULL) {
static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_CPlatformView, "deliverKeyEvent", "(IICII)V");
JNFCallVoidMethod(env, peer, jm_deliverKeyEvent,
javaKeyType, javaModifiers,
testChar, javaKeyCode, javaKeyLocation);
}
}
jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags) jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
{ {
// Mousing needs the key modifiers // Mousing needs the key modifiers
...@@ -726,217 +542,6 @@ jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags) ...@@ -726,217 +542,6 @@ jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
return modifiers; return modifiers;
} }
/*
* Converts an NSEvent button number to a MouseEvent constant.
*/
static jint
NSButtonToJavaButton(NSInteger nsButtonNumber)
{
jint jbutton = java_awt_event_MouseEvent_NOBUTTON;
if (nsButtonNumber == 0) { // left
jbutton = java_awt_event_MouseEvent_BUTTON1;
} else if (nsButtonNumber == 1) { // right
jbutton = java_awt_event_MouseEvent_BUTTON3;
} else if (nsButtonNumber == 2) { // middle
jbutton = java_awt_event_MouseEvent_BUTTON2;
}
return jbutton;
}
static BOOL isDragging = NO;
void
DeliverMouseClickedEvent(JNIEnv *env, NSEvent *event, jobject peer)
{
NSPoint pt = [event locationInWindow];
NSPoint pOnScreen = [NSEvent mouseLocation];
jint etype = java_awt_event_MouseEvent_MOUSE_CLICKED;
jint modifiers = GetJavaMouseModifiers([event buttonNumber], [event modifierFlags]);
jint clickCount = [event clickCount];
jint button = NSButtonToJavaButton([event buttonNumber]);
if (env != NULL) {
static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_CPlatformView,
"deliverMouseEvent", "(IIIIFFFF)V");
JNFCallVoidMethod(env, peer, jm_deliverMouseEvent,
etype, modifiers,
clickCount, button,
pt.x, pt.y,
pOnScreen.x, pOnScreen.y);
}
}
/*
* After every key down event, this is called to make the matching
* KEY_TYPED (if this key posts those). We use the same NSEvent for it,
* but create a KEY_TYPED java event this time.
* If this key doesn't post typed, we don't post the event.
*
* TODO: some duplicated effort here; could just fold it
* into DeliverJavaKeyEvent...
*/
static void
DeliverKeyTypedEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer)
{
if (peer == NULL) {
return;
}
jint javaKeyCode, javaKeyLocation;
BOOL postsTyped = NO;
unichar testChar, testDeadChar = 0;
jint javaModifiers = NsKeyModifiersToJavaModifiers([nsEvent modifierFlags]);
if (javaModifiers == 0) {
testDeadChar = [nsEvent deadKeyCharacter];
}
NSString *theChars = [nsEvent characters];
unsigned i, stringLength = [theChars length];
for (i = 0; i < stringLength; i++) {
testChar = [theChars characterAtIndex:i];
NsCharToJavaVirtualKeyCode(testChar, testDeadChar,
[nsEvent modifierFlags], [nsEvent keyCode],
&javaKeyCode, &javaKeyLocation, &postsTyped);
if (postsTyped) {
// Some keys may generate a KEY_TYPED, but we can't determine
// what that character is. That's likely a bug, but for now we
// just check for CHAR_UNDEFINED.
unichar theChar = GetJavaCharacter(nsEvent, i);
if (theChar != java_awt_event_KeyEvent_CHAR_UNDEFINED) {
if (env != NULL) {
static JNF_CLASS_CACHE(jc_CPlatformView,
"sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_CPlatformView,
"deliverKeyEvent", "(IICII)V");
JNFCallVoidMethod(env, peer, jm_deliverKeyEvent,
java_awt_event_KeyEvent_KEY_TYPED,
javaModifiers,
theChar,
java_awt_event_KeyEvent_VK_UNDEFINED,
java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN);
}
}
}
}
}
/*
* There are a couple of extra events that Java expects to get that don't
* actually correspond to a direct NSEvent, KEY_TYPED and MOUSE_CLICKED are
* both extra events that are sort of redundant with ordinary
* key downs and mouse ups. In this extra message, we take the original
* input event and if necessary, cons up a special follow-on event which
* we dispatch over to Java.
*
* For Java, keyDown's generate a KeyPressed (for each hardware key as it
* goes down) and then a "logical KeyTyped" event for the key event. (So
* a shift-a generates two presses, one keytyped of "A", and then two
* releases). The standard event utility function converts a key down to
* a key pressed. When appropriate, we need to cons up another event
* (KEY_TYPED) to follow a keyDown.
*
* Java expects you to send a clicked event if you got a down & up, with no
* intervening drag. So in addition to the MOUSE_RELEASED event that a
* mouseUp is translated to, we also have to cons up a MOUSE_CLICKED event
* for that case. Mike Paquette, god of Window Server event handling,
* confirmed this fact about how to determine if a mouse up event had an
* intervening drag:
* An initial mouse-down gets a click count of 1. Subsequent left or right
* mouse-downs within the space/time tolerance limits increment the click
* count. A mouse-up will have the clickCount of the last mouseDown if
* mouse is not outside the tolerance limits, but 0 otherwise. Thus, a
* down-up sequence without any intervening drag will have a click count
* of 0 in the mouse-up event. NOTE: The problem with this is that
* clickCount goes to zero after some point in time. So a long, click &
* hold without moving and then release the mouse doesn't create a
* MOUSE_CLICK event as it should. Java AWT now tracks the drag state itself.
*
* As another add-on, we also check for the status of mouse-motion events
* after a mouse-down, so we know whether to generate mouse-dragged events
* during this down sequence.
*/
void
SendAdditionalJavaEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer)
{
AWT_ASSERT_APPKIT_THREAD;
NSEventType type = [nsEvent type];
switch (type) {
case NSKeyDown:
break;
case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
// TODO: we may need to pull in changedDragToMove here...
//if (!isDragging && ([NSViewAWT changedDragToMove]==NO)) {
if (!isDragging) {
// got down/up pair with no dragged in between; ignores drag events
// that have been morphed to move events
DeliverMouseClickedEvent(env, nsEvent, peer);
}
break;
// TODO: to be implemented...
#if 0
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
//
// During a drag, the AppKit does not send mouseEnter and mouseExit
// events. It turns out that doing a hitTest causes the window's
// view hierarchy to be locked from drawing and that, of course,
// slows everything way down. Synthesize mouseEnter and mouseExit
// then forward.
//
NSView *hitView = [[source model] hitTest:[nsEvent locationInWindow]];
if ((hitView != nil) &&
([hitView conformsToProtocol:@protocol(AWTPeerControl)]))
{
if (sLastMouseDraggedView == nil) {
sLastMouseDraggedView = hitView;
}
else if (hitView != sLastMouseDraggedView) {
// We know sLastMouseDraggedView is a AWTPeerControl.
jobject lastPeer =
[(id <AWTPeerControl>)sLastMouseDraggedView peer];
// Send mouseExit to sLastMouseDraggedView
jobject exitEvent =
makeMouseEvent(env, nsEvent, lastPeer,
sLastMouseDraggedView,
java_awt_event_MouseEvent_MOUSE_EXITED);
pushEventForward(exitEvent, env);
(*env)->DeleteLocalRef(env, exitEvent);
// Send mouseEnter to hitView
jobject enterEvent =
makeMouseEvent(env, nsEvent, peer, hitView,
java_awt_event_MouseEvent_MOUSE_ENTERED);
pushEventForward(enterEvent, env);
(*env)->DeleteLocalRef(env, enterEvent);
// Set sLastMouseDraggedView = hitView
sLastMouseDraggedView = hitView;
}
}
break;
#endif
default:
break;
}
}
jlong UTC(NSEvent *event) { jlong UTC(NSEvent *event) {
struct timeval tv; struct timeval tv;
if (gettimeofday(&tv, NULL) == 0) { if (gettimeofday(&tv, NULL) == 0) {
...@@ -1069,3 +674,23 @@ JNF_COCOA_ENTER(env); ...@@ -1069,3 +674,23 @@ JNF_COCOA_ENTER(env);
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
} }
/*
* Class: sun_lwawt_macosx_event_NSEvent
* Method: nsToJavaChar
* Signature: (CI)C
*/
JNIEXPORT jint JNICALL
Java_sun_lwawt_macosx_event_NSEvent_nsToJavaChar
(JNIEnv *env, jclass cls, char nsChar, jint modifierFlags)
{
jchar javaChar = 0;
JNF_COCOA_ENTER(env);
javaChar = NsCharToJavaChar(nsChar, modifierFlags);
JNF_COCOA_EXIT(env);
return javaChar;
}
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
@private @private
JNFWeakJObjectWrapper *javaPlatformWindow; JNFWeakJObjectWrapper *javaPlatformWindow;
CMenuBar *javaMenuBar; CMenuBar *javaMenuBar;
NSWindow *growBoxWindow;
NSSize javaMinSize; NSSize javaMinSize;
NSSize javaMaxSize; NSSize javaMaxSize;
jint styleBits; jint styleBits;
...@@ -47,7 +46,6 @@ ...@@ -47,7 +46,6 @@
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow; @property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@property (nonatomic, retain) CMenuBar *javaMenuBar; @property (nonatomic, retain) CMenuBar *javaMenuBar;
@property (nonatomic, retain) NSWindow *growBoxWindow;
@property (nonatomic) NSSize javaMinSize; @property (nonatomic) NSSize javaMinSize;
@property (nonatomic) NSSize javaMaxSize; @property (nonatomic) NSSize javaMaxSize;
@property (nonatomic) jint styleBits; @property (nonatomic) jint styleBits;
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#import "ThreadUtilities.h" #import "ThreadUtilities.h"
#import "OSVersion.h" #import "OSVersion.h"
#define MASK(KEY) \ #define MASK(KEY) \
(sun_lwawt_macosx_CPlatformWindow_ ## KEY) (sun_lwawt_macosx_CPlatformWindow_ ## KEY)
...@@ -50,31 +49,12 @@ ...@@ -50,31 +49,12 @@
#define SET(BITS, KEY, VALUE) \ #define SET(BITS, KEY, VALUE) \
BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
@interface JavaResizeGrowBoxOverlayWindow : NSWindow { }
@end
@implementation JavaResizeGrowBoxOverlayWindow
- (BOOL) accessibilityIsIgnored
{
return YES;
}
- (NSArray *)accessibilityChildrenAttribute
{
return nil;
}
@end
@implementation AWTWindow @implementation AWTWindow
@synthesize javaPlatformWindow; @synthesize javaPlatformWindow;
@synthesize javaMenuBar; @synthesize javaMenuBar;
@synthesize growBoxWindow;
@synthesize javaMinSize; @synthesize javaMinSize;
@synthesize javaMaxSize; @synthesize javaMaxSize;
@synthesize styleBits; @synthesize styleBits;
...@@ -154,24 +134,6 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); ...@@ -154,24 +134,6 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
} }
- (BOOL) shouldShowGrowBox {
return isSnowLeopardOrLower() && IS(self.styleBits, RESIZABLE);
}
- (NSImage *) createGrowBoxImage {
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(12, 12)];
JRSUIControlRef growBoxWidget = JRSUIControlCreate(FALSE);
JRSUIControlSetWidget(growBoxWidget, kJRSUI_Widget_growBoxTextured);
JRSUIControlSetWindowType(growBoxWidget, kJRSUI_WindowType_utility);
JRSUIRendererRef renderer = JRSUIRendererCreate();
[image lockFocus]; // sets current graphics context to that of the image
JRSUIControlDraw(renderer, growBoxWidget, [[NSGraphicsContext currentContext] graphicsPort], CGRectMake(0, 1, 11, 11));
[image unlockFocus];
JRSUIRendererRelease(renderer);
JRSUIControlRelease(growBoxWidget);
return image;
}
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
styleBits:(jint)bits styleBits:(jint)bits
frameRect:(NSRect)rect frameRect:(NSRect)rect
...@@ -205,28 +167,6 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -205,28 +167,6 @@ AWT_ASSERT_APPKIT_THREAD;
[self setReleasedWhenClosed:NO]; [self setReleasedWhenClosed:NO];
[self setPreservesContentDuringLiveResize:YES]; [self setPreservesContentDuringLiveResize:YES];
if ([self shouldShowGrowBox]) {
NSImage *growBoxImage = [self createGrowBoxImage];
growBoxWindow = [[JavaResizeGrowBoxOverlayWindow alloc] initWithContentRect:NSMakeRect(0, 0, [growBoxImage size].width, [growBoxImage size].height) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[self.growBoxWindow setIgnoresMouseEvents:YES];
[self.growBoxWindow setOpaque:NO];
[self.growBoxWindow setBackgroundColor:[NSColor clearColor]];
[self.growBoxWindow setHasShadow:NO];
[self.growBoxWindow setReleasedWhenClosed:NO];
NSImageView *imageView = [[NSImageView alloc] initWithFrame:[self.growBoxWindow frame]];
[imageView setEditable:NO];
[imageView setAnimates:NO];
[imageView setAllowsCutCopyPaste:NO];
[self.growBoxWindow setContentView:imageView];
[imageView setImage:growBoxImage];
[growBoxImage release];
[imageView release];
[self addChildWindow:self.growBoxWindow ordered:NSWindowAbove];
[self adjustGrowBoxWindow];
} else growBoxWindow = nil;
return self; return self;
} }
...@@ -235,7 +175,6 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -235,7 +175,6 @@ AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv]; JNIEnv *env = [ThreadUtilities getJNIEnv];
[self.javaPlatformWindow setJObject:nil withEnv:env]; [self.javaPlatformWindow setJObject:nil withEnv:env];
self.growBoxWindow = nil;
[super dealloc]; [super dealloc];
} }
...@@ -321,14 +260,6 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -321,14 +260,6 @@ AWT_ASSERT_APPKIT_THREAD;
// NSWindowDelegate methods // NSWindowDelegate methods
- (void) adjustGrowBoxWindow {
if (self.growBoxWindow != nil) {
NSRect parentRect = [self frame];
parentRect.origin.x += (parentRect.size.width - [self.growBoxWindow frame].size.width);
[self.growBoxWindow setFrameOrigin:parentRect.origin];
}
}
- (void) _deliverMoveResizeEvent { - (void) _deliverMoveResizeEvent {
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
...@@ -342,8 +273,6 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -342,8 +273,6 @@ AWT_ASSERT_APPKIT_THREAD;
// TODO: create generic AWT assert // TODO: create generic AWT assert
} }
[self adjustGrowBoxWindow];
NSRect frame = ConvertNSScreenRect(env, [self frame]); NSRect frame = ConvertNSScreenRect(env, [self frame]);
static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V"); static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIII)V");
...@@ -548,6 +477,31 @@ AWT_ASSERT_APPKIT_THREAD; ...@@ -548,6 +477,31 @@ AWT_ASSERT_APPKIT_THREAD;
} }
[super sendEvent:event]; [super sendEvent:event];
} }
- (void)constrainSize:(NSSize*)size {
float minWidth = 0.f, minHeight = 0.f;
if (IS(self.styleBits, DECORATED)) {
NSRect frame = [self frame];
NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self styleMask]];
float top = frame.size.height - contentRect.size.height;
float left = contentRect.origin.x - frame.origin.x;
float bottom = contentRect.origin.y - frame.origin.y;
float right = frame.size.width - (contentRect.size.width + left);
// Speculative estimation: 80 - enough for window decorations controls
minWidth += left + right + 80;
minHeight += top + bottom;
}
minWidth = MAX(1.f, minWidth);
minHeight = MAX(1.f, minHeight);
size->width = MAX(size->width, minWidth);
size->height = MAX(size->height, minHeight);
}
@end // AWTWindow @end // AWTWindow
...@@ -703,6 +657,8 @@ AWT_ASSERT_NOT_APPKIT_THREAD; ...@@ -703,6 +657,8 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
NSRect rect = ConvertNSScreenRect(NULL, jrect); NSRect rect = ConvertNSScreenRect(NULL, jrect);
[window constrainSize:&rect.size];
[window setFrame:rect display:YES]; [window setFrame:rect display:YES];
// only start tracking events if pointer is above the toplevel // only start tracking events if pointer is above the toplevel
...@@ -734,13 +690,16 @@ AWT_ASSERT_NOT_APPKIT_THREAD; ...@@ -734,13 +690,16 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
if (maxW < 1) maxW = 1; if (maxW < 1) maxW = 1;
if (maxH < 1) maxH = 1; if (maxH < 1) maxH = 1;
NSSize min = { minW, minH };
NSSize max = { maxW, maxH };
AWTWindow *window = OBJC(windowPtr); AWTWindow *window = OBJC(windowPtr);
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
NSSize min = { minW, minH };
NSSize max = { maxW, maxH };
[window constrainSize:&min];
[window constrainSize:&max];
window.javaMinSize = min; window.javaMinSize = min;
window.javaMaxSize = max; window.javaMaxSize = max;
[window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
...@@ -830,7 +789,6 @@ AWT_ASSERT_NOT_APPKIT_THREAD; ...@@ -830,7 +789,6 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
AWT_ASSERT_APPKIT_THREAD; AWT_ASSERT_APPKIT_THREAD;
[window setAlphaValue:alpha]; [window setAlphaValue:alpha];
[window.growBoxWindow setAlphaValue:alpha];
}]; }];
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
......
...@@ -648,6 +648,10 @@ extern JNFClassInfo jc_CDropTargetContextPeer; ...@@ -648,6 +648,10 @@ extern JNFClassInfo jc_CDropTargetContextPeer;
if (sDraggingError == FALSE) { if (sDraggingError == FALSE) {
sDraggingLocation = [sender draggingLocation]; sDraggingLocation = [sender draggingLocation];
NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil]; NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
// The y coordinate that comes in the NSDraggingInfo seems to be reversed - probably
// has to do something with the type of view it comes to.
// This is the earliest place where we can correct it.
javaLocation.y = fView.window.frame.size.height - javaLocation.y;
jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]]; jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]];
jint dropAction = sJavaDropOperation; jint dropAction = sJavaDropOperation;
......
...@@ -70,19 +70,8 @@ static void CImage_CopyNSImageIntoArray ...@@ -70,19 +70,8 @@ static void CImage_CopyNSImageIntoArray
[oldContext release]; [oldContext release];
} }
/* static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height)
* Class: sun_lwawt_macosx_CImage
* Method: nativeCreateNSImageFromArray
* Signature: ([III)J
*/
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray
(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
{ {
jlong result = 0L;
JNF_COCOA_ENTER(env);
AWT_ASSERT_ANY_THREAD;
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:width pixelsWide:width
pixelsHigh:height pixelsHigh:height
...@@ -105,15 +94,83 @@ AWT_ASSERT_ANY_THREAD; ...@@ -105,15 +94,83 @@ AWT_ASSERT_ANY_THREAD;
(*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT); (*env)->ReleasePrimitiveArrayCritical(env, buffer, src, JNI_ABORT);
NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; return imageRep;
[nsImage addRepresentation:imageRep]; }
[imageRep release];
/*
* Class: sun_lwawt_macosx_CImage
* Method: nativeCreateNSImageFromArray
* Signature: ([III)J
*/
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArray
(JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
{
jlong result = 0L;
JNF_COCOA_ENTER(env);
AWT_ASSERT_ANY_THREAD;
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
if (imageRep) {
NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[nsImage addRepresentation:imageRep];
[imageRep release];
if (nsImage != nil) { if (nsImage != nil) {
CFRetain(nsImage); // GC CFRetain(nsImage); // GC
}
result = ptr_to_jlong(nsImage);
} }
result = ptr_to_jlong(nsImage); JNF_COCOA_EXIT(env);
return result;
}
/*
* Class: sun_lwawt_macosx_CImage
* Method: nativeCreateNSImageFromArrays
* Signature: ([[I[I[I)J
*/
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromArrays
(JNIEnv *env, jclass klass, jobjectArray buffers, jintArray widths, jintArray heights)
{
jlong result = 0L;
JNF_COCOA_ENTER(env);
AWT_ASSERT_ANY_THREAD;
jsize num = (*env)->GetArrayLength(env, buffers);
NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num];
jint * ws = (*env)->GetIntArrayElements(env, widths, NULL);
jint * hs = (*env)->GetIntArrayElements(env, heights, NULL);
jsize i;
for (i = 0; i < num; i++) {
jintArray buffer = (*env)->GetObjectArrayElement(env, buffers, i);
NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, ws[i], hs[i]);
if (imageRep) {
[reps addObject: imageRep];
}
}
(*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT);
(*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
if ([reps count]) {
NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
[nsImage addRepresentations: reps];
[reps release];
if (nsImage != nil) {
CFRetain(nsImage); // GC
}
result = ptr_to_jlong(nsImage);
}
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
* *
* This code is free software; you can redistribute it and/or modify it * 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 * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. * published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
......
...@@ -114,6 +114,23 @@ class VMConnection { ...@@ -114,6 +114,23 @@ class VMConnection {
String value = token.substring(index + 1, String value = token.substring(index + 1,
token.length() - 1); // Remove comma delimiter token.length() - 1); // Remove comma delimiter
/*
* for values enclosed in quotes (single and/or double quotes)
* strip off enclosing quote chars
* needed for quote enclosed delimited substrings
*/
if (name.equals("options")) {
StringBuilder sb = new StringBuilder();
for (String s : splitStringAtNonEnclosedWhiteSpace(value)) {
while (isEnclosed(s, "\"") || isEnclosed(s, "'")) {
s = s.substring(1, s.length() - 1);
}
sb.append(s);
sb.append(" ");
}
value = sb.toString();
}
Connector.Argument argument = arguments.get(name); Connector.Argument argument = arguments.get(name);
if (argument == null) { if (argument == null) {
throw new IllegalArgumentException throw new IllegalArgumentException
...@@ -136,6 +153,152 @@ class VMConnection { ...@@ -136,6 +153,152 @@ class VMConnection {
return arguments; return arguments;
} }
private static boolean isEnclosed(String value, String enclosingChar) {
if (value.indexOf(enclosingChar) == 0) {
int lastIndex = value.lastIndexOf(enclosingChar);
if (lastIndex > 0 && lastIndex == value.length() - 1) {
return true;
}
}
return false;
}
private static List<String> splitStringAtNonEnclosedWhiteSpace(String value) throws IllegalArgumentException {
List<String> al = new ArrayList<String>();
char[] arr;
int startPosition = 0;
int endPosition = 0;
final char SPACE = ' ';
final char DOUBLEQ = '"';
final char SINGLEQ = '\'';
/*
* An "open" or "active" enclosing state is where
* the first valid start quote qualifier is found,
* and there is a search in progress for the
* relevant end matching quote
*
* enclosingTargetChar set to SPACE
* is used to signal a non open enclosing state
*/
char enclosingTargetChar = SPACE;
if (value == null) {
throw new IllegalArgumentException
(MessageOutput.format("value string is null"));
}
// split parameter string into individual chars
arr = value.toCharArray();
for (int i = 0; i < arr.length; i++) {
switch (arr[i]) {
case SPACE: {
// do nothing for spaces
// unless last in array
if (isLastChar(arr, i)) {
endPosition = i;
// break for substring creation
break;
}
continue;
}
case DOUBLEQ:
case SINGLEQ: {
if (enclosingTargetChar == arr[i]) {
// potential match to close open enclosing
if (isNextCharWhitespace(arr, i)) {
// if peek next is whitespace
// then enclosing is a valid substring
endPosition = i;
// reset enclosing target char
enclosingTargetChar = SPACE;
// break for substring creation
break;
}
}
if (enclosingTargetChar == SPACE) {
// no open enclosing state
// handle as normal char
if (isPreviousCharWhitespace(arr, i)) {
startPosition = i;
// peek forward for end candidates
if (value.indexOf(arr[i], i + 1) >= 0) {
// set open enclosing state by
// setting up the target char
enclosingTargetChar = arr[i];
} else {
// no more target chars left to match
// end enclosing, handle as normal char
if (isNextCharWhitespace(arr, i)) {
endPosition = i;
// break for substring creation
break;
}
}
}
}
continue;
}
default: {
// normal non-space, non-" and non-' chars
if (enclosingTargetChar == SPACE) {
// no open enclosing state
if (isPreviousCharWhitespace(arr, i)) {
// start of space delim substring
startPosition = i;
}
if (isNextCharWhitespace(arr, i)) {
// end of space delim substring
endPosition = i;
// break for substring creation
break;
}
}
continue;
}
}
// break's end up here
if (startPosition > endPosition) {
throw new IllegalArgumentException
(MessageOutput.format("Illegal option values"));
}
// extract substring and add to List<String>
al.add(value.substring(startPosition, ++endPosition));
// set new start position
i = startPosition = endPosition;
} // for loop
return al;
}
static private boolean isPreviousCharWhitespace(char[] arr, int curr_pos) {
return isCharWhitespace(arr, curr_pos - 1);
}
static private boolean isNextCharWhitespace(char[] arr, int curr_pos) {
return isCharWhitespace(arr, curr_pos + 1);
}
static private boolean isCharWhitespace(char[] arr, int pos) {
if (pos < 0 || pos >= arr.length) {
// outside arraybounds is considered an implicit space
return true;
}
if (arr[pos] == ' ') {
return true;
}
return false;
}
static private boolean isLastChar(char[] arr, int pos) {
return (pos + 1 == arr.length);
}
VMConnection(String connectSpec, int traceFlags) { VMConnection(String connectSpec, int traceFlags) {
String nameString; String nameString;
String argString; String argString;
......
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -616,9 +616,6 @@ public final class HttpCookie implements Cloneable { ...@@ -616,9 +616,6 @@ public final class HttpCookie implements Cloneable {
* would be accepted.</li> * would be accepted.</li>
* <li>A Set-Cookie2 with Domain=.com or Domain=.com., will always be * <li>A Set-Cookie2 with Domain=.com or Domain=.com., will always be
* rejected, because there is no embedded dot.</li> * rejected, because there is no embedded dot.</li>
* <li>A Set-Cookie2 with Domain=ajax.com will be accepted, and the
* value for Domain will be taken to be .ajax.com, because a dot
* gets prepended to the value.</li>
* <li>A Set-Cookie2 from request-host example for Domain=.local will * <li>A Set-Cookie2 from request-host example for Domain=.local will
* be accepted, because the effective host name for the request- * be accepted, because the effective host name for the request-
* host is example.local, and example.local domain-matches .local.</li> * host is example.local, and example.local domain-matches .local.</li>
......
...@@ -269,7 +269,7 @@ public final class Files { ...@@ -269,7 +269,7 @@ public final class Files {
* WritableByteChannel wbc = Files.newByteChannel(path, EnumSet.of(CREATE,APPEND)); * WritableByteChannel wbc = Files.newByteChannel(path, EnumSet.of(CREATE,APPEND));
* *
* // create file with initial permissions, opening it for both reading and writing * // create file with initial permissions, opening it for both reading and writing
* {@code FileAttribute<<SetPosixFilePermission>> perms = ...} * {@code FileAttribute<Set<PosixFilePermission>> perms = ...}
* SeekableByteChannel sbc = Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms); * SeekableByteChannel sbc = Files.newByteChannel(path, EnumSet.of(CREATE_NEW,READ,WRITE), perms);
* </pre> * </pre>
* *
......
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -114,7 +114,7 @@ public class CodeSource implements java.io.Serializable { ...@@ -114,7 +114,7 @@ public class CodeSource implements java.io.Serializable {
* *
* @return a hash code value for this object. * @return a hash code value for this object.
*/ */
@Override
public int hashCode() { public int hashCode() {
if (location != null) if (location != null)
return location.hashCode(); return location.hashCode();
...@@ -133,6 +133,7 @@ public class CodeSource implements java.io.Serializable { ...@@ -133,6 +133,7 @@ public class CodeSource implements java.io.Serializable {
* *
* @return true if the objects are considered equal, false otherwise. * @return true if the objects are considered equal, false otherwise.
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) if (obj == this)
return true; return true;
...@@ -231,10 +232,10 @@ public class CodeSource implements java.io.Serializable { ...@@ -231,10 +232,10 @@ public class CodeSource implements java.io.Serializable {
/** /**
* Returns true if this CodeSource object "implies" the specified CodeSource. * Returns true if this CodeSource object "implies" the specified CodeSource.
* <P> * <p>
* More specifically, this method makes the following checks, in order. * More specifically, this method makes the following checks.
* If any fail, it returns false. If they all succeed, it returns true.<p> * If any fail, it returns false. If they all succeed, it returns true.<p>
* <ol> * <ul>
* <li> <i>codesource</i> must not be null. * <li> <i>codesource</i> must not be null.
* <li> If this object's certificates are not null, then all * <li> If this object's certificates are not null, then all
* of this object's certificates must be present in <i>codesource</i>'s * of this object's certificates must be present in <i>codesource</i>'s
...@@ -242,14 +243,14 @@ public class CodeSource implements java.io.Serializable { ...@@ -242,14 +243,14 @@ public class CodeSource implements java.io.Serializable {
* <li> If this object's location (getLocation()) is not null, then the * <li> If this object's location (getLocation()) is not null, then the
* following checks are made against this object's location and * following checks are made against this object's location and
* <i>codesource</i>'s:<p> * <i>codesource</i>'s:<p>
* <ol> * <ul>
* <li> <i>codesource</i>'s location must not be null. * <li> <i>codesource</i>'s location must not be null.
* *
* <li> If this object's location * <li> If this object's location
* equals <i>codesource</i>'s location, then return true. * equals <i>codesource</i>'s location, then return true.
* *
* <li> This object's protocol (getLocation().getProtocol()) must be * <li> This object's protocol (getLocation().getProtocol()) must be
* equal to <i>codesource</i>'s protocol. * equal to <i>codesource</i>'s protocol, ignoring case.
* *
* <li> If this object's host (getLocation().getHost()) is not null, * <li> If this object's host (getLocation().getHost()) is not null,
* then the SocketPermission * then the SocketPermission
...@@ -258,7 +259,8 @@ public class CodeSource implements java.io.Serializable { ...@@ -258,7 +259,8 @@ public class CodeSource implements java.io.Serializable {
* *
* <li> If this object's port (getLocation().getPort()) is not * <li> If this object's port (getLocation().getPort()) is not
* equal to -1 (that is, if a port is specified), it must equal * equal to -1 (that is, if a port is specified), it must equal
* <i>codesource</i>'s port. * <i>codesource</i>'s port or default port
* (codesource.getLocation().getDefaultPort()).
* *
* <li> If this object's file (getLocation().getFile()) doesn't equal * <li> If this object's file (getLocation().getFile()) doesn't equal
* <i>codesource</i>'s file, then the following checks are made: * <i>codesource</i>'s file, then the following checks are made:
...@@ -275,8 +277,8 @@ public class CodeSource implements java.io.Serializable { ...@@ -275,8 +277,8 @@ public class CodeSource implements java.io.Serializable {
* <li> If this object's reference (getLocation().getRef()) is * <li> If this object's reference (getLocation().getRef()) is
* not null, it must equal <i>codesource</i>'s reference. * not null, it must equal <i>codesource</i>'s reference.
* *
* </ol> * </ul>
* </ol> * </ul>
* <p> * <p>
* For example, the codesource objects with the following locations * For example, the codesource objects with the following locations
* and null certificates all imply * and null certificates all imply
...@@ -369,85 +371,88 @@ public class CodeSource implements java.io.Serializable { ...@@ -369,85 +371,88 @@ public class CodeSource implements java.io.Serializable {
* *
* @param that CodeSource to compare against * @param that CodeSource to compare against
*/ */
private boolean matchLocation(CodeSource that) private boolean matchLocation(CodeSource that) {
{ if (location == null)
if (location == null) { return true;
return true;
}
if ((that == null) || (that.location == null)) if ((that == null) || (that.location == null))
return false; return false;
if (location.equals(that.location)) if (location.equals(that.location))
return true; return true;
if (!location.getProtocol().equals(that.location.getProtocol())) if (!location.getProtocol().equalsIgnoreCase(that.location.getProtocol()))
return false; return false;
String thisHost = location.getHost(); int thisPort = location.getPort();
String thatHost = that.location.getHost(); if (thisPort != -1) {
int thatPort = that.location.getPort();
int port = thatPort != -1 ? thatPort
: that.location.getDefaultPort();
if (thisPort != port)
return false;
}
if (thisHost != null) { if (location.getFile().endsWith("/-")) {
if (("".equals(thisHost) || "localhost".equals(thisHost)) && // Matches the directory and (recursively) all files
("".equals(thatHost) || "localhost".equals(thatHost))) { // and subdirectories contained in that directory.
// ok // For example, "/a/b/-" implies anything that starts with
} else if (!thisHost.equals(thatHost)) { // "/a/b/"
if (thatHost == null) { String thisPath = location.getFile().substring(0,
return false; location.getFile().length()-1);
} if (!that.location.getFile().startsWith(thisPath))
if (this.sp == null) { return false;
this.sp = new SocketPermission(thisHost, "resolve"); } else if (location.getFile().endsWith("/*")) {
} // Matches the directory and all the files contained in that
if (that.sp == null) { // directory.
that.sp = new SocketPermission(thatHost, "resolve"); // For example, "/a/b/*" implies anything that starts with
} // "/a/b/" but has no further slashes
if (!this.sp.implies(that.sp)) { int last = that.location.getFile().lastIndexOf('/');
return false; if (last == -1)
} return false;
} String thisPath = location.getFile().substring(0,
location.getFile().length()-1);
String thatPath = that.location.getFile().substring(0, last+1);
if (!thatPath.equals(thisPath))
return false;
} else {
// Exact matches only.
// For example, "/a/b" and "/a/b/" both imply "/a/b/"
if ((!that.location.getFile().equals(location.getFile()))
&& (!that.location.getFile().equals(location.getFile()+"/"))) {
return false;
} }
}
if (location.getPort() != -1) { if (location.getRef() != null
if (location.getPort() != that.location.getPort()) && !location.getRef().equals(that.location.getRef())) {
return false; return false;
} }
if (location.getFile().endsWith("/-")) { String thisHost = location.getHost();
// Matches the directory and (recursively) all files String thatHost = that.location.getHost();
// and subdirectories contained in that directory. if (thisHost != null) {
// For example, "/a/b/-" implies anything that starts with if (("".equals(thisHost) || "localhost".equals(thisHost)) &&
// "/a/b/" ("".equals(thatHost) || "localhost".equals(thatHost))) {
String thisPath = location.getFile().substring(0, // ok
location.getFile().length()-1); } else if (!thisHost.equals(thatHost)) {
if (!that.location.getFile().startsWith(thisPath)) if (thatHost == null) {
return false;
} else if (location.getFile().endsWith("/*")) {
// Matches the directory and all the files contained in that
// directory.
// For example, "/a/b/*" implies anything that starts with
// "/a/b/" but has no further slashes
int last = that.location.getFile().lastIndexOf('/');
if (last == -1)
return false; return false;
String thisPath = location.getFile().substring(0, }
location.getFile().length()-1); if (this.sp == null) {
String thatPath = that.location.getFile().substring(0, last+1); this.sp = new SocketPermission(thisHost, "resolve");
if (!thatPath.equals(thisPath)) }
return false; if (that.sp == null) {
} else { that.sp = new SocketPermission(thatHost, "resolve");
// Exact matches only. }
// For example, "/a/b" and "/a/b/" both imply "/a/b/" if (!this.sp.implies(that.sp)) {
if ((!that.location.getFile().equals(location.getFile()))
&& (!that.location.getFile().equals(location.getFile()+"/"))) {
return false; return false;
} }
} }
if (location.getRef() == null)
return true;
else
return location.getRef().equals(that.location.getRef());
} }
// everything matches
return true;
}
/** /**
* Returns a string describing this CodeSource, telling its * Returns a string describing this CodeSource, telling its
...@@ -455,6 +460,7 @@ public class CodeSource implements java.io.Serializable { ...@@ -455,6 +460,7 @@ public class CodeSource implements java.io.Serializable {
* *
* @return information about this CodeSource. * @return information about this CodeSource.
*/ */
@Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("("); sb.append("(");
......
...@@ -170,6 +170,7 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -170,6 +170,7 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @throws ArrayStoreException {@inheritDoc} * @throws ArrayStoreException {@inheritDoc}
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) { public <T> T[] toArray(T[] a) {
// Estimate size of array; be prepared to see more or fewer elements // Estimate size of array; be prepared to see more or fewer elements
int size = size(); int size = size();
...@@ -180,13 +181,21 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -180,13 +181,21 @@ public abstract class AbstractCollection<E> implements Collection<E> {
for (int i = 0; i < r.length; i++) { for (int i = 0; i < r.length; i++) {
if (! it.hasNext()) { // fewer elements than expected if (! it.hasNext()) { // fewer elements than expected
if (a != r) if (a == r) {
r[i] = null; // null-terminate
} else if (a.length < i) {
return Arrays.copyOf(r, i); return Arrays.copyOf(r, i);
r[i] = null; // null-terminate } else {
return r; System.arraycopy(r, 0, a, 0, i);
if (a.length > i) {
a[i] = null;
}
}
return a;
} }
r[i] = (T)it.next(); r[i] = (T)it.next();
} }
// more elements than expected
return it.hasNext() ? finishToArray(r, it) : r; return it.hasNext() ? finishToArray(r, it) : r;
} }
...@@ -208,6 +217,7 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -208,6 +217,7 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @return array containing the elements in the given array, plus any * @return array containing the elements in the given array, plus any
* further elements returned by the iterator, trimmed to size * further elements returned by the iterator, trimmed to size
*/ */
@SuppressWarnings("unchecked")
private static <T> T[] finishToArray(T[] r, Iterator<?> it) { private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
int i = r.length; int i = r.length;
while (it.hasNext()) { while (it.hasNext()) {
......
...@@ -516,7 +516,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L ...@@ -516,7 +516,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
return false; return false;
ListIterator<E> e1 = listIterator(); ListIterator<E> e1 = listIterator();
ListIterator e2 = ((List) o).listIterator(); ListIterator<?> e2 = ((List<?>) o).listIterator();
while (e1.hasNext() && e2.hasNext()) { while (e1.hasNext() && e2.hasNext()) {
E o1 = e1.next(); E o1 = e1.next();
Object o2 = e2.next(); Object o2 = e2.next();
......
...@@ -443,7 +443,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> { ...@@ -443,7 +443,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
if (!(o instanceof Map)) if (!(o instanceof Map))
return false; return false;
Map<K,V> m = (Map<K,V>) o; Map<?,?> m = (Map<?,?>) o;
if (m.size() != size()) if (m.size() != size())
return false; return false;
...@@ -534,7 +534,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> { ...@@ -534,7 +534,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
* @return a shallow copy of this map * @return a shallow copy of this map
*/ */
protected Object clone() throws CloneNotSupportedException { protected Object clone() throws CloneNotSupportedException {
AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone(); AbstractMap<?,?> result = (AbstractMap<?,?>)super.clone();
result.keySet = null; result.keySet = null;
result.values = null; result.values = null;
return result; return result;
...@@ -652,7 +652,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> { ...@@ -652,7 +652,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return eq(key, e.getKey()) && eq(value, e.getValue()); return eq(key, e.getKey()) && eq(value, e.getValue());
} }
...@@ -783,7 +783,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> { ...@@ -783,7 +783,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return eq(key, e.getKey()) && eq(value, e.getValue()); return eq(key, e.getKey()) && eq(value, e.getValue());
} }
......
...@@ -88,7 +88,7 @@ public abstract class AbstractSet<E> extends AbstractCollection<E> implements Se ...@@ -88,7 +88,7 @@ public abstract class AbstractSet<E> extends AbstractCollection<E> implements Se
if (!(o instanceof Set)) if (!(o instanceof Set))
return false; return false;
Collection c = (Collection) o; Collection<?> c = (Collection<?>) o;
if (c.size() != size()) if (c.size() != size())
return false; return false;
try { try {
......
...@@ -813,7 +813,8 @@ public class ArrayDeque<E> extends AbstractCollection<E> ...@@ -813,7 +813,8 @@ public class ArrayDeque<E> extends AbstractCollection<E>
*/ */
public ArrayDeque<E> clone() { public ArrayDeque<E> clone() {
try { try {
ArrayDeque<E> result = (ArrayDeque<E>) super.clone(); @SuppressWarnings("unchecked")
ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
result.elements = Arrays.copyOf(elements, elements.length); result.elements = Arrays.copyOf(elements, elements.length);
return result; return result;
...@@ -849,6 +850,7 @@ public class ArrayDeque<E> extends AbstractCollection<E> ...@@ -849,6 +850,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
/** /**
* Deserialize this deque. * Deserialize this deque.
*/ */
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream s) private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
s.defaultReadObject(); s.defaultReadObject();
......
...@@ -300,8 +300,7 @@ public class ArrayList<E> extends AbstractList<E> ...@@ -300,8 +300,7 @@ public class ArrayList<E> extends AbstractList<E>
*/ */
public Object clone() { public Object clone() {
try { try {
@SuppressWarnings("unchecked") ArrayList<?> v = (ArrayList<?>) super.clone();
ArrayList<E> v = (ArrayList<E>) super.clone();
v.elementData = Arrays.copyOf(elementData, size); v.elementData = Arrays.copyOf(elementData, size);
v.modCount = 0; v.modCount = 0;
return v; return v;
......
...@@ -560,6 +560,7 @@ public class Arrays { ...@@ -560,6 +560,7 @@ public class Arrays {
* off is the offset to generate corresponding low, high in src * off is the offset to generate corresponding low, high in src
* To be removed in a future release. * To be removed in a future release.
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void mergeSort(Object[] src, private static void mergeSort(Object[] src,
Object[] dest, Object[] dest,
int low, int low,
...@@ -746,6 +747,7 @@ public class Arrays { ...@@ -746,6 +747,7 @@ public class Arrays {
* off is the offset into src corresponding to low in dest * off is the offset into src corresponding to low in dest
* To be removed in a future release. * To be removed in a future release.
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void mergeSort(Object[] src, private static void mergeSort(Object[] src,
Object[] dest, Object[] dest,
int low, int high, int off, int low, int high, int off,
...@@ -1477,8 +1479,10 @@ public class Arrays { ...@@ -1477,8 +1479,10 @@ public class Arrays {
while (low <= high) { while (low <= high) {
int mid = (low + high) >>> 1; int mid = (low + high) >>> 1;
Comparable midVal = (Comparable)a[mid]; @SuppressWarnings("rawtypes")
int cmp = midVal.compareTo(key); Comparable midVal = (Comparable)a[mid];
@SuppressWarnings("unchecked")
int cmp = midVal.compareTo(key);
if (cmp < 0) if (cmp < 0)
low = mid + 1; low = mid + 1;
...@@ -2215,6 +2219,7 @@ public class Arrays { ...@@ -2215,6 +2219,7 @@ public class Arrays {
* @throws NullPointerException if <tt>original</tt> is null * @throws NullPointerException if <tt>original</tt> is null
* @since 1.6 * @since 1.6
*/ */
@SuppressWarnings("unchecked")
public static <T> T[] copyOf(T[] original, int newLength) { public static <T> T[] copyOf(T[] original, int newLength) {
return (T[]) copyOf(original, newLength, original.getClass()); return (T[]) copyOf(original, newLength, original.getClass());
} }
...@@ -2242,6 +2247,7 @@ public class Arrays { ...@@ -2242,6 +2247,7 @@ public class Arrays {
* @since 1.6 * @since 1.6
*/ */
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) { public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
@SuppressWarnings("unchecked")
T[] copy = ((Object)newType == (Object)Object[].class) T[] copy = ((Object)newType == (Object)Object[].class)
? (T[]) new Object[newLength] ? (T[]) new Object[newLength]
: (T[]) Array.newInstance(newType.getComponentType(), newLength); : (T[]) Array.newInstance(newType.getComponentType(), newLength);
...@@ -2470,8 +2476,9 @@ public class Arrays { ...@@ -2470,8 +2476,9 @@ public class Arrays {
* @throws NullPointerException if <tt>original</tt> is null * @throws NullPointerException if <tt>original</tt> is null
* @since 1.6 * @since 1.6
*/ */
@SuppressWarnings("unchecked")
public static <T> T[] copyOfRange(T[] original, int from, int to) { public static <T> T[] copyOfRange(T[] original, int from, int to) {
return copyOfRange(original, from, to, (Class<T[]>) original.getClass()); return copyOfRange(original, from, to, (Class<? extends T[]>) original.getClass());
} }
/** /**
...@@ -2509,6 +2516,7 @@ public class Arrays { ...@@ -2509,6 +2516,7 @@ public class Arrays {
int newLength = to - from; int newLength = to - from;
if (newLength < 0) if (newLength < 0)
throw new IllegalArgumentException(from + " > " + to); throw new IllegalArgumentException(from + " > " + to);
@SuppressWarnings("unchecked")
T[] copy = ((Object)newType == (Object)Object[].class) T[] copy = ((Object)newType == (Object)Object[].class)
? (T[]) new Object[newLength] ? (T[]) new Object[newLength]
: (T[]) Array.newInstance(newType.getComponentType(), newLength); : (T[]) Array.newInstance(newType.getComponentType(), newLength);
...@@ -2851,6 +2859,7 @@ public class Arrays { ...@@ -2851,6 +2859,7 @@ public class Arrays {
return a.clone(); return a.clone();
} }
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) { public <T> T[] toArray(T[] a) {
int size = size(); int size = size();
if (a.length < size) if (a.length < size)
...@@ -3634,7 +3643,7 @@ public class Arrays { ...@@ -3634,7 +3643,7 @@ public class Arrays {
if (element == null) { if (element == null) {
buf.append("null"); buf.append("null");
} else { } else {
Class eClass = element.getClass(); Class<?> eClass = element.getClass();
if (eClass.isArray()) { if (eClass.isArray()) {
if (eClass == byte[].class) if (eClass == byte[].class)
......
...@@ -840,7 +840,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca ...@@ -840,7 +840,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* of a Locale. * of a Locale.
*/ */
private static final ConcurrentMap<Locale, int[]> cachedLocaleData private static final ConcurrentMap<Locale, int[]> cachedLocaleData
= new ConcurrentHashMap<Locale, int[]>(3); = new ConcurrentHashMap<>(3);
// Special values of stamp[] // Special values of stamp[]
/** /**
...@@ -1499,7 +1499,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca ...@@ -1499,7 +1499,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale); DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
String[] strings = getFieldStrings(field, style, symbols); String[] strings = getFieldStrings(field, style, symbols);
if (strings != null) { if (strings != null) {
Map<String,Integer> names = new HashMap<String,Integer>(); Map<String,Integer> names = new HashMap<>();
for (int i = 0; i < strings.length; i++) { for (int i = 0; i < strings.length; i++) {
if (strings[i].length() == 0) { if (strings[i].length() == 0) {
continue; continue;
......
...@@ -150,6 +150,7 @@ public class Collections { ...@@ -150,6 +150,7 @@ public class Collections {
* detects that the natural ordering of the list elements is * detects that the natural ordering of the list elements is
* found to violate the {@link Comparable} contract * found to violate the {@link Comparable} contract
*/ */
@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> void sort(List<T> list) { public static <T extends Comparable<? super T>> void sort(List<T> list) {
Object[] a = list.toArray(); Object[] a = list.toArray();
Arrays.sort(a); Arrays.sort(a);
...@@ -212,13 +213,14 @@ public class Collections { ...@@ -212,13 +213,14 @@ public class Collections {
* @throws IllegalArgumentException (optional) if the comparator is * @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract * found to violate the {@link Comparator} contract
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> void sort(List<T> list, Comparator<? super T> c) { public static <T> void sort(List<T> list, Comparator<? super T> c) {
Object[] a = list.toArray(); Object[] a = list.toArray();
Arrays.sort(a, (Comparator)c); Arrays.sort(a, (Comparator)c);
ListIterator i = list.listIterator(); ListIterator<T> i = list.listIterator();
for (int j=0; j<a.length; j++) { for (int j=0; j<a.length; j++) {
i.next(); i.next();
i.set(a[j]); i.set((T)a[j]);
} }
} }
...@@ -357,9 +359,10 @@ public class Collections { ...@@ -357,9 +359,10 @@ public class Collections {
* or the search key is not mutually comparable with the * or the search key is not mutually comparable with the
* elements of the list using this comparator. * elements of the list using this comparator.
*/ */
@SuppressWarnings("unchecked")
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) { public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) {
if (c==null) if (c==null)
return binarySearch((List) list, key); return binarySearch((List<? extends Comparable<? super T>>) list, key);
if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD) if (list instanceof RandomAccess || list.size()<BINARYSEARCH_THRESHOLD)
return Collections.indexedBinarySearch(list, key, c); return Collections.indexedBinarySearch(list, key, c);
...@@ -406,9 +409,6 @@ public class Collections { ...@@ -406,9 +409,6 @@ public class Collections {
return -(low + 1); // key not found return -(low + 1); // key not found
} }
private interface SelfComparable extends Comparable<SelfComparable> {}
/** /**
* Reverses the order of the elements in the specified list.<p> * Reverses the order of the elements in the specified list.<p>
* *
...@@ -418,12 +418,16 @@ public class Collections { ...@@ -418,12 +418,16 @@ public class Collections {
* @throws UnsupportedOperationException if the specified list or * @throws UnsupportedOperationException if the specified list or
* its list-iterator does not support the <tt>set</tt> operation. * its list-iterator does not support the <tt>set</tt> operation.
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void reverse(List<?> list) { public static void reverse(List<?> list) {
int size = list.size(); int size = list.size();
if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) { if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--) for (int i=0, mid=size>>1, j=size-1; i<mid; i++, j--)
swap(list, i, j); swap(list, i, j);
} else { } else {
// instead of using a raw type here, it's possible to capture
// the wildcard but it will require a call to a supplementary
// private method
ListIterator fwd = list.listIterator(); ListIterator fwd = list.listIterator();
ListIterator rev = list.listIterator(size); ListIterator rev = list.listIterator(size);
for (int i=0, mid=list.size()>>1; i<mid; i++) { for (int i=0, mid=list.size()>>1; i<mid; i++) {
...@@ -493,6 +497,7 @@ public class Collections { ...@@ -493,6 +497,7 @@ public class Collections {
* @throws UnsupportedOperationException if the specified list or its * @throws UnsupportedOperationException if the specified list or its
* list-iterator does not support the <tt>set</tt> operation. * list-iterator does not support the <tt>set</tt> operation.
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void shuffle(List<?> list, Random rnd) { public static void shuffle(List<?> list, Random rnd) {
int size = list.size(); int size = list.size();
if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) { if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
...@@ -506,6 +511,9 @@ public class Collections { ...@@ -506,6 +511,9 @@ public class Collections {
swap(arr, i-1, rnd.nextInt(i)); swap(arr, i-1, rnd.nextInt(i));
// Dump array back into list // Dump array back into list
// instead of using a raw type here, it's possible to capture
// the wildcard but it will require a call to a supplementary
// private method
ListIterator it = list.listIterator(); ListIterator it = list.listIterator();
for (int i=0; i<arr.length; i++) { for (int i=0; i<arr.length; i++) {
it.next(); it.next();
...@@ -527,7 +535,11 @@ public class Collections { ...@@ -527,7 +535,11 @@ public class Collections {
* || j &lt; 0 || j &gt;= list.size()). * || j &lt; 0 || j &gt;= list.size()).
* @since 1.4 * @since 1.4
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void swap(List<?> list, int i, int j) { public static void swap(List<?> list, int i, int j) {
// instead of using a raw type here, it's possible to capture
// the wildcard but it will require a call to a supplementary
// private method
final List l = list; final List l = list;
l.set(i, l.set(j, l.get(i))); l.set(i, l.set(j, l.get(i)));
} }
...@@ -657,9 +669,10 @@ public class Collections { ...@@ -657,9 +669,10 @@ public class Collections {
* @throws NoSuchElementException if the collection is empty. * @throws NoSuchElementException if the collection is empty.
* @see Comparable * @see Comparable
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) { public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
if (comp==null) if (comp==null)
return (T)min((Collection<SelfComparable>) (Collection) coll); return (T)min((Collection) coll);
Iterator<? extends T> i = coll.iterator(); Iterator<? extends T> i = coll.iterator();
T candidate = i.next(); T candidate = i.next();
...@@ -727,9 +740,10 @@ public class Collections { ...@@ -727,9 +740,10 @@ public class Collections {
* @throws NoSuchElementException if the collection is empty. * @throws NoSuchElementException if the collection is empty.
* @see Comparable * @see Comparable
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) { public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
if (comp==null) if (comp==null)
return (T)max((Collection<SelfComparable>) (Collection) coll); return (T)max((Collection) coll);
Iterator<? extends T> i = coll.iterator(); Iterator<? extends T> i = coll.iterator();
T candidate = i.next(); T candidate = i.next();
...@@ -1389,7 +1403,9 @@ public class Collections { ...@@ -1389,7 +1403,9 @@ public class Collections {
extends UnmodifiableSet<Map.Entry<K,V>> { extends UnmodifiableSet<Map.Entry<K,V>> {
private static final long serialVersionUID = 7854390611657943733L; private static final long serialVersionUID = 7854390611657943733L;
@SuppressWarnings({ "unchecked", "rawtypes" })
UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) { UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
// Need to cast to raw in order to work around a limitation in the type system
super((Set)s); super((Set)s);
} }
public Iterator<Map.Entry<K,V>> iterator() { public Iterator<Map.Entry<K,V>> iterator() {
...@@ -1408,13 +1424,15 @@ public class Collections { ...@@ -1408,13 +1424,15 @@ public class Collections {
}; };
} }
@SuppressWarnings("unchecked")
public Object[] toArray() { public Object[] toArray() {
Object[] a = c.toArray(); Object[] a = c.toArray();
for (int i=0; i<a.length; i++) for (int i=0; i<a.length; i++)
a[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)a[i]); a[i] = new UnmodifiableEntry<>((Map.Entry<? extends K, ? extends V>)a[i]);
return a; return a;
} }
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) { public <T> T[] toArray(T[] a) {
// We don't pass a to c.toArray, to avoid window of // We don't pass a to c.toArray, to avoid window of
// vulnerability wherein an unscrupulous multithreaded client // vulnerability wherein an unscrupulous multithreaded client
...@@ -1422,7 +1440,7 @@ public class Collections { ...@@ -1422,7 +1440,7 @@ public class Collections {
Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0)); Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0));
for (int i=0; i<arr.length; i++) for (int i=0; i<arr.length; i++)
arr[i] = new UnmodifiableEntry<>((Map.Entry<K,V>)arr[i]); arr[i] = new UnmodifiableEntry<>((Map.Entry<? extends K, ? extends V>)arr[i]);
if (arr.length > a.length) if (arr.length > a.length)
return (T[])arr; return (T[])arr;
...@@ -1464,7 +1482,7 @@ public class Collections { ...@@ -1464,7 +1482,7 @@ public class Collections {
if (!(o instanceof Set)) if (!(o instanceof Set))
return false; return false;
Set s = (Set) o; Set<?> s = (Set<?>) o;
if (s.size() != c.size()) if (s.size() != c.size())
return false; return false;
return containsAll(s); // Invokes safe containsAll() above return containsAll(s); // Invokes safe containsAll() above
...@@ -1493,7 +1511,7 @@ public class Collections { ...@@ -1493,7 +1511,7 @@ public class Collections {
return true; return true;
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry t = (Map.Entry)o; Map.Entry<?,?> t = (Map.Entry<?,?>)o;
return eq(e.getKey(), t.getKey()) && return eq(e.getKey(), t.getKey()) &&
eq(e.getValue(), t.getValue()); eq(e.getValue(), t.getValue());
} }
......
...@@ -114,7 +114,6 @@ class ComparableTimSort { ...@@ -114,7 +114,6 @@ class ComparableTimSort {
// Allocate temp storage (which may be increased later if necessary) // Allocate temp storage (which may be increased later if necessary)
int len = a.length; int len = a.length;
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ? Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ?
len >>> 1 : INITIAL_TMP_STORAGE_LENGTH]; len >>> 1 : INITIAL_TMP_STORAGE_LENGTH];
tmp = newArray; tmp = newArray;
...@@ -209,14 +208,13 @@ class ComparableTimSort { ...@@ -209,14 +208,13 @@ class ComparableTimSort {
* @param start the index of the first element in the range that is * @param start the index of the first element in the range that is
* not already known to be sorted ({@code lo <= start <= hi}) * not already known to be sorted ({@code lo <= start <= hi})
*/ */
@SuppressWarnings("fallthrough") @SuppressWarnings({ "fallthrough", "rawtypes", "unchecked" })
private static void binarySort(Object[] a, int lo, int hi, int start) { private static void binarySort(Object[] a, int lo, int hi, int start) {
assert lo <= start && start <= hi; assert lo <= start && start <= hi;
if (start == lo) if (start == lo)
start++; start++;
for ( ; start < hi; start++) { for ( ; start < hi; start++) {
@SuppressWarnings("unchecked") Comparable pivot = (Comparable) a[start];
Comparable<Object> pivot = (Comparable) a[start];
// Set left (and right) to the index where a[start] (pivot) belongs // Set left (and right) to the index where a[start] (pivot) belongs
int left = lo; int left = lo;
...@@ -279,7 +277,7 @@ class ComparableTimSort { ...@@ -279,7 +277,7 @@ class ComparableTimSort {
* @return the length of the run beginning at the specified position in * @return the length of the run beginning at the specified position in
* the specified array * the specified array
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
private static int countRunAndMakeAscending(Object[] a, int lo, int hi) { private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
assert lo < hi; assert lo < hi;
int runHi = lo + 1; int runHi = lo + 1;
...@@ -614,7 +612,7 @@ class ComparableTimSort { ...@@ -614,7 +612,7 @@ class ComparableTimSort {
* (must be aBase + aLen) * (must be aBase + aLen)
* @param len2 length of second run to be merged (must be > 0) * @param len2 length of second run to be merged (must be > 0)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
private void mergeLo(int base1, int len1, int base2, int len2) { private void mergeLo(int base1, int len1, int base2, int len2) {
assert len1 > 0 && len2 > 0 && base1 + len1 == base2; assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
...@@ -731,7 +729,7 @@ class ComparableTimSort { ...@@ -731,7 +729,7 @@ class ComparableTimSort {
* (must be aBase + aLen) * (must be aBase + aLen)
* @param len2 length of second run to be merged (must be > 0) * @param len2 length of second run to be merged (must be > 0)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
private void mergeHi(int base1, int len1, int base2, int len2) { private void mergeHi(int base1, int len1, int base2, int len2) {
assert len1 > 0 && len2 > 0 && base1 + len1 == base2; assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
...@@ -865,7 +863,6 @@ class ComparableTimSort { ...@@ -865,7 +863,6 @@ class ComparableTimSort {
else else
newSize = Math.min(newSize, a.length >>> 1); newSize = Math.min(newSize, a.length >>> 1);
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
Object[] newArray = new Object[newSize]; Object[] newArray = new Object[newSize];
tmp = newArray; tmp = newArray;
} }
......
...@@ -404,7 +404,7 @@ public final class Currency implements Serializable { ...@@ -404,7 +404,7 @@ public final class Currency implements Serializable {
public static Set<Currency> getAvailableCurrencies() { public static Set<Currency> getAvailableCurrencies() {
synchronized(Currency.class) { synchronized(Currency.class) {
if (available == null) { if (available == null) {
available = new HashSet<Currency>(256); available = new HashSet<>(256);
// Add simple currencies first // Add simple currencies first
for (char c1 = 'A'; c1 <= 'Z'; c1 ++) { for (char c1 = 'A'; c1 <= 'Z'; c1 ++) {
......
...@@ -120,11 +120,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -120,11 +120,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return (value == null ? NULL : value); return (value == null ? NULL : value);
} }
@SuppressWarnings("unchecked")
private V unmaskNull(Object value) { private V unmaskNull(Object value) {
return (V) (value == NULL ? null : value); return (V)(value == NULL ? null : value);
} }
private static final Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; private static final Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
/** /**
* Creates an empty enum map with the specified key type. * Creates an empty enum map with the specified key type.
...@@ -218,12 +219,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -218,12 +219,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* key * key
*/ */
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
return isValidKey(key) && vals[((Enum)key).ordinal()] != null; return isValidKey(key) && vals[((Enum<?>)key).ordinal()] != null;
} }
private boolean containsMapping(Object key, Object value) { private boolean containsMapping(Object key, Object value) {
return isValidKey(key) && return isValidKey(key) &&
maskNull(value).equals(vals[((Enum)key).ordinal()]); maskNull(value).equals(vals[((Enum<?>)key).ordinal()]);
} }
/** /**
...@@ -243,7 +244,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -243,7 +244,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
*/ */
public V get(Object key) { public V get(Object key) {
return (isValidKey(key) ? return (isValidKey(key) ?
unmaskNull(vals[((Enum)key).ordinal()]) : null); unmaskNull(vals[((Enum<?>)key).ordinal()]) : null);
} }
// Modification Operations // Modification Operations
...@@ -285,7 +286,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -285,7 +286,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
public V remove(Object key) { public V remove(Object key) {
if (!isValidKey(key)) if (!isValidKey(key))
return null; return null;
int index = ((Enum)key).ordinal(); int index = ((Enum<?>)key).ordinal();
Object oldValue = vals[index]; Object oldValue = vals[index];
vals[index] = null; vals[index] = null;
if (oldValue != null) if (oldValue != null)
...@@ -296,7 +297,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -296,7 +297,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
private boolean removeMapping(Object key, Object value) { private boolean removeMapping(Object key, Object value) {
if (!isValidKey(key)) if (!isValidKey(key))
return false; return false;
int index = ((Enum)key).ordinal(); int index = ((Enum<?>)key).ordinal();
if (maskNull(value).equals(vals[index])) { if (maskNull(value).equals(vals[index])) {
vals[index] = null; vals[index] = null;
size--; size--;
...@@ -314,7 +315,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -314,7 +315,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return false; return false;
// Cheaper than instanceof Enum followed by getDeclaringClass // Cheaper than instanceof Enum followed by getDeclaringClass
Class keyClass = key.getClass(); Class<?> keyClass = key.getClass();
return keyClass == keyType || keyClass.getSuperclass() == keyType; return keyClass == keyType || keyClass.getSuperclass() == keyType;
} }
...@@ -331,8 +332,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -331,8 +332,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
*/ */
public void putAll(Map<? extends K, ? extends V> m) { public void putAll(Map<? extends K, ? extends V> m) {
if (m instanceof EnumMap) { if (m instanceof EnumMap) {
EnumMap<? extends K, ? extends V> em = EnumMap<?, ?> em = (EnumMap<?, ?>)m;
(EnumMap<? extends K, ? extends V>)m;
if (em.keyType != keyType) { if (em.keyType != keyType) {
if (em.isEmpty()) if (em.isEmpty())
return; return;
...@@ -476,13 +476,13 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -476,13 +476,13 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry entry = (Map.Entry)o; Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return containsMapping(entry.getKey(), entry.getValue()); return containsMapping(entry.getKey(), entry.getValue());
} }
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry entry = (Map.Entry)o; Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return removeMapping(entry.getKey(), entry.getValue()); return removeMapping(entry.getKey(), entry.getValue());
} }
public int size() { public int size() {
...@@ -610,7 +610,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -610,7 +610,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
V ourValue = unmaskNull(vals[index]); V ourValue = unmaskNull(vals[index]);
Object hisValue = e.getValue(); Object hisValue = e.getValue();
return (e.getKey() == keyUniverse[index] && return (e.getKey() == keyUniverse[index] &&
...@@ -655,11 +655,11 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -655,11 +655,11 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
if (this == o) if (this == o)
return true; return true;
if (o instanceof EnumMap) if (o instanceof EnumMap)
return equals((EnumMap)o); return equals((EnumMap<?,?>)o);
if (!(o instanceof Map)) if (!(o instanceof Map))
return false; return false;
Map<K,V> m = (Map<K,V>)o; Map<?,?> m = (Map<?,?>)o;
if (size != m.size()) if (size != m.size())
return false; return false;
...@@ -680,7 +680,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -680,7 +680,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return true; return true;
} }
private boolean equals(EnumMap em) { private boolean equals(EnumMap<?,?> em) {
if (em.keyType != keyType) if (em.keyType != keyType)
return size == 0 && em.size == 0; return size == 0 && em.size == 0;
...@@ -721,6 +721,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -721,6 +721,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* *
* @return a shallow copy of this enum map * @return a shallow copy of this enum map
*/ */
@SuppressWarnings("unchecked")
public EnumMap<K, V> clone() { public EnumMap<K, V> clone() {
EnumMap<K, V> result = null; EnumMap<K, V> result = null;
try { try {
...@@ -736,7 +737,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -736,7 +737,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* Throws an exception if e is not of the correct type for this enum set. * Throws an exception if e is not of the correct type for this enum set.
*/ */
private void typeCheck(K key) { private void typeCheck(K key) {
Class keyClass = key.getClass(); Class<?> keyClass = key.getClass();
if (keyClass != keyType && keyClass.getSuperclass() != keyType) if (keyClass != keyType && keyClass.getSuperclass() != keyType)
throw new ClassCastException(keyClass + " != " + keyType); throw new ClassCastException(keyClass + " != " + keyType);
} }
...@@ -785,6 +786,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> ...@@ -785,6 +786,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* Reconstitute the <tt>EnumMap</tt> instance from a stream (i.e., * Reconstitute the <tt>EnumMap</tt> instance from a stream (i.e.,
* deserialize it). * deserialize it).
*/ */
@SuppressWarnings("unchecked")
private void readObject(java.io.ObjectInputStream s) private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException throws java.io.IOException, ClassNotFoundException
{ {
......
...@@ -88,11 +88,11 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> ...@@ -88,11 +88,11 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
/** /**
* All of the values comprising T. (Cached for performance.) * All of the values comprising T. (Cached for performance.)
*/ */
final Enum[] universe; final Enum<?>[] universe;
private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; private static Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
EnumSet(Class<E>elementType, Enum[] universe) { EnumSet(Class<E>elementType, Enum<?>[] universe) {
this.elementType = elementType; this.elementType = elementType;
this.universe = universe; this.universe = universe;
} }
...@@ -105,7 +105,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> ...@@ -105,7 +105,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
* @throws NullPointerException if <tt>elementType</tt> is null * @throws NullPointerException if <tt>elementType</tt> is null
*/ */
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) { public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
Enum[] universe = getUniverse(elementType); Enum<?>[] universe = getUniverse(elementType);
if (universe == null) if (universe == null)
throw new ClassCastException(elementType + " not an enum"); throw new ClassCastException(elementType + " not an enum");
...@@ -358,6 +358,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> ...@@ -358,6 +358,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
* *
* @return a copy of this set * @return a copy of this set
*/ */
@SuppressWarnings("unchecked")
public EnumSet<E> clone() { public EnumSet<E> clone() {
try { try {
return (EnumSet<E>) super.clone(); return (EnumSet<E>) super.clone();
...@@ -375,7 +376,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> ...@@ -375,7 +376,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
* Throws an exception if e is not of the correct type for this enum set. * Throws an exception if e is not of the correct type for this enum set.
*/ */
final void typeCheck(E e) { final void typeCheck(E e) {
Class eClass = e.getClass(); Class<?> eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType) if (eClass != elementType && eClass.getSuperclass() != elementType)
throw new ClassCastException(eClass + " != " + elementType); throw new ClassCastException(eClass + " != " + elementType);
} }
...@@ -413,16 +414,19 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> ...@@ -413,16 +414,19 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
* *
* @serial * @serial
*/ */
private final Enum[] elements; private final Enum<?>[] elements;
SerializationProxy(EnumSet<E> set) { SerializationProxy(EnumSet<E> set) {
elementType = set.elementType; elementType = set.elementType;
elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY); elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY);
} }
// instead of cast to E, we should perhaps use elementType.cast()
// to avoid injection of forged stream, but it will slow the implementation
@SuppressWarnings("unchecked")
private Object readResolve() { private Object readResolve() {
EnumSet<E> result = EnumSet.noneOf(elementType); EnumSet<E> result = EnumSet.noneOf(elementType);
for (Enum e : elements) for (Enum<?> e : elements)
result.add((E)e); result.add((E)e);
return result; return result;
} }
......
...@@ -146,7 +146,7 @@ public class HashMap<K,V> ...@@ -146,7 +146,7 @@ public class HashMap<K,V>
/** /**
* The table, resized as necessary. Length MUST Always be a power of two. * The table, resized as necessary. Length MUST Always be a power of two.
*/ */
transient Entry[] table; transient Entry<?,?>[] table;
/** /**
* The number of key-value mappings contained in this map. * The number of key-value mappings contained in this map.
...@@ -311,16 +311,17 @@ public class HashMap<K,V> ...@@ -311,16 +311,17 @@ public class HashMap<K,V>
* *
* @see #put(Object, Object) * @see #put(Object, Object)
*/ */
@SuppressWarnings("unchecked")
public V get(Object key) { public V get(Object key) {
if (key == null) if (key == null)
return getForNullKey(); return (V)getForNullKey();
int hash = hash(key.hashCode()); int hash = hash(key.hashCode());
for (Entry<K,V> e = table[indexFor(hash, table.length)]; for (Entry<?,?> e = table[indexFor(hash, table.length)];
e != null; e != null;
e = e.next) { e = e.next) {
Object k; Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
return e.value; return (V)e.value;
} }
return null; return null;
} }
...@@ -332,8 +333,8 @@ public class HashMap<K,V> ...@@ -332,8 +333,8 @@ public class HashMap<K,V>
* operations (get and put), but incorporated with conditionals in * operations (get and put), but incorporated with conditionals in
* others. * others.
*/ */
private V getForNullKey() { private Object getForNullKey() {
for (Entry<K,V> e = table[0]; e != null; e = e.next) { for (Entry<?,?> e = table[0]; e != null; e = e.next) {
if (e.key == null) if (e.key == null)
return e.value; return e.value;
} }
...@@ -357,15 +358,16 @@ public class HashMap<K,V> ...@@ -357,15 +358,16 @@ public class HashMap<K,V>
* HashMap. Returns null if the HashMap contains no mapping * HashMap. Returns null if the HashMap contains no mapping
* for the key. * for the key.
*/ */
@SuppressWarnings("unchecked")
final Entry<K,V> getEntry(Object key) { final Entry<K,V> getEntry(Object key) {
int hash = (key == null) ? 0 : hash(key.hashCode()); int hash = (key == null) ? 0 : hash(key.hashCode());
for (Entry<K,V> e = table[indexFor(hash, table.length)]; for (Entry<?,?> e = table[indexFor(hash, table.length)];
e != null; e != null;
e = e.next) { e = e.next) {
Object k; Object k;
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) ((k = e.key) == key || (key != null && key.equals(k))))
return e; return (Entry<K,V>)e;
} }
return null; return null;
} }
...@@ -388,7 +390,9 @@ public class HashMap<K,V> ...@@ -388,7 +390,9 @@ public class HashMap<K,V>
return putForNullKey(value); return putForNullKey(value);
int hash = hash(key.hashCode()); int hash = hash(key.hashCode());
int i = indexFor(hash, table.length); int i = indexFor(hash, table.length);
for (Entry<K,V> e = table[i]; e != null; e = e.next) { @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)table[i];
for(; e != null; e = e.next) {
Object k; Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
V oldValue = e.value; V oldValue = e.value;
...@@ -407,7 +411,9 @@ public class HashMap<K,V> ...@@ -407,7 +411,9 @@ public class HashMap<K,V>
* Offloaded version of put for null keys * Offloaded version of put for null keys
*/ */
private V putForNullKey(V value) { private V putForNullKey(V value) {
for (Entry<K,V> e = table[0]; e != null; e = e.next) { @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)table[0];
for(; e != null; e = e.next) {
if (e.key == null) { if (e.key == null) {
V oldValue = e.value; V oldValue = e.value;
e.value = value; e.value = value;
...@@ -435,7 +441,8 @@ public class HashMap<K,V> ...@@ -435,7 +441,8 @@ public class HashMap<K,V>
* clone or deserialize. It will only happen for construction if the * clone or deserialize. It will only happen for construction if the
* input Map is a sorted map whose ordering is inconsistent w/ equals. * input Map is a sorted map whose ordering is inconsistent w/ equals.
*/ */
for (Entry<K,V> e = table[i]; e != null; e = e.next) { for (@SuppressWarnings("unchecked")
Entry<?,V> e = (Entry<?,V>)table[i]; e != null; e = e.next) {
Object k; Object k;
if (e.hash == hash && if (e.hash == hash &&
((k = e.key) == key || (key != null && key.equals(k)))) { ((k = e.key) == key || (key != null && key.equals(k)))) {
...@@ -467,14 +474,14 @@ public class HashMap<K,V> ...@@ -467,14 +474,14 @@ public class HashMap<K,V>
* is irrelevant). * is irrelevant).
*/ */
void resize(int newCapacity) { void resize(int newCapacity) {
Entry[] oldTable = table; Entry<?,?>[] oldTable = table;
int oldCapacity = oldTable.length; int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) { if (oldCapacity == MAXIMUM_CAPACITY) {
threshold = Integer.MAX_VALUE; threshold = Integer.MAX_VALUE;
return; return;
} }
Entry[] newTable = new Entry[newCapacity]; Entry<?,?>[] newTable = new Entry<?,?>[newCapacity];
transfer(newTable); transfer(newTable);
table = newTable; table = newTable;
threshold = (int)(newCapacity * loadFactor); threshold = (int)(newCapacity * loadFactor);
...@@ -483,17 +490,18 @@ public class HashMap<K,V> ...@@ -483,17 +490,18 @@ public class HashMap<K,V>
/** /**
* Transfers all entries from current table to newTable. * Transfers all entries from current table to newTable.
*/ */
void transfer(Entry[] newTable) { @SuppressWarnings("unchecked")
Entry[] src = table; void transfer(Entry<?,?>[] newTable) {
Entry<?,?>[] src = table;
int newCapacity = newTable.length; int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) { for (int j = 0; j < src.length; j++) {
Entry<K,V> e = src[j]; Entry<K,V> e = (Entry<K,V>)src[j];
if (e != null) { if (e != null) {
src[j] = null; src[j] = null;
do { do {
Entry<K,V> next = e.next; Entry<K,V> next = e.next;
int i = indexFor(e.hash, newCapacity); int i = indexFor(e.hash, newCapacity);
e.next = newTable[i]; e.next = (Entry<K,V>)newTable[i];
newTable[i] = e; newTable[i] = e;
e = next; e = next;
} while (e != null); } while (e != null);
...@@ -560,7 +568,8 @@ public class HashMap<K,V> ...@@ -560,7 +568,8 @@ public class HashMap<K,V>
final Entry<K,V> removeEntryForKey(Object key) { final Entry<K,V> removeEntryForKey(Object key) {
int hash = (key == null) ? 0 : hash(key.hashCode()); int hash = (key == null) ? 0 : hash(key.hashCode());
int i = indexFor(hash, table.length); int i = indexFor(hash, table.length);
Entry<K,V> prev = table[i]; @SuppressWarnings("unchecked")
Entry<K,V> prev = (Entry<K,V>)table[i];
Entry<K,V> e = prev; Entry<K,V> e = prev;
while (e != null) { while (e != null) {
...@@ -591,11 +600,12 @@ public class HashMap<K,V> ...@@ -591,11 +600,12 @@ public class HashMap<K,V>
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return null; return null;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object key = entry.getKey(); Object key = entry.getKey();
int hash = (key == null) ? 0 : hash(key.hashCode()); int hash = (key == null) ? 0 : hash(key.hashCode());
int i = indexFor(hash, table.length); int i = indexFor(hash, table.length);
Entry<K,V> prev = table[i]; @SuppressWarnings("unchecked")
Entry<K,V> prev = (Entry<K,V>)table[i];
Entry<K,V> e = prev; Entry<K,V> e = prev;
while (e != null) { while (e != null) {
...@@ -623,7 +633,7 @@ public class HashMap<K,V> ...@@ -623,7 +633,7 @@ public class HashMap<K,V>
*/ */
public void clear() { public void clear() {
modCount++; modCount++;
Entry[] tab = table; Entry<?,?>[] tab = table;
for (int i = 0; i < tab.length; i++) for (int i = 0; i < tab.length; i++)
tab[i] = null; tab[i] = null;
size = 0; size = 0;
...@@ -641,9 +651,9 @@ public class HashMap<K,V> ...@@ -641,9 +651,9 @@ public class HashMap<K,V>
if (value == null) if (value == null)
return containsNullValue(); return containsNullValue();
Entry[] tab = table; Entry<?,?>[] tab = table;
for (int i = 0; i < tab.length ; i++) for (int i = 0; i < tab.length ; i++)
for (Entry e = tab[i] ; e != null ; e = e.next) for (Entry<?,?> e = tab[i] ; e != null ; e = e.next)
if (value.equals(e.value)) if (value.equals(e.value))
return true; return true;
return false; return false;
...@@ -653,9 +663,9 @@ public class HashMap<K,V> ...@@ -653,9 +663,9 @@ public class HashMap<K,V>
* Special-case code for containsValue with null argument * Special-case code for containsValue with null argument
*/ */
private boolean containsNullValue() { private boolean containsNullValue() {
Entry[] tab = table; Entry<?,?>[] tab = table;
for (int i = 0; i < tab.length ; i++) for (int i = 0; i < tab.length ; i++)
for (Entry e = tab[i] ; e != null ; e = e.next) for (Entry<?,?> e = tab[i] ; e != null ; e = e.next)
if (e.value == null) if (e.value == null)
return true; return true;
return false; return false;
...@@ -667,6 +677,7 @@ public class HashMap<K,V> ...@@ -667,6 +677,7 @@ public class HashMap<K,V>
* *
* @return a shallow copy of this map * @return a shallow copy of this map
*/ */
@SuppressWarnings("unchecked")
public Object clone() { public Object clone() {
HashMap<K,V> result = null; HashMap<K,V> result = null;
try { try {
...@@ -674,7 +685,7 @@ public class HashMap<K,V> ...@@ -674,7 +685,7 @@ public class HashMap<K,V>
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
// assert false; // assert false;
} }
result.table = new Entry[table.length]; result.table = new Entry<?,?>[table.length];
result.entrySet = null; result.entrySet = null;
result.modCount = 0; result.modCount = 0;
result.size = 0; result.size = 0;
...@@ -717,7 +728,7 @@ public class HashMap<K,V> ...@@ -717,7 +728,7 @@ public class HashMap<K,V>
public final boolean equals(Object o) { public final boolean equals(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
Object k1 = getKey(); Object k1 = getKey();
Object k2 = e.getKey(); Object k2 = e.getKey();
if (k1 == k2 || (k1 != null && k1.equals(k2))) { if (k1 == k2 || (k1 != null && k1.equals(k2))) {
...@@ -762,7 +773,8 @@ public class HashMap<K,V> ...@@ -762,7 +773,8 @@ public class HashMap<K,V>
* Subclass overrides this to alter the behavior of put method. * Subclass overrides this to alter the behavior of put method.
*/ */
void addEntry(int hash, K key, V value, int bucketIndex) { void addEntry(int hash, K key, V value, int bucketIndex) {
Entry<K,V> e = table[bucketIndex]; @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)table[bucketIndex];
table[bucketIndex] = new Entry<>(hash, key, value, e); table[bucketIndex] = new Entry<>(hash, key, value, e);
if (size++ >= threshold) if (size++ >= threshold)
resize(2 * table.length); resize(2 * table.length);
...@@ -777,21 +789,22 @@ public class HashMap<K,V> ...@@ -777,21 +789,22 @@ public class HashMap<K,V>
* clone, and readObject. * clone, and readObject.
*/ */
void createEntry(int hash, K key, V value, int bucketIndex) { void createEntry(int hash, K key, V value, int bucketIndex) {
Entry<K,V> e = table[bucketIndex]; @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)table[bucketIndex];
table[bucketIndex] = new Entry<>(hash, key, value, e); table[bucketIndex] = new Entry<>(hash, key, value, e);
size++; size++;
} }
private abstract class HashIterator<E> implements Iterator<E> { private abstract class HashIterator<E> implements Iterator<E> {
Entry<K,V> next; // next entry to return Entry<?,?> next; // next entry to return
int expectedModCount; // For fast-fail int expectedModCount; // For fast-fail
int index; // current slot int index; // current slot
Entry<K,V> current; // current entry Entry<?,?> current; // current entry
HashIterator() { HashIterator() {
expectedModCount = modCount; expectedModCount = modCount;
if (size > 0) { // advance to first entry if (size > 0) { // advance to first entry
Entry[] t = table; Entry<?,?>[] t = table;
while (index < t.length && (next = t[index++]) == null) while (index < t.length && (next = t[index++]) == null)
; ;
} }
...@@ -801,20 +814,21 @@ public class HashMap<K,V> ...@@ -801,20 +814,21 @@ public class HashMap<K,V>
return next != null; return next != null;
} }
@SuppressWarnings("unchecked")
final Entry<K,V> nextEntry() { final Entry<K,V> nextEntry() {
if (modCount != expectedModCount) if (modCount != expectedModCount)
throw new ConcurrentModificationException(); throw new ConcurrentModificationException();
Entry<K,V> e = next; Entry<?,?> e = next;
if (e == null) if (e == null)
throw new NoSuchElementException(); throw new NoSuchElementException();
if ((next = e.next) == null) { if ((next = e.next) == null) {
Entry[] t = table; Entry<?,?>[] t = table;
while (index < t.length && (next = t[index++]) == null) while (index < t.length && (next = t[index++]) == null)
; ;
} }
current = e; current = e;
return e; return (Entry<K,V>)e;
} }
public void remove() { public void remove() {
...@@ -965,7 +979,7 @@ public class HashMap<K,V> ...@@ -965,7 +979,7 @@ public class HashMap<K,V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> e = (Map.Entry<K,V>) o; Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Entry<K,V> candidate = getEntry(e.getKey()); Entry<K,V> candidate = getEntry(e.getKey());
return candidate != null && candidate.equals(e); return candidate != null && candidate.equals(e);
} }
...@@ -1039,8 +1053,10 @@ public class HashMap<K,V> ...@@ -1039,8 +1053,10 @@ public class HashMap<K,V>
// Read the keys and values, and put the mappings in the HashMap // Read the keys and values, and put the mappings in the HashMap
for (int i=0; i<size; i++) { for (int i=0; i<size; i++) {
K key = (K) s.readObject(); @SuppressWarnings("unchecked")
V value = (V) s.readObject(); K key = (K) s.readObject();
@SuppressWarnings("unchecked")
V value = (V) s.readObject();
putForCreate(key, value); putForCreate(key, value);
} }
} }
......
...@@ -247,6 +247,7 @@ public class HashSet<E> ...@@ -247,6 +247,7 @@ public class HashSet<E>
* *
* @return a shallow copy of this set * @return a shallow copy of this set
*/ */
@SuppressWarnings("unchecked")
public Object clone() { public Object clone() {
try { try {
HashSet<E> newSet = (HashSet<E>) super.clone(); HashSet<E> newSet = (HashSet<E>) super.clone();
...@@ -296,7 +297,7 @@ public class HashSet<E> ...@@ -296,7 +297,7 @@ public class HashSet<E>
// Read in HashMap capacity and load factor and create backing HashMap // Read in HashMap capacity and load factor and create backing HashMap
int capacity = s.readInt(); int capacity = s.readInt();
float loadFactor = s.readFloat(); float loadFactor = s.readFloat();
map = (((HashSet)this) instanceof LinkedHashSet ? map = (((HashSet<?>)this) instanceof LinkedHashSet ?
new LinkedHashMap<E,Object>(capacity, loadFactor) : new LinkedHashMap<E,Object>(capacity, loadFactor) :
new HashMap<E,Object>(capacity, loadFactor)); new HashMap<E,Object>(capacity, loadFactor));
...@@ -305,7 +306,8 @@ public class HashSet<E> ...@@ -305,7 +306,8 @@ public class HashSet<E>
// Read in all elements in the proper order. // Read in all elements in the proper order.
for (int i=0; i<size; i++) { for (int i=0; i<size; i++) {
E e = (E) s.readObject(); @SuppressWarnings("unchecked")
E e = (E) s.readObject();
map.put(e, PRESENT); map.put(e, PRESENT);
} }
} }
......
...@@ -129,7 +129,7 @@ public class Hashtable<K,V> ...@@ -129,7 +129,7 @@ public class Hashtable<K,V>
/** /**
* The hash table data. * The hash table data.
*/ */
private transient Entry[] table; private transient Entry<?,?>[] table;
/** /**
* The total number of entries in the hash table. * The total number of entries in the hash table.
...@@ -182,7 +182,7 @@ public class Hashtable<K,V> ...@@ -182,7 +182,7 @@ public class Hashtable<K,V>
if (initialCapacity==0) if (initialCapacity==0)
initialCapacity = 1; initialCapacity = 1;
this.loadFactor = loadFactor; this.loadFactor = loadFactor;
table = new Entry[initialCapacity]; table = new Entry<?,?>[initialCapacity];
threshold = (int)(initialCapacity * loadFactor); threshold = (int)(initialCapacity * loadFactor);
} }
...@@ -288,9 +288,9 @@ public class Hashtable<K,V> ...@@ -288,9 +288,9 @@ public class Hashtable<K,V>
throw new NullPointerException(); throw new NullPointerException();
} }
Entry tab[] = table; Entry<?,?> tab[] = table;
for (int i = tab.length ; i-- > 0 ;) { for (int i = tab.length ; i-- > 0 ;) {
for (Entry<K,V> e = tab[i] ; e != null ; e = e.next) { for (Entry<?,?> e = tab[i] ; e != null ; e = e.next) {
if (e.value.equals(value)) { if (e.value.equals(value)) {
return true; return true;
} }
...@@ -326,10 +326,10 @@ public class Hashtable<K,V> ...@@ -326,10 +326,10 @@ public class Hashtable<K,V>
* @see #contains(Object) * @see #contains(Object)
*/ */
public synchronized boolean containsKey(Object key) { public synchronized boolean containsKey(Object key) {
Entry tab[] = table; Entry<?,?> tab[] = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) { for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) { if ((e.hash == hash) && e.key.equals(key)) {
return true; return true;
} }
...@@ -352,13 +352,14 @@ public class Hashtable<K,V> ...@@ -352,13 +352,14 @@ public class Hashtable<K,V>
* @throws NullPointerException if the specified key is null * @throws NullPointerException if the specified key is null
* @see #put(Object, Object) * @see #put(Object, Object)
*/ */
@SuppressWarnings("unchecked")
public synchronized V get(Object key) { public synchronized V get(Object key) {
Entry tab[] = table; Entry<?,?> tab[] = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) { for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) { if ((e.hash == hash) && e.key.equals(key)) {
return e.value; return (V)e.value;
} }
} }
return null; return null;
...@@ -379,9 +380,10 @@ public class Hashtable<K,V> ...@@ -379,9 +380,10 @@ public class Hashtable<K,V>
* number of keys in the hashtable exceeds this hashtable's capacity * number of keys in the hashtable exceeds this hashtable's capacity
* and load factor. * and load factor.
*/ */
@SuppressWarnings("unchecked")
protected void rehash() { protected void rehash() {
int oldCapacity = table.length; int oldCapacity = table.length;
Entry[] oldMap = table; Entry<?,?>[] oldMap = table;
// overflow-conscious code // overflow-conscious code
int newCapacity = (oldCapacity << 1) + 1; int newCapacity = (oldCapacity << 1) + 1;
...@@ -391,19 +393,19 @@ public class Hashtable<K,V> ...@@ -391,19 +393,19 @@ public class Hashtable<K,V>
return; return;
newCapacity = MAX_ARRAY_SIZE; newCapacity = MAX_ARRAY_SIZE;
} }
Entry[] newMap = new Entry[newCapacity]; Entry<?,?>[] newMap = new Entry<?,?>[newCapacity];
modCount++; modCount++;
threshold = (int)(newCapacity * loadFactor); threshold = (int)(newCapacity * loadFactor);
table = newMap; table = newMap;
for (int i = oldCapacity ; i-- > 0 ;) { for (int i = oldCapacity ; i-- > 0 ;) {
for (Entry<K,V> old = oldMap[i] ; old != null ; ) { for (Entry<K,V> old = (Entry<K,V>)oldMap[i] ; old != null ; ) {
Entry<K,V> e = old; Entry<K,V> e = old;
old = old.next; old = old.next;
int index = (e.hash & 0x7FFFFFFF) % newCapacity; int index = (e.hash & 0x7FFFFFFF) % newCapacity;
e.next = newMap[index]; e.next = (Entry<K,V>)newMap[index];
newMap[index] = e; newMap[index] = e;
} }
} }
...@@ -433,13 +435,15 @@ public class Hashtable<K,V> ...@@ -433,13 +435,15 @@ public class Hashtable<K,V>
} }
// Makes sure the key is not already in the hashtable. // Makes sure the key is not already in the hashtable.
Entry tab[] = table; Entry<?,?> tab[] = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) { @SuppressWarnings("unchecked")
if ((e.hash == hash) && e.key.equals(key)) { Entry<K,V> entry = (Entry<K,V>)tab[index];
V old = e.value; for(; entry != null ; entry = entry.next) {
e.value = value; if ((entry.hash == hash) && entry.key.equals(key)) {
V old = entry.value;
entry.value = value;
return old; return old;
} }
} }
...@@ -454,7 +458,8 @@ public class Hashtable<K,V> ...@@ -454,7 +458,8 @@ public class Hashtable<K,V>
} }
// Creates the new entry. // Creates the new entry.
Entry<K,V> e = tab[index]; @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)tab[index];
tab[index] = new Entry<>(hash, key, value, e); tab[index] = new Entry<>(hash, key, value, e);
count++; count++;
return null; return null;
...@@ -470,10 +475,12 @@ public class Hashtable<K,V> ...@@ -470,10 +475,12 @@ public class Hashtable<K,V>
* @throws NullPointerException if the key is <code>null</code> * @throws NullPointerException if the key is <code>null</code>
*/ */
public synchronized V remove(Object key) { public synchronized V remove(Object key) {
Entry tab[] = table; Entry<?,?> tab[] = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index], prev = null ; e != null ; prev = e, e = e.next) { @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)tab[index];
for(Entry<K,V> prev = null ; e != null ; prev = e, e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) { if ((e.hash == hash) && e.key.equals(key)) {
modCount++; modCount++;
if (prev != null) { if (prev != null) {
...@@ -508,7 +515,7 @@ public class Hashtable<K,V> ...@@ -508,7 +515,7 @@ public class Hashtable<K,V>
* Clears this hashtable so that it contains no keys. * Clears this hashtable so that it contains no keys.
*/ */
public synchronized void clear() { public synchronized void clear() {
Entry tab[] = table; Entry<?,?> tab[] = table;
modCount++; modCount++;
for (int index = tab.length; --index >= 0; ) for (int index = tab.length; --index >= 0; )
tab[index] = null; tab[index] = null;
...@@ -524,11 +531,11 @@ public class Hashtable<K,V> ...@@ -524,11 +531,11 @@ public class Hashtable<K,V>
*/ */
public synchronized Object clone() { public synchronized Object clone() {
try { try {
Hashtable<K,V> t = (Hashtable<K,V>) super.clone(); Hashtable<?,?> t = (Hashtable<?,?>)super.clone();
t.table = new Entry[table.length]; t.table = new Entry<?,?>[table.length];
for (int i = table.length ; i-- > 0 ; ) { for (int i = table.length ; i-- > 0 ; ) {
t.table[i] = (table[i] != null) t.table[i] = (table[i] != null)
? (Entry<K,V>) table[i].clone() : null; ? (Entry<?,?>) table[i].clone() : null;
} }
t.keySet = null; t.keySet = null;
t.entrySet = null; t.entrySet = null;
...@@ -675,13 +682,13 @@ public class Hashtable<K,V> ...@@ -675,13 +682,13 @@ public class Hashtable<K,V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry entry = (Map.Entry)o; Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
Object key = entry.getKey(); Object key = entry.getKey();
Entry[] tab = table; Entry<?,?>[] tab = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next) for (Entry<?,?> e = tab[index]; e != null; e = e.next)
if (e.hash==hash && e.equals(entry)) if (e.hash==hash && e.equals(entry))
return true; return true;
return false; return false;
...@@ -690,14 +697,15 @@ public class Hashtable<K,V> ...@@ -690,14 +697,15 @@ public class Hashtable<K,V>
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
K key = entry.getKey(); Object key = entry.getKey();
Entry[] tab = table; Entry<?,?>[] tab = table;
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index], prev = null; e != null; @SuppressWarnings("unchecked")
prev = e, e = e.next) { Entry<K,V> e = (Entry<K,V>)tab[index];
for(Entry<K,V> prev = null; e != null; prev = e, e = e.next) {
if (e.hash==hash && e.equals(entry)) { if (e.hash==hash && e.equals(entry)) {
modCount++; modCount++;
if (prev != null) if (prev != null)
...@@ -776,7 +784,7 @@ public class Hashtable<K,V> ...@@ -776,7 +784,7 @@ public class Hashtable<K,V>
if (!(o instanceof Map)) if (!(o instanceof Map))
return false; return false;
Map<K,V> t = (Map<K,V>) o; Map<?,?> t = (Map<?,?>) o;
if (t.size() != size()) if (t.size() != size())
return false; return false;
...@@ -826,9 +834,9 @@ public class Hashtable<K,V> ...@@ -826,9 +834,9 @@ public class Hashtable<K,V>
return h; // Returns zero return h; // Returns zero
loadFactor = -loadFactor; // Mark hashCode computation in progress loadFactor = -loadFactor; // Mark hashCode computation in progress
Entry[] tab = table; Entry<?,?>[] tab = table;
for (int i = 0; i < tab.length; i++) for (int i = 0; i < tab.length; i++)
for (Entry e = tab[i]; e != null; e = e.next) for (Entry<?,?> e = tab[i]; e != null; e = e.next)
h += e.key.hashCode() ^ e.value.hashCode(); h += e.key.hashCode() ^ e.value.hashCode();
loadFactor = -loadFactor; // Mark hashCode computation complete loadFactor = -loadFactor; // Mark hashCode computation complete
...@@ -859,7 +867,7 @@ public class Hashtable<K,V> ...@@ -859,7 +867,7 @@ public class Hashtable<K,V>
// Stack copies of the entries in the table // Stack copies of the entries in the table
for (int index = 0; index < table.length; index++) { for (int index = 0; index < table.length; index++) {
Entry entry = table[index]; Entry<?,?> entry = table[index];
while (entry != null) { while (entry != null) {
entryStack = entryStack =
...@@ -899,14 +907,15 @@ public class Hashtable<K,V> ...@@ -899,14 +907,15 @@ public class Hashtable<K,V>
length--; length--;
if (origlength > 0 && length > origlength) if (origlength > 0 && length > origlength)
length = origlength; length = origlength;
Entry<?,?>[] table = new Entry<?,?>[length];
Entry[] table = new Entry[length];
count = 0; count = 0;
// Read the number of elements and then all the key/value objects // Read the number of elements and then all the key/value objects
for (; elements > 0; elements--) { for (; elements > 0; elements--) {
K key = (K)s.readObject(); @SuppressWarnings("unchecked")
V value = (V)s.readObject(); K key = (K)s.readObject();
@SuppressWarnings("unchecked")
V value = (V)s.readObject();
// synch could be eliminated for performance // synch could be eliminated for performance
reconstitutionPut(table, key, value); reconstitutionPut(table, key, value);
} }
...@@ -924,7 +933,7 @@ public class Hashtable<K,V> ...@@ -924,7 +933,7 @@ public class Hashtable<K,V>
* because we are creating a new instance. Also, no return value * because we are creating a new instance. Also, no return value
* is needed. * is needed.
*/ */
private void reconstitutionPut(Entry[] tab, K key, V value) private void reconstitutionPut(Entry<?,?>[] tab, K key, V value)
throws StreamCorruptedException throws StreamCorruptedException
{ {
if (value == null) { if (value == null) {
...@@ -934,13 +943,14 @@ public class Hashtable<K,V> ...@@ -934,13 +943,14 @@ public class Hashtable<K,V>
// This should not happen in deserialized version. // This should not happen in deserialized version.
int hash = key.hashCode(); int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length; int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index] ; e != null ; e = e.next) { for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) { if ((e.hash == hash) && e.key.equals(key)) {
throw new java.io.StreamCorruptedException(); throw new java.io.StreamCorruptedException();
} }
} }
// Creates the new entry. // Creates the new entry.
Entry<K,V> e = tab[index]; @SuppressWarnings("unchecked")
Entry<K,V> e = (Entry<K,V>)tab[index];
tab[index] = new Entry<>(hash, key, value, e); tab[index] = new Entry<>(hash, key, value, e);
count++; count++;
} }
...@@ -961,6 +971,7 @@ public class Hashtable<K,V> ...@@ -961,6 +971,7 @@ public class Hashtable<K,V>
this.next = next; this.next = next;
} }
@SuppressWarnings("unchecked")
protected Object clone() { protected Object clone() {
return new Entry<>(hash, key, value, return new Entry<>(hash, key, value,
(next==null ? null : (Entry<K,V>) next.clone())); (next==null ? null : (Entry<K,V>) next.clone()));
...@@ -988,7 +999,7 @@ public class Hashtable<K,V> ...@@ -988,7 +999,7 @@ public class Hashtable<K,V>
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return (key==null ? e.getKey()==null : key.equals(e.getKey())) && return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
(value==null ? e.getValue()==null : value.equals(e.getValue())); (value==null ? e.getValue()==null : value.equals(e.getValue()));
...@@ -1016,10 +1027,10 @@ public class Hashtable<K,V> ...@@ -1016,10 +1027,10 @@ public class Hashtable<K,V>
* by passing an Enumeration. * by passing an Enumeration.
*/ */
private class Enumerator<T> implements Enumeration<T>, Iterator<T> { private class Enumerator<T> implements Enumeration<T>, Iterator<T> {
Entry[] table = Hashtable.this.table; Entry<?,?>[] table = Hashtable.this.table;
int index = table.length; int index = table.length;
Entry<K,V> entry = null; Entry<?,?> entry = null;
Entry<K,V> lastReturned = null; Entry<?,?> lastReturned = null;
int type; int type;
/** /**
...@@ -1041,9 +1052,9 @@ public class Hashtable<K,V> ...@@ -1041,9 +1052,9 @@ public class Hashtable<K,V>
} }
public boolean hasMoreElements() { public boolean hasMoreElements() {
Entry<K,V> e = entry; Entry<?,?> e = entry;
int i = index; int i = index;
Entry[] t = table; Entry<?,?>[] t = table;
/* Use locals for faster loop iteration */ /* Use locals for faster loop iteration */
while (e == null && i > 0) { while (e == null && i > 0) {
e = t[--i]; e = t[--i];
...@@ -1053,10 +1064,11 @@ public class Hashtable<K,V> ...@@ -1053,10 +1064,11 @@ public class Hashtable<K,V>
return e != null; return e != null;
} }
@SuppressWarnings("unchecked")
public T nextElement() { public T nextElement() {
Entry<K,V> et = entry; Entry<?,?> et = entry;
int i = index; int i = index;
Entry[] t = table; Entry<?,?>[] t = table;
/* Use locals for faster loop iteration */ /* Use locals for faster loop iteration */
while (et == null && i > 0) { while (et == null && i > 0) {
et = t[--i]; et = t[--i];
...@@ -1064,7 +1076,7 @@ public class Hashtable<K,V> ...@@ -1064,7 +1076,7 @@ public class Hashtable<K,V>
entry = et; entry = et;
index = i; index = i;
if (et != null) { if (et != null) {
Entry<K,V> e = lastReturned = entry; Entry<?,?> e = lastReturned = entry;
entry = e.next; entry = e.next;
return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e); return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e);
} }
...@@ -1091,11 +1103,12 @@ public class Hashtable<K,V> ...@@ -1091,11 +1103,12 @@ public class Hashtable<K,V>
throw new ConcurrentModificationException(); throw new ConcurrentModificationException();
synchronized(Hashtable.this) { synchronized(Hashtable.this) {
Entry[] tab = Hashtable.this.table; Entry<?,?>[] tab = Hashtable.this.table;
int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length; int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
for (Entry<K,V> e = tab[index], prev = null; e != null; @SuppressWarnings("unchecked")
prev = e, e = e.next) { Entry<K,V> e = (Entry<K,V>)tab[index];
for(Entry<K,V> prev = null; e != null; prev = e, e = e.next) {
if (e == lastReturned) { if (e == lastReturned) {
modCount++; modCount++;
expectedModCount++; expectedModCount++;
......
...@@ -327,6 +327,7 @@ public class IdentityHashMap<K,V> ...@@ -327,6 +327,7 @@ public class IdentityHashMap<K,V>
* *
* @see #put(Object, Object) * @see #put(Object, Object)
*/ */
@SuppressWarnings("unchecked")
public V get(Object key) { public V get(Object key) {
Object k = maskNull(key); Object k = maskNull(key);
Object[] tab = table; Object[] tab = table;
...@@ -431,7 +432,8 @@ public class IdentityHashMap<K,V> ...@@ -431,7 +432,8 @@ public class IdentityHashMap<K,V>
Object item; Object item;
while ( (item = tab[i]) != null) { while ( (item = tab[i]) != null) {
if (item == k) { if (item == k) {
V oldValue = (V) tab[i + 1]; @SuppressWarnings("unchecked")
V oldValue = (V) tab[i + 1];
tab[i + 1] = value; tab[i + 1] = value;
return oldValue; return oldValue;
} }
...@@ -524,7 +526,8 @@ public class IdentityHashMap<K,V> ...@@ -524,7 +526,8 @@ public class IdentityHashMap<K,V>
if (item == k) { if (item == k) {
modCount++; modCount++;
size--; size--;
V oldValue = (V) tab[i + 1]; @SuppressWarnings("unchecked")
V oldValue = (V) tab[i + 1];
tab[i + 1] = null; tab[i + 1] = null;
tab[i] = null; tab[i] = null;
closeDeletion(i); closeDeletion(i);
...@@ -638,7 +641,7 @@ public class IdentityHashMap<K,V> ...@@ -638,7 +641,7 @@ public class IdentityHashMap<K,V>
if (o == this) { if (o == this) {
return true; return true;
} else if (o instanceof IdentityHashMap) { } else if (o instanceof IdentityHashMap) {
IdentityHashMap m = (IdentityHashMap) o; IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) o;
if (m.size() != size) if (m.size() != size)
return false; return false;
...@@ -650,7 +653,7 @@ public class IdentityHashMap<K,V> ...@@ -650,7 +653,7 @@ public class IdentityHashMap<K,V>
} }
return true; return true;
} else if (o instanceof Map) { } else if (o instanceof Map) {
Map m = (Map)o; Map<?,?> m = (Map<?,?>)o;
return entrySet().equals(m.entrySet()); return entrySet().equals(m.entrySet());
} else { } else {
return false; // o is not a Map return false; // o is not a Map
...@@ -698,7 +701,7 @@ public class IdentityHashMap<K,V> ...@@ -698,7 +701,7 @@ public class IdentityHashMap<K,V>
*/ */
public Object clone() { public Object clone() {
try { try {
IdentityHashMap<K,V> m = (IdentityHashMap<K,V>) super.clone(); IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) super.clone();
m.entrySet = null; m.entrySet = null;
m.table = table.clone(); m.table = table.clone();
return m; return m;
...@@ -768,7 +771,7 @@ public class IdentityHashMap<K,V> ...@@ -768,7 +771,7 @@ public class IdentityHashMap<K,V>
int len = tab.length; int len = tab.length;
int d = deletedSlot; int d = deletedSlot;
K key = (K) tab[d]; Object key = tab[d];
tab[d] = null; // vacate the slot tab[d] = null; // vacate the slot
tab[d + 1] = null; tab[d + 1] = null;
...@@ -818,12 +821,14 @@ public class IdentityHashMap<K,V> ...@@ -818,12 +821,14 @@ public class IdentityHashMap<K,V>
} }
private class KeyIterator extends IdentityHashMapIterator<K> { private class KeyIterator extends IdentityHashMapIterator<K> {
@SuppressWarnings("unchecked")
public K next() { public K next() {
return (K) unmaskNull(traversalTable[nextIndex()]); return (K) unmaskNull(traversalTable[nextIndex()]);
} }
} }
private class ValueIterator extends IdentityHashMapIterator<V> { private class ValueIterator extends IdentityHashMapIterator<V> {
@SuppressWarnings("unchecked")
public V next() { public V next() {
return (V) traversalTable[nextIndex() + 1]; return (V) traversalTable[nextIndex() + 1];
} }
...@@ -854,16 +859,19 @@ public class IdentityHashMap<K,V> ...@@ -854,16 +859,19 @@ public class IdentityHashMap<K,V>
this.index = index; this.index = index;
} }
@SuppressWarnings("unchecked")
public K getKey() { public K getKey() {
checkIndexForEntryUse(); checkIndexForEntryUse();
return (K) unmaskNull(traversalTable[index]); return (K) unmaskNull(traversalTable[index]);
} }
@SuppressWarnings("unchecked")
public V getValue() { public V getValue() {
checkIndexForEntryUse(); checkIndexForEntryUse();
return (V) traversalTable[index+1]; return (V) traversalTable[index+1];
} }
@SuppressWarnings("unchecked")
public V setValue(V value) { public V setValue(V value) {
checkIndexForEntryUse(); checkIndexForEntryUse();
V oldValue = (V) traversalTable[index+1]; V oldValue = (V) traversalTable[index+1];
...@@ -880,7 +888,7 @@ public class IdentityHashMap<K,V> ...@@ -880,7 +888,7 @@ public class IdentityHashMap<K,V>
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry e = (Map.Entry)o; Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return (e.getKey() == unmaskNull(traversalTable[index]) && return (e.getKey() == unmaskNull(traversalTable[index]) &&
e.getValue() == traversalTable[index+1]); e.getValue() == traversalTable[index+1]);
} }
...@@ -1109,13 +1117,13 @@ public class IdentityHashMap<K,V> ...@@ -1109,13 +1117,13 @@ public class IdentityHashMap<K,V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry entry = (Map.Entry)o; Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return containsMapping(entry.getKey(), entry.getValue()); return containsMapping(entry.getKey(), entry.getValue());
} }
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry entry = (Map.Entry)o; Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return removeMapping(entry.getKey(), entry.getValue()); return removeMapping(entry.getKey(), entry.getValue());
} }
public int size() { public int size() {
...@@ -1213,8 +1221,10 @@ public class IdentityHashMap<K,V> ...@@ -1213,8 +1221,10 @@ public class IdentityHashMap<K,V>
// Read the keys and values, and put the mappings in the table // Read the keys and values, and put the mappings in the table
for (int i=0; i<size; i++) { for (int i=0; i<size; i++) {
K key = (K) s.readObject(); @SuppressWarnings("unchecked")
V value = (V) s.readObject(); K key = (K) s.readObject();
@SuppressWarnings("unchecked")
V value = (V) s.readObject();
putForCreate(key, value); putForCreate(key, value);
} }
} }
...@@ -1226,7 +1236,7 @@ public class IdentityHashMap<K,V> ...@@ -1226,7 +1236,7 @@ public class IdentityHashMap<K,V>
private void putForCreate(K key, V value) private void putForCreate(K key, V value)
throws IOException throws IOException
{ {
K k = (K)maskNull(key); Object k = maskNull(key);
Object[] tab = table; Object[] tab = table;
int len = tab.length; int len = tab.length;
int i = hash(k, len); int i = hash(k, len);
......
...@@ -40,7 +40,7 @@ public class IllegalFormatConversionException extends IllegalFormatException { ...@@ -40,7 +40,7 @@ public class IllegalFormatConversionException extends IllegalFormatException {
private static final long serialVersionUID = 17000126L; private static final long serialVersionUID = 17000126L;
private char c; private char c;
private Class arg; private Class<?> arg;
/** /**
* Constructs an instance of this class with the mismatched conversion and * Constructs an instance of this class with the mismatched conversion and
......
...@@ -46,7 +46,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -46,7 +46,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
// Redundant - maintained for performance // Redundant - maintained for performance
private int size = 0; private int size = 0;
JumboEnumSet(Class<E>elementType, Enum[] universe) { JumboEnumSet(Class<E>elementType, Enum<?>[] universe) {
super(elementType, universe); super(elementType, universe);
elements = new long[(universe.length + 63) >>> 6]; elements = new long[(universe.length + 63) >>> 6];
} }
...@@ -127,6 +127,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -127,6 +127,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
return unseen != 0; return unseen != 0;
} }
@Override
public E next() { public E next() {
if (!hasNext()) if (!hasNext())
throw new NoSuchElementException(); throw new NoSuchElementException();
...@@ -176,11 +177,11 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -176,11 +177,11 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
public boolean contains(Object e) { public boolean contains(Object e) {
if (e == null) if (e == null)
return false; return false;
Class eClass = e.getClass(); Class<?> eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType) if (eClass != elementType && eClass.getSuperclass() != elementType)
return false; return false;
int eOrdinal = ((Enum)e).ordinal(); int eOrdinal = ((Enum<?>)e).ordinal();
return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0; return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0;
} }
...@@ -217,10 +218,10 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -217,10 +218,10 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
public boolean remove(Object e) { public boolean remove(Object e) {
if (e == null) if (e == null)
return false; return false;
Class eClass = e.getClass(); Class<?> eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType) if (eClass != elementType && eClass.getSuperclass() != elementType)
return false; return false;
int eOrdinal = ((Enum)e).ordinal(); int eOrdinal = ((Enum<?>)e).ordinal();
int eWordNum = eOrdinal >>> 6; int eWordNum = eOrdinal >>> 6;
long oldElements = elements[eWordNum]; long oldElements = elements[eWordNum];
...@@ -246,7 +247,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -246,7 +247,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof JumboEnumSet)) if (!(c instanceof JumboEnumSet))
return super.containsAll(c); return super.containsAll(c);
JumboEnumSet es = (JumboEnumSet)c; JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) if (es.elementType != elementType)
return es.isEmpty(); return es.isEmpty();
...@@ -268,7 +269,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -268,7 +269,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof JumboEnumSet)) if (!(c instanceof JumboEnumSet))
return super.addAll(c); return super.addAll(c);
JumboEnumSet es = (JumboEnumSet)c; JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) { if (es.elementType != elementType) {
if (es.isEmpty()) if (es.isEmpty())
return false; return false;
...@@ -294,7 +295,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -294,7 +295,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof JumboEnumSet)) if (!(c instanceof JumboEnumSet))
return super.removeAll(c); return super.removeAll(c);
JumboEnumSet es = (JumboEnumSet)c; JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) if (es.elementType != elementType)
return false; return false;
...@@ -348,7 +349,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -348,7 +349,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(o instanceof JumboEnumSet)) if (!(o instanceof JumboEnumSet))
return super.equals(o); return super.equals(o);
JumboEnumSet es = (JumboEnumSet)o; JumboEnumSet<?> es = (JumboEnumSet<?>)o;
if (es.elementType != elementType) if (es.elementType != elementType)
return size == 0 && es.size == 0; return size == 0 && es.size == 0;
......
...@@ -246,11 +246,12 @@ public class LinkedHashMap<K,V> ...@@ -246,11 +246,12 @@ public class LinkedHashMap<K,V>
* by superclass resize. It is overridden for performance, as it is * by superclass resize. It is overridden for performance, as it is
* faster to iterate using our linked list. * faster to iterate using our linked list.
*/ */
@SuppressWarnings("unchecked")
void transfer(HashMap.Entry[] newTable) { void transfer(HashMap.Entry[] newTable) {
int newCapacity = newTable.length; int newCapacity = newTable.length;
for (Entry<K,V> e = header.after; e != header; e = e.after) { for (Entry<K,V> e = header.after; e != header; e = e.after) {
int index = indexFor(e.hash, newCapacity); int index = indexFor(e.hash, newCapacity);
e.next = newTable[index]; e.next = (HashMap.Entry<K,V>)newTable[index];
newTable[index] = e; newTable[index] = e;
} }
} }
...@@ -267,11 +268,11 @@ public class LinkedHashMap<K,V> ...@@ -267,11 +268,11 @@ public class LinkedHashMap<K,V>
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
// Overridden to take advantage of faster iterator // Overridden to take advantage of faster iterator
if (value==null) { if (value==null) {
for (Entry e = header.after; e != header; e = e.after) for (Entry<?,?> e = header.after; e != header; e = e.after)
if (e.value==null) if (e.value==null)
return true; return true;
} else { } else {
for (Entry e = header.after; e != header; e = e.after) for (Entry<?,?> e = header.after; e != header; e = e.after)
if (value.equals(e.value)) if (value.equals(e.value))
return true; return true;
} }
...@@ -437,7 +438,8 @@ public class LinkedHashMap<K,V> ...@@ -437,7 +438,8 @@ public class LinkedHashMap<K,V>
* table or remove the eldest entry. * table or remove the eldest entry.
*/ */
void createEntry(int hash, K key, V value, int bucketIndex) { void createEntry(int hash, K key, V value, int bucketIndex) {
HashMap.Entry<K,V> old = table[bucketIndex]; @SuppressWarnings("unchecked")
HashMap.Entry<K,V> old = (HashMap.Entry<K,V>)table[bucketIndex];
Entry<K,V> e = new Entry<>(hash, key, value, old); Entry<K,V> e = new Entry<>(hash, key, value, old);
table[bucketIndex] = e; table[bucketIndex] = e;
e.addBefore(header); e.addBefore(header);
......
...@@ -61,12 +61,12 @@ package java.util; ...@@ -61,12 +61,12 @@ package java.util;
*/ */
public class Observable { public class Observable {
private boolean changed = false; private boolean changed = false;
private Vector obs; private Vector<Observer> obs;
/** Construct an Observable with zero Observers. */ /** Construct an Observable with zero Observers. */
public Observable() { public Observable() {
obs = new Vector(); obs = new Vector<>();
} }
/** /**
......
...@@ -449,6 +449,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -449,6 +449,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
* this queue * this queue
* @throws NullPointerException if the specified array is null * @throws NullPointerException if the specified array is null
*/ */
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) { public <T> T[] toArray(T[] a) {
if (a.length < size) if (a.length < size)
// Make a new array of a's runtime type, but my contents: // Make a new array of a's runtime type, but my contents:
...@@ -514,6 +515,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -514,6 +515,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
(forgetMeNot != null && !forgetMeNot.isEmpty()); (forgetMeNot != null && !forgetMeNot.isEmpty());
} }
@SuppressWarnings("unchecked")
public E next() { public E next() {
if (expectedModCount != modCount) if (expectedModCount != modCount)
throw new ConcurrentModificationException(); throw new ConcurrentModificationException();
...@@ -571,8 +573,10 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -571,8 +573,10 @@ public class PriorityQueue<E> extends AbstractQueue<E>
return null; return null;
int s = --size; int s = --size;
modCount++; modCount++;
E result = (E) queue[0]; @SuppressWarnings("unchecked")
E x = (E) queue[s]; E result = (E) queue[0];
@SuppressWarnings("unchecked")
E x = (E) queue[s];
queue[s] = null; queue[s] = null;
if (s != 0) if (s != 0)
siftDown(0, x); siftDown(0, x);
...@@ -598,7 +602,8 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -598,7 +602,8 @@ public class PriorityQueue<E> extends AbstractQueue<E>
if (s == i) // removed last element if (s == i) // removed last element
queue[i] = null; queue[i] = null;
else { else {
E moved = (E) queue[s]; @SuppressWarnings("unchecked")
E moved = (E) queue[s];
queue[s] = null; queue[s] = null;
siftDown(i, moved); siftDown(i, moved);
if (queue[i] == moved) { if (queue[i] == moved) {
...@@ -629,6 +634,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -629,6 +634,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
siftUpComparable(k, x); siftUpComparable(k, x);
} }
@SuppressWarnings("unchecked")
private void siftUpComparable(int k, E x) { private void siftUpComparable(int k, E x) {
Comparable<? super E> key = (Comparable<? super E>) x; Comparable<? super E> key = (Comparable<? super E>) x;
while (k > 0) { while (k > 0) {
...@@ -645,8 +651,9 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -645,8 +651,9 @@ public class PriorityQueue<E> extends AbstractQueue<E>
private void siftUpUsingComparator(int k, E x) { private void siftUpUsingComparator(int k, E x) {
while (k > 0) { while (k > 0) {
int parent = (k - 1) >>> 1; int parent = (k - 1) >>> 1;
Object e = queue[parent]; @SuppressWarnings("unchecked")
if (comparator.compare(x, (E) e) >= 0) E e = (E) queue[parent];
if (comparator.compare(x, e) >= 0)
break; break;
queue[k] = e; queue[k] = e;
k = parent; k = parent;
...@@ -669,6 +676,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -669,6 +676,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
siftDownComparable(k, x); siftDownComparable(k, x);
} }
@SuppressWarnings("unchecked")
private void siftDownComparable(int k, E x) { private void siftDownComparable(int k, E x) {
Comparable<? super E> key = (Comparable<? super E>)x; Comparable<? super E> key = (Comparable<? super E>)x;
int half = size >>> 1; // loop while a non-leaf int half = size >>> 1; // loop while a non-leaf
...@@ -687,6 +695,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -687,6 +695,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
queue[k] = key; queue[k] = key;
} }
@SuppressWarnings("unchecked")
private void siftDownUsingComparator(int k, E x) { private void siftDownUsingComparator(int k, E x) {
int half = size >>> 1; int half = size >>> 1;
while (k < half) { while (k < half) {
...@@ -708,6 +717,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> ...@@ -708,6 +717,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
* Establishes the heap invariant (described above) in the entire tree, * Establishes the heap invariant (described above) in the entire tree,
* assuming nothing about the order of the elements prior to the call. * assuming nothing about the order of the elements prior to the call.
*/ */
@SuppressWarnings("unchecked")
private void heapify() { private void heapify() {
for (int i = (size >>> 1) - 1; i >= 0; i--) for (int i = (size >>> 1) - 1; i >= 0; i--)
siftDown(i, (E) queue[i]); siftDown(i, (E) queue[i]);
......
...@@ -824,7 +824,7 @@ class Properties extends Hashtable<Object,Object> { ...@@ -824,7 +824,7 @@ class Properties extends Hashtable<Object,Object> {
bw.write("#" + new Date().toString()); bw.write("#" + new Date().toString());
bw.newLine(); bw.newLine();
synchronized (this) { synchronized (this) {
for (Enumeration e = keys(); e.hasMoreElements();) { for (Enumeration<?> e = keys(); e.hasMoreElements();) {
String key = (String)e.nextElement(); String key = (String)e.nextElement();
String val = (String)get(key); String val = (String)get(key);
key = saveConvert(key, true, escUnicode); key = saveConvert(key, true, escUnicode);
...@@ -987,7 +987,7 @@ class Properties extends Hashtable<Object,Object> { ...@@ -987,7 +987,7 @@ class Properties extends Hashtable<Object,Object> {
* @see #stringPropertyNames * @see #stringPropertyNames
*/ */
public Enumeration<?> propertyNames() { public Enumeration<?> propertyNames() {
Hashtable h = new Hashtable(); Hashtable<String,Object> h = new Hashtable<>();
enumerate(h); enumerate(h);
return h.keys(); return h.keys();
} }
...@@ -1026,10 +1026,10 @@ class Properties extends Hashtable<Object,Object> { ...@@ -1026,10 +1026,10 @@ class Properties extends Hashtable<Object,Object> {
*/ */
public void list(PrintStream out) { public void list(PrintStream out) {
out.println("-- listing properties --"); out.println("-- listing properties --");
Hashtable h = new Hashtable(); Hashtable<String,Object> h = new Hashtable<>();
enumerate(h); enumerate(h);
for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { for (Enumeration<String> e = h.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement(); String key = e.nextElement();
String val = (String)h.get(key); String val = (String)h.get(key);
if (val.length() > 40) { if (val.length() > 40) {
val = val.substring(0, 37) + "..."; val = val.substring(0, 37) + "...";
...@@ -1054,10 +1054,10 @@ class Properties extends Hashtable<Object,Object> { ...@@ -1054,10 +1054,10 @@ class Properties extends Hashtable<Object,Object> {
*/ */
public void list(PrintWriter out) { public void list(PrintWriter out) {
out.println("-- listing properties --"); out.println("-- listing properties --");
Hashtable h = new Hashtable(); Hashtable<String,Object> h = new Hashtable<>();
enumerate(h); enumerate(h);
for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { for (Enumeration<String> e = h.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement(); String key = e.nextElement();
String val = (String)h.get(key); String val = (String)h.get(key);
if (val.length() > 40) { if (val.length() > 40) {
val = val.substring(0, 37) + "..."; val = val.substring(0, 37) + "...";
...@@ -1072,11 +1072,11 @@ class Properties extends Hashtable<Object,Object> { ...@@ -1072,11 +1072,11 @@ class Properties extends Hashtable<Object,Object> {
* @throws ClassCastException if any of the property keys * @throws ClassCastException if any of the property keys
* is not of String type. * is not of String type.
*/ */
private synchronized void enumerate(Hashtable h) { private synchronized void enumerate(Hashtable<String,Object> h) {
if (defaults != null) { if (defaults != null) {
defaults.enumerate(h); defaults.enumerate(h);
} }
for (Enumeration e = keys() ; e.hasMoreElements() ;) { for (Enumeration<?> e = keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement(); String key = (String)e.nextElement();
h.put(key, get(key)); h.put(key, get(key));
} }
...@@ -1091,7 +1091,7 @@ class Properties extends Hashtable<Object,Object> { ...@@ -1091,7 +1091,7 @@ class Properties extends Hashtable<Object,Object> {
if (defaults != null) { if (defaults != null) {
defaults.enumerateStringProperties(h); defaults.enumerateStringProperties(h);
} }
for (Enumeration e = keys() ; e.hasMoreElements() ;) { for (Enumeration<?> e = keys() ; e.hasMoreElements() ;) {
Object k = e.nextElement(); Object k = e.nextElement();
Object v = get(k); Object v = get(k);
if (k instanceof String && v instanceof String) { if (k instanceof String && v instanceof String) {
......
...@@ -442,7 +442,7 @@ implements Serializable ...@@ -442,7 +442,7 @@ implements Serializable
* Key is property name; value is PropertyPermission. * Key is property name; value is PropertyPermission.
* Not serialized; see serialization section at end of class. * Not serialized; see serialization section at end of class.
*/ */
private transient Map<String, Permission> perms; private transient Map<String, PropertyPermission> perms;
/** /**
* Boolean saying if "*" is in the collection. * Boolean saying if "*" is in the collection.
...@@ -488,7 +488,7 @@ implements Serializable ...@@ -488,7 +488,7 @@ implements Serializable
String propName = pp.getName(); String propName = pp.getName();
synchronized (this) { synchronized (this) {
PropertyPermission existing = (PropertyPermission) perms.get(propName); PropertyPermission existing = perms.get(propName);
if (existing != null) { if (existing != null) {
int oldMask = existing.getMask(); int oldMask = existing.getMask();
...@@ -499,7 +499,7 @@ implements Serializable ...@@ -499,7 +499,7 @@ implements Serializable
perms.put(propName, new PropertyPermission(propName, actions)); perms.put(propName, new PropertyPermission(propName, actions));
} }
} else { } else {
perms.put(propName, permission); perms.put(propName, pp);
} }
} }
...@@ -533,7 +533,7 @@ implements Serializable ...@@ -533,7 +533,7 @@ implements Serializable
// short circuit if the "*" Permission was added // short circuit if the "*" Permission was added
if (all_allowed) { if (all_allowed) {
synchronized (this) { synchronized (this) {
x = (PropertyPermission) perms.get("*"); x = perms.get("*");
} }
if (x != null) { if (x != null) {
effective |= x.getMask(); effective |= x.getMask();
...@@ -550,7 +550,7 @@ implements Serializable ...@@ -550,7 +550,7 @@ implements Serializable
//System.out.println("check "+name); //System.out.println("check "+name);
synchronized (this) { synchronized (this) {
x = (PropertyPermission) perms.get(name); x = perms.get(name);
} }
if (x != null) { if (x != null) {
...@@ -570,7 +570,7 @@ implements Serializable ...@@ -570,7 +570,7 @@ implements Serializable
name = name.substring(0, last+1) + "*"; name = name.substring(0, last+1) + "*";
//System.out.println("check "+name); //System.out.println("check "+name);
synchronized (this) { synchronized (this) {
x = (PropertyPermission) perms.get(name); x = perms.get(name);
} }
if (x != null) { if (x != null) {
...@@ -592,11 +592,15 @@ implements Serializable ...@@ -592,11 +592,15 @@ implements Serializable
* *
* @return an enumeration of all the PropertyPermission objects. * @return an enumeration of all the PropertyPermission objects.
*/ */
@SuppressWarnings("unchecked")
public Enumeration<Permission> elements() { public Enumeration<Permission> elements() {
// Convert Iterator of Map values into an Enumeration // Convert Iterator of Map values into an Enumeration
synchronized (this) { synchronized (this) {
return Collections.enumeration(perms.values()); /**
* Casting to rawtype since Enumeration<PropertyPermission>
* cannot be directly cast to Enumeration<Permission>
*/
return (Enumeration)Collections.enumeration(perms.values());
} }
} }
...@@ -633,7 +637,8 @@ implements Serializable ...@@ -633,7 +637,8 @@ implements Serializable
// Don't call out.defaultWriteObject() // Don't call out.defaultWriteObject()
// Copy perms into a Hashtable // Copy perms into a Hashtable
Hashtable<String, Permission> permissions = new Hashtable<>(perms.size()*2); Hashtable<String, Permission> permissions =
new Hashtable<>(perms.size()*2);
synchronized (this) { synchronized (this) {
permissions.putAll(perms); permissions.putAll(perms);
} }
...@@ -661,8 +666,8 @@ implements Serializable ...@@ -661,8 +666,8 @@ implements Serializable
// Get permissions // Get permissions
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Hashtable<String, Permission> permissions = Hashtable<String, PropertyPermission> permissions =
(Hashtable<String, Permission>)gfields.get("permissions", null); (Hashtable<String, PropertyPermission>)gfields.get("permissions", null);
perms = new HashMap<>(permissions.size()*2); perms = new HashMap<>(permissions.size()*2);
perms.putAll(permissions); perms.putAll(permissions);
} }
......
...@@ -41,7 +41,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -41,7 +41,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
*/ */
private long elements = 0L; private long elements = 0L;
RegularEnumSet(Class<E>elementType, Enum[] universe) { RegularEnumSet(Class<E>elementType, Enum<?>[] universe) {
super(elementType, universe); super(elementType, universe);
} }
...@@ -96,6 +96,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -96,6 +96,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
return unseen != 0; return unseen != 0;
} }
@SuppressWarnings("unchecked")
public E next() { public E next() {
if (unseen == 0) if (unseen == 0)
throw new NoSuchElementException(); throw new NoSuchElementException();
...@@ -139,11 +140,11 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -139,11 +140,11 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
public boolean contains(Object e) { public boolean contains(Object e) {
if (e == null) if (e == null)
return false; return false;
Class eClass = e.getClass(); Class<?> eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType) if (eClass != elementType && eClass.getSuperclass() != elementType)
return false; return false;
return (elements & (1L << ((Enum)e).ordinal())) != 0; return (elements & (1L << ((Enum<?>)e).ordinal())) != 0;
} }
// Modification Operations // Modification Operations
...@@ -160,7 +161,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -160,7 +161,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
typeCheck(e); typeCheck(e);
long oldElements = elements; long oldElements = elements;
elements |= (1L << ((Enum)e).ordinal()); elements |= (1L << ((Enum<?>)e).ordinal());
return elements != oldElements; return elements != oldElements;
} }
...@@ -173,12 +174,12 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -173,12 +174,12 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
public boolean remove(Object e) { public boolean remove(Object e) {
if (e == null) if (e == null)
return false; return false;
Class eClass = e.getClass(); Class<?> eClass = e.getClass();
if (eClass != elementType && eClass.getSuperclass() != elementType) if (eClass != elementType && eClass.getSuperclass() != elementType)
return false; return false;
long oldElements = elements; long oldElements = elements;
elements &= ~(1L << ((Enum)e).ordinal()); elements &= ~(1L << ((Enum<?>)e).ordinal());
return elements != oldElements; return elements != oldElements;
} }
...@@ -197,7 +198,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -197,7 +198,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof RegularEnumSet)) if (!(c instanceof RegularEnumSet))
return super.containsAll(c); return super.containsAll(c);
RegularEnumSet es = (RegularEnumSet)c; RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType) if (es.elementType != elementType)
return es.isEmpty(); return es.isEmpty();
...@@ -216,7 +217,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -216,7 +217,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof RegularEnumSet)) if (!(c instanceof RegularEnumSet))
return super.addAll(c); return super.addAll(c);
RegularEnumSet es = (RegularEnumSet)c; RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType) { if (es.elementType != elementType) {
if (es.isEmpty()) if (es.isEmpty())
return false; return false;
...@@ -242,7 +243,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -242,7 +243,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(c instanceof RegularEnumSet)) if (!(c instanceof RegularEnumSet))
return super.removeAll(c); return super.removeAll(c);
RegularEnumSet es = (RegularEnumSet)c; RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType) if (es.elementType != elementType)
return false; return false;
...@@ -295,7 +296,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> { ...@@ -295,7 +296,7 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (!(o instanceof RegularEnumSet)) if (!(o instanceof RegularEnumSet))
return super.equals(o); return super.equals(o);
RegularEnumSet es = (RegularEnumSet)o; RegularEnumSet<?> es = (RegularEnumSet<?>)o;
if (es.elementType != elementType) if (es.elementType != elementType)
return elements == 0 && es.elements == 0; return elements == 0 && es.elements == 0;
return es.elements == elements; return es.elements == elements;
......
...@@ -294,7 +294,8 @@ public abstract class ResourceBundle { ...@@ -294,7 +294,8 @@ public abstract class ResourceBundle {
/** /**
* Queue for reference objects referring to class loaders or bundles. * Queue for reference objects referring to class loaders or bundles.
*/ */
private static final ReferenceQueue<Object> referenceQueue = new ReferenceQueue<>(); private static final ReferenceQueue<Object> referenceQueue =
new ReferenceQueue<>();
/** /**
* The parent bundle of this bundle. * The parent bundle of this bundle.
...@@ -417,7 +418,7 @@ public abstract class ResourceBundle { ...@@ -417,7 +418,7 @@ public abstract class ResourceBundle {
* caller's caller. * caller's caller.
*/ */
private static ClassLoader getLoader() { private static ClassLoader getLoader() {
Class[] stack = getClassContext(); Class<?>[] stack = getClassContext();
/* Magic number 2 identifies our caller's caller */ /* Magic number 2 identifies our caller's caller */
Class<?> c = stack[2]; Class<?> c = stack[2];
ClassLoader cl = (c == null) ? null : c.getClassLoader(); ClassLoader cl = (c == null) ? null : c.getClassLoader();
...@@ -434,7 +435,7 @@ public abstract class ResourceBundle { ...@@ -434,7 +435,7 @@ public abstract class ResourceBundle {
return cl; return cl;
} }
private static native Class[] getClassContext(); private static native Class<?>[] getClassContext();
/** /**
* A wrapper of ClassLoader.getSystemClassLoader(). * A wrapper of ClassLoader.getSystemClassLoader().
......
...@@ -218,20 +218,20 @@ public final class ServiceLoader<S> ...@@ -218,20 +218,20 @@ public final class ServiceLoader<S>
reload(); reload();
} }
private static void fail(Class service, String msg, Throwable cause) private static void fail(Class<?> service, String msg, Throwable cause)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
throw new ServiceConfigurationError(service.getName() + ": " + msg, throw new ServiceConfigurationError(service.getName() + ": " + msg,
cause); cause);
} }
private static void fail(Class service, String msg) private static void fail(Class<?> service, String msg)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
throw new ServiceConfigurationError(service.getName() + ": " + msg); throw new ServiceConfigurationError(service.getName() + ": " + msg);
} }
private static void fail(Class service, URL u, int line, String msg) private static void fail(Class<?> service, URL u, int line, String msg)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
fail(service, u + ":" + line + ": " + msg); fail(service, u + ":" + line + ": " + msg);
...@@ -240,7 +240,7 @@ public final class ServiceLoader<S> ...@@ -240,7 +240,7 @@ public final class ServiceLoader<S>
// Parse a single line from the given configuration file, adding the name // Parse a single line from the given configuration file, adding the name
// on the line to the names list. // on the line to the names list.
// //
private int parseLine(Class service, URL u, BufferedReader r, int lc, private int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
List<String> names) List<String> names)
throws IOException, ServiceConfigurationError throws IOException, ServiceConfigurationError
{ {
...@@ -286,7 +286,7 @@ public final class ServiceLoader<S> ...@@ -286,7 +286,7 @@ public final class ServiceLoader<S>
// If an I/O error occurs while reading from the given URL, or // If an I/O error occurs while reading from the given URL, or
// if a configuration-file format error is detected // if a configuration-file format error is detected
// //
private Iterator<String> parse(Class service, URL u) private Iterator<String> parse(Class<?> service, URL u)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
InputStream in = null; InputStream in = null;
......
...@@ -428,7 +428,7 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -428,7 +428,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
// The structure is: // The structure is:
// Map(key=id, value=SoftReference(Map(key=locale, value=displaynames))) // Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE = private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE =
new ConcurrentHashMap<String, SoftReference<Map<Locale, String[]>>>(); new ConcurrentHashMap<>();
} }
private static final String[] getDisplayNames(String id, Locale locale) { private static final String[] getDisplayNames(String id, Locale locale) {
...@@ -452,9 +452,9 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -452,9 +452,9 @@ abstract public class TimeZone implements Serializable, Cloneable {
String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale); String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
if (names != null) { if (names != null) {
Map<Locale, String[]> perLocale = new ConcurrentHashMap<Locale, String[]>(); Map<Locale, String[]> perLocale = new ConcurrentHashMap<>();
perLocale.put(locale, names); perLocale.put(locale, names);
ref = new SoftReference<Map<Locale, String[]>>(perLocale); ref = new SoftReference<>(perLocale);
displayNames.put(id, ref); displayNames.put(id, ref);
} }
return names; return names;
......
...@@ -307,7 +307,7 @@ public class TreeMap<K,V> ...@@ -307,7 +307,7 @@ public class TreeMap<K,V>
public void putAll(Map<? extends K, ? extends V> map) { public void putAll(Map<? extends K, ? extends V> map) {
int mapSize = map.size(); int mapSize = map.size();
if (size==0 && mapSize!=0 && map instanceof SortedMap) { if (size==0 && mapSize!=0 && map instanceof SortedMap) {
Comparator c = ((SortedMap)map).comparator(); Comparator<?> c = ((SortedMap<?,?>)map).comparator();
if (c == comparator || (c != null && c.equals(comparator))) { if (c == comparator || (c != null && c.equals(comparator))) {
++modCount; ++modCount;
try { try {
...@@ -340,7 +340,8 @@ public class TreeMap<K,V> ...@@ -340,7 +340,8 @@ public class TreeMap<K,V>
return getEntryUsingComparator(key); return getEntryUsingComparator(key);
if (key == null) if (key == null)
throw new NullPointerException(); throw new NullPointerException();
Comparable<? super K> k = (Comparable<? super K>) key; @SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key;
Entry<K,V> p = root; Entry<K,V> p = root;
while (p != null) { while (p != null) {
int cmp = k.compareTo(p.key); int cmp = k.compareTo(p.key);
...@@ -361,7 +362,8 @@ public class TreeMap<K,V> ...@@ -361,7 +362,8 @@ public class TreeMap<K,V>
* worthwhile here.) * worthwhile here.)
*/ */
final Entry<K,V> getEntryUsingComparator(Object key) { final Entry<K,V> getEntryUsingComparator(Object key) {
K k = (K) key; @SuppressWarnings("unchecked")
K k = (K) key;
Comparator<? super K> cpr = comparator; Comparator<? super K> cpr = comparator;
if (cpr != null) { if (cpr != null) {
Entry<K,V> p = root; Entry<K,V> p = root;
...@@ -554,7 +556,8 @@ public class TreeMap<K,V> ...@@ -554,7 +556,8 @@ public class TreeMap<K,V>
else { else {
if (key == null) if (key == null)
throw new NullPointerException(); throw new NullPointerException();
Comparable<? super K> k = (Comparable<? super K>) key; @SuppressWarnings("unchecked")
Comparable<? super K> k = (Comparable<? super K>) key;
do { do {
parent = t; parent = t;
cmp = k.compareTo(t.key); cmp = k.compareTo(t.key);
...@@ -618,9 +621,9 @@ public class TreeMap<K,V> ...@@ -618,9 +621,9 @@ public class TreeMap<K,V>
* @return a shallow copy of this map * @return a shallow copy of this map
*/ */
public Object clone() { public Object clone() {
TreeMap<K,V> clone = null; TreeMap<?,?> clone;
try { try {
clone = (TreeMap<K,V>) super.clone(); clone = (TreeMap<?,?>) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new InternalError(e); throw new InternalError(e);
} }
...@@ -803,7 +806,7 @@ public class TreeMap<K,V> ...@@ -803,7 +806,7 @@ public class TreeMap<K,V>
*/ */
public NavigableSet<K> navigableKeySet() { public NavigableSet<K> navigableKeySet() {
KeySet<K> nks = navigableKeySet; KeySet<K> nks = navigableKeySet;
return (nks != null) ? nks : (navigableKeySet = new KeySet(this)); return (nks != null) ? nks : (navigableKeySet = new KeySet<>(this));
} }
/** /**
...@@ -859,9 +862,9 @@ public class TreeMap<K,V> ...@@ -859,9 +862,9 @@ public class TreeMap<K,V>
public NavigableMap<K, V> descendingMap() { public NavigableMap<K, V> descendingMap() {
NavigableMap<K, V> km = descendingMap; NavigableMap<K, V> km = descendingMap;
return (km != null) ? km : return (km != null) ? km :
(descendingMap = new DescendingSubMap(this, (descendingMap = new DescendingSubMap<>(this,
true, null, true, true, null, true,
true, null, true)); true, null, true));
} }
/** /**
...@@ -874,9 +877,9 @@ public class TreeMap<K,V> ...@@ -874,9 +877,9 @@ public class TreeMap<K,V>
*/ */
public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive, public NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
K toKey, boolean toInclusive) { K toKey, boolean toInclusive) {
return new AscendingSubMap(this, return new AscendingSubMap<>(this,
false, fromKey, fromInclusive, false, fromKey, fromInclusive,
false, toKey, toInclusive); false, toKey, toInclusive);
} }
/** /**
...@@ -888,9 +891,9 @@ public class TreeMap<K,V> ...@@ -888,9 +891,9 @@ public class TreeMap<K,V>
* @since 1.6 * @since 1.6
*/ */
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
return new AscendingSubMap(this, return new AscendingSubMap<>(this,
true, null, true, true, null, true,
false, toKey, inclusive); false, toKey, inclusive);
} }
/** /**
...@@ -902,9 +905,9 @@ public class TreeMap<K,V> ...@@ -902,9 +905,9 @@ public class TreeMap<K,V>
* @since 1.6 * @since 1.6
*/ */
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
return new AscendingSubMap(this, return new AscendingSubMap<>(this,
false, fromKey, inclusive, false, fromKey, inclusive,
true, null, true); true, null, true);
} }
/** /**
...@@ -978,8 +981,8 @@ public class TreeMap<K,V> ...@@ -978,8 +981,8 @@ public class TreeMap<K,V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
V value = entry.getValue(); Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey()); Entry<K,V> p = getEntry(entry.getKey());
return p != null && valEquals(p.getValue(), value); return p != null && valEquals(p.getValue(), value);
} }
...@@ -987,8 +990,8 @@ public class TreeMap<K,V> ...@@ -987,8 +990,8 @@ public class TreeMap<K,V>
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
V value = entry.getValue(); Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey()); Entry<K,V> p = getEntry(entry.getKey());
if (p != null && valEquals(p.getValue(), value)) { if (p != null && valEquals(p.getValue(), value)) {
deleteEntry(p); deleteEntry(p);
...@@ -1023,21 +1026,21 @@ public class TreeMap<K,V> ...@@ -1023,21 +1026,21 @@ public class TreeMap<K,V>
} }
static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> { static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> {
private final NavigableMap<E, Object> m; private final NavigableMap<E, ?> m;
KeySet(NavigableMap<E,Object> map) { m = map; } KeySet(NavigableMap<E,?> map) { m = map; }
public Iterator<E> iterator() { public Iterator<E> iterator() {
if (m instanceof TreeMap) if (m instanceof TreeMap)
return ((TreeMap<E,Object>)m).keyIterator(); return ((TreeMap<E,?>)m).keyIterator();
else else
return (Iterator<E>)(((TreeMap.NavigableSubMap)m).keyIterator()); return ((TreeMap.NavigableSubMap<E,?>)m).keyIterator();
} }
public Iterator<E> descendingIterator() { public Iterator<E> descendingIterator() {
if (m instanceof TreeMap) if (m instanceof TreeMap)
return ((TreeMap<E,Object>)m).descendingKeyIterator(); return ((TreeMap<E,?>)m).descendingKeyIterator();
else else
return (Iterator<E>)(((TreeMap.NavigableSubMap)m).descendingKeyIterator()); return ((TreeMap.NavigableSubMap<E,?>)m).descendingKeyIterator();
} }
public int size() { return m.size(); } public int size() { return m.size(); }
...@@ -1052,11 +1055,11 @@ public class TreeMap<K,V> ...@@ -1052,11 +1055,11 @@ public class TreeMap<K,V>
public E last() { return m.lastKey(); } public E last() { return m.lastKey(); }
public Comparator<? super E> comparator() { return m.comparator(); } public Comparator<? super E> comparator() { return m.comparator(); }
public E pollFirst() { public E pollFirst() {
Map.Entry<E,Object> e = m.pollFirstEntry(); Map.Entry<E,?> e = m.pollFirstEntry();
return (e == null) ? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
public E pollLast() { public E pollLast() {
Map.Entry<E,Object> e = m.pollLastEntry(); Map.Entry<E,?> e = m.pollLastEntry();
return (e == null) ? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
public boolean remove(Object o) { public boolean remove(Object o) {
...@@ -1085,7 +1088,7 @@ public class TreeMap<K,V> ...@@ -1085,7 +1088,7 @@ public class TreeMap<K,V>
return tailSet(fromElement, true); return tailSet(fromElement, true);
} }
public NavigableSet<E> descendingSet() { public NavigableSet<E> descendingSet() {
return new KeySet(m.descendingMap()); return new KeySet<>(m.descendingMap());
} }
} }
...@@ -1184,6 +1187,7 @@ public class TreeMap<K,V> ...@@ -1184,6 +1187,7 @@ public class TreeMap<K,V>
/** /**
* Compares two keys using the correct comparison method for this TreeMap. * Compares two keys using the correct comparison method for this TreeMap.
*/ */
@SuppressWarnings("unchecked")
final int compare(Object k1, Object k2) { final int compare(Object k1, Object k2) {
return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2) return comparator==null ? ((Comparable<? super K>)k1).compareTo((K)k2)
: comparator.compare((K)k1, (K)k2); : comparator.compare((K)k1, (K)k2);
...@@ -1488,7 +1492,7 @@ public class TreeMap<K,V> ...@@ -1488,7 +1492,7 @@ public class TreeMap<K,V>
public final NavigableSet<K> navigableKeySet() { public final NavigableSet<K> navigableKeySet() {
KeySet<K> nksv = navigableKeySetView; KeySet<K> nksv = navigableKeySetView;
return (nksv != null) ? nksv : return (nksv != null) ? nksv :
(navigableKeySetView = new TreeMap.KeySet(this)); (navigableKeySetView = new TreeMap.KeySet<>(this));
} }
public final Set<K> keySet() { public final Set<K> keySet() {
...@@ -1522,7 +1526,7 @@ public class TreeMap<K,V> ...@@ -1522,7 +1526,7 @@ public class TreeMap<K,V>
if (size == -1 || sizeModCount != m.modCount) { if (size == -1 || sizeModCount != m.modCount) {
sizeModCount = m.modCount; sizeModCount = m.modCount;
size = 0; size = 0;
Iterator i = iterator(); Iterator<?> i = iterator();
while (i.hasNext()) { while (i.hasNext()) {
size++; size++;
i.next(); i.next();
...@@ -1539,11 +1543,11 @@ public class TreeMap<K,V> ...@@ -1539,11 +1543,11 @@ public class TreeMap<K,V>
public boolean contains(Object o) { public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
K key = entry.getKey(); Object key = entry.getKey();
if (!inRange(key)) if (!inRange(key))
return false; return false;
TreeMap.Entry node = m.getEntry(key); TreeMap.Entry<?,?> node = m.getEntry(key);
return node != null && return node != null &&
valEquals(node.getValue(), entry.getValue()); valEquals(node.getValue(), entry.getValue());
} }
...@@ -1551,8 +1555,8 @@ public class TreeMap<K,V> ...@@ -1551,8 +1555,8 @@ public class TreeMap<K,V>
public boolean remove(Object o) { public boolean remove(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
Map.Entry<K,V> entry = (Map.Entry<K,V>) o; Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
K key = entry.getKey(); Object key = entry.getKey();
if (!inRange(key)) if (!inRange(key))
return false; return false;
TreeMap.Entry<K,V> node = m.getEntry(key); TreeMap.Entry<K,V> node = m.getEntry(key);
...@@ -1709,34 +1713,34 @@ public class TreeMap<K,V> ...@@ -1709,34 +1713,34 @@ public class TreeMap<K,V>
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
if (!inRange(toKey, toInclusive)) if (!inRange(toKey, toInclusive))
throw new IllegalArgumentException("toKey out of range"); throw new IllegalArgumentException("toKey out of range");
return new AscendingSubMap(m, return new AscendingSubMap<>(m,
false, fromKey, fromInclusive, false, fromKey, fromInclusive,
false, toKey, toInclusive); false, toKey, toInclusive);
} }
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
if (!inRange(toKey, inclusive)) if (!inRange(toKey, inclusive))
throw new IllegalArgumentException("toKey out of range"); throw new IllegalArgumentException("toKey out of range");
return new AscendingSubMap(m, return new AscendingSubMap<>(m,
fromStart, lo, loInclusive, fromStart, lo, loInclusive,
false, toKey, inclusive); false, toKey, inclusive);
} }
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
if (!inRange(fromKey, inclusive)) if (!inRange(fromKey, inclusive))
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
return new AscendingSubMap(m, return new AscendingSubMap<>(m,
false, fromKey, inclusive, false, fromKey, inclusive,
toEnd, hi, hiInclusive); toEnd, hi, hiInclusive);
} }
public NavigableMap<K,V> descendingMap() { public NavigableMap<K,V> descendingMap() {
NavigableMap<K,V> mv = descendingMapView; NavigableMap<K,V> mv = descendingMapView;
return (mv != null) ? mv : return (mv != null) ? mv :
(descendingMapView = (descendingMapView =
new DescendingSubMap(m, new DescendingSubMap<>(m,
fromStart, lo, loInclusive, fromStart, lo, loInclusive,
toEnd, hi, hiInclusive)); toEnd, hi, hiInclusive));
} }
Iterator<K> keyIterator() { Iterator<K> keyIterator() {
...@@ -1790,34 +1794,34 @@ public class TreeMap<K,V> ...@@ -1790,34 +1794,34 @@ public class TreeMap<K,V>
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
if (!inRange(toKey, toInclusive)) if (!inRange(toKey, toInclusive))
throw new IllegalArgumentException("toKey out of range"); throw new IllegalArgumentException("toKey out of range");
return new DescendingSubMap(m, return new DescendingSubMap<>(m,
false, toKey, toInclusive, false, toKey, toInclusive,
false, fromKey, fromInclusive); false, fromKey, fromInclusive);
} }
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { public NavigableMap<K,V> headMap(K toKey, boolean inclusive) {
if (!inRange(toKey, inclusive)) if (!inRange(toKey, inclusive))
throw new IllegalArgumentException("toKey out of range"); throw new IllegalArgumentException("toKey out of range");
return new DescendingSubMap(m, return new DescendingSubMap<>(m,
false, toKey, inclusive, false, toKey, inclusive,
toEnd, hi, hiInclusive); toEnd, hi, hiInclusive);
} }
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
if (!inRange(fromKey, inclusive)) if (!inRange(fromKey, inclusive))
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
return new DescendingSubMap(m, return new DescendingSubMap<>(m,
fromStart, lo, loInclusive, fromStart, lo, loInclusive,
false, fromKey, inclusive); false, fromKey, inclusive);
} }
public NavigableMap<K,V> descendingMap() { public NavigableMap<K,V> descendingMap() {
NavigableMap<K,V> mv = descendingMapView; NavigableMap<K,V> mv = descendingMapView;
return (mv != null) ? mv : return (mv != null) ? mv :
(descendingMapView = (descendingMapView =
new AscendingSubMap(m, new AscendingSubMap<>(m,
fromStart, lo, loInclusive, fromStart, lo, loInclusive,
toEnd, hi, hiInclusive)); toEnd, hi, hiInclusive));
} }
Iterator<K> keyIterator() { Iterator<K> keyIterator() {
...@@ -1862,9 +1866,9 @@ public class TreeMap<K,V> ...@@ -1862,9 +1866,9 @@ public class TreeMap<K,V>
private boolean fromStart = false, toEnd = false; private boolean fromStart = false, toEnd = false;
private K fromKey, toKey; private K fromKey, toKey;
private Object readResolve() { private Object readResolve() {
return new AscendingSubMap(TreeMap.this, return new AscendingSubMap<>(TreeMap.this,
fromStart, fromKey, true, fromStart, fromKey, true,
toEnd, toKey, false); toEnd, toKey, false);
} }
public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); } public Set<Map.Entry<K,V>> entrySet() { throw new InternalError(); }
public K lastKey() { throw new InternalError(); } public K lastKey() { throw new InternalError(); }
...@@ -2331,12 +2335,12 @@ public class TreeMap<K,V> ...@@ -2331,12 +2335,12 @@ public class TreeMap<K,V>
* @param defaultVal if non-null, this default value is used for * @param defaultVal if non-null, this default value is used for
* each value in the map. If null, each value is read from * each value in the map. If null, each value is read from
* iterator or stream, as described above. * iterator or stream, as described above.
* @throws IOException propagated from stream reads. This cannot * @throws java.io.IOException propagated from stream reads. This cannot
* occur if str is null. * occur if str is null.
* @throws ClassNotFoundException propagated from readObject. * @throws ClassNotFoundException propagated from readObject.
* This cannot occur if str is null. * This cannot occur if str is null.
*/ */
private void buildFromSorted(int size, Iterator it, private void buildFromSorted(int size, Iterator<?> it,
java.io.ObjectInputStream str, java.io.ObjectInputStream str,
V defaultVal) V defaultVal)
throws java.io.IOException, ClassNotFoundException { throws java.io.IOException, ClassNotFoundException {
...@@ -2359,9 +2363,10 @@ public class TreeMap<K,V> ...@@ -2359,9 +2363,10 @@ public class TreeMap<K,V>
* @param redLevel the level at which nodes should be red. * @param redLevel the level at which nodes should be red.
* Must be equal to computeRedLevel for tree of this size. * Must be equal to computeRedLevel for tree of this size.
*/ */
@SuppressWarnings("unchecked")
private final Entry<K,V> buildFromSorted(int level, int lo, int hi, private final Entry<K,V> buildFromSorted(int level, int lo, int hi,
int redLevel, int redLevel,
Iterator it, Iterator<?> it,
java.io.ObjectInputStream str, java.io.ObjectInputStream str,
V defaultVal) V defaultVal)
throws java.io.IOException, ClassNotFoundException { throws java.io.IOException, ClassNotFoundException {
...@@ -2391,9 +2396,9 @@ public class TreeMap<K,V> ...@@ -2391,9 +2396,9 @@ public class TreeMap<K,V>
V value; V value;
if (it != null) { if (it != null) {
if (defaultVal==null) { if (defaultVal==null) {
Map.Entry<K,V> entry = (Map.Entry<K,V>)it.next(); Map.Entry<?,?> entry = (Map.Entry<?,?>)it.next();
key = entry.getKey(); key = (K)entry.getKey();
value = entry.getValue(); value = (V)entry.getValue();
} else { } else {
key = (K)it.next(); key = (K)it.next();
value = defaultVal; value = defaultVal;
......
...@@ -302,7 +302,7 @@ public class TreeSet<E> extends AbstractSet<E> ...@@ -302,7 +302,7 @@ public class TreeSet<E> extends AbstractSet<E>
m instanceof TreeMap) { m instanceof TreeMap) {
SortedSet<? extends E> set = (SortedSet<? extends E>) c; SortedSet<? extends E> set = (SortedSet<? extends E>) c;
TreeMap<E,Object> map = (TreeMap<E, Object>) m; TreeMap<E,Object> map = (TreeMap<E, Object>) m;
Comparator<? super E> cc = (Comparator<? super E>) set.comparator(); Comparator<?> cc = set.comparator();
Comparator<? super E> mc = map.comparator(); Comparator<? super E> mc = map.comparator();
if (cc==mc || (cc != null && cc.equals(mc))) { if (cc==mc || (cc != null && cc.equals(mc))) {
map.addAllForTreeSet(set, PRESENT); map.addAllForTreeSet(set, PRESENT);
...@@ -469,8 +469,9 @@ public class TreeSet<E> extends AbstractSet<E> ...@@ -469,8 +469,9 @@ public class TreeSet<E> extends AbstractSet<E>
* *
* @return a shallow copy of this set * @return a shallow copy of this set
*/ */
@SuppressWarnings("unchecked")
public Object clone() { public Object clone() {
TreeSet<E> clone = null; TreeSet<E> clone;
try { try {
clone = (TreeSet<E>) super.clone(); clone = (TreeSet<E>) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
...@@ -519,14 +520,11 @@ public class TreeSet<E> extends AbstractSet<E> ...@@ -519,14 +520,11 @@ public class TreeSet<E> extends AbstractSet<E>
s.defaultReadObject(); s.defaultReadObject();
// Read in Comparator // Read in Comparator
Comparator<? super E> c = (Comparator<? super E>) s.readObject(); @SuppressWarnings("unchecked")
Comparator<? super E> c = (Comparator<? super E>) s.readObject();
// Create backing TreeMap // Create backing TreeMap
TreeMap<E,Object> tm; TreeMap<E,Object> tm = new TreeMap<>(c);
if (c==null)
tm = new TreeMap<>();
else
tm = new TreeMap<>(c);
m = tm; m = tm;
// Read in size // Read in size
......
...@@ -186,7 +186,7 @@ public class WeakHashMap<K,V> ...@@ -186,7 +186,7 @@ public class WeakHashMap<K,V>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Entry<K,V>[] newTable(int n) { private Entry<K,V>[] newTable(int n) {
return (Entry<K,V>[]) new Entry[n]; return (Entry<K,V>[]) new Entry<?,?>[n];
} }
/** /**
......
...@@ -759,16 +759,19 @@ public final class Matcher implements MatchResult { ...@@ -759,16 +759,19 @@ public final class Matcher implements MatchResult {
char nextChar = replacement.charAt(cursor); char nextChar = replacement.charAt(cursor);
if (nextChar == '\\') { if (nextChar == '\\') {
cursor++; cursor++;
if (cursor == replacement.length())
throw new IllegalArgumentException(
"character to be escaped is missing");
nextChar = replacement.charAt(cursor); nextChar = replacement.charAt(cursor);
result.append(nextChar); result.append(nextChar);
cursor++; cursor++;
} else if (nextChar == '$') { } else if (nextChar == '$') {
// Skip past $ // Skip past $
cursor++; cursor++;
// A StringIndexOutOfBoundsException is thrown if // Throw IAE if this "$" is the last character in replacement
// this "$" is the last character in replacement if (cursor == replacement.length())
// string in current implementation, a IAE might be throw new IllegalArgumentException(
// more appropriate. "Illegal group reference: group index is missing");
nextChar = replacement.charAt(cursor); nextChar = replacement.charAt(cursor);
int refNum = -1; int refNum = -1;
if (nextChar == '{') { if (nextChar == '{') {
......
...@@ -371,7 +371,7 @@ public class BorderFactory ...@@ -371,7 +371,7 @@ public class BorderFactory
/** /**
* Creates a new titled border with the specified title, * Creates a new titled border with the specified title,
* the default border type (determined by the current look and feel), * the default border type (determined by the current look and feel),
* the default text position (sitting on the top line), * the default text position (determined by the current look and feel),
* the default justification (leading), and the default * the default justification (leading), and the default
* font and text color (determined by the current look and feel). * font and text color (determined by the current look and feel).
* *
...@@ -385,7 +385,7 @@ public class BorderFactory ...@@ -385,7 +385,7 @@ public class BorderFactory
/** /**
* Creates a new titled border with an empty title, * Creates a new titled border with an empty title,
* the specified border object, * the specified border object,
* the default text position (sitting on the top line), * the default text position (determined by the current look and feel),
* the default justification (leading), and the default * the default justification (leading), and the default
* font and text color (determined by the current look and feel). * font and text color (determined by the current look and feel).
* *
...@@ -400,7 +400,7 @@ public class BorderFactory ...@@ -400,7 +400,7 @@ public class BorderFactory
/** /**
* Adds a title to an existing border, * Adds a title to an existing border,
* with default positioning (sitting on the top line), * with default positioning (determined by the current look and feel),
* default justification (leading) and the default * default justification (leading) and the default
* font and text color (determined by the current look and feel). * font and text color (determined by the current look and feel).
* *
...@@ -439,7 +439,8 @@ public class BorderFactory ...@@ -439,7 +439,8 @@ public class BorderFactory
*<li><code>TitledBorder.ABOVE_BOTTOM</code> *<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line) *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code> *<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (top) *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul> *</ul>
* @return the <code>TitledBorder</code> object * @return the <code>TitledBorder</code> object
*/ */
...@@ -477,7 +478,8 @@ public class BorderFactory ...@@ -477,7 +478,8 @@ public class BorderFactory
*<li><code>TitledBorder.ABOVE_BOTTOM</code> *<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line) *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code> *<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (top) *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul> *</ul>
* @param titleFont a Font object specifying the title font * @param titleFont a Font object specifying the title font
* @return the TitledBorder object * @return the TitledBorder object
...@@ -516,7 +518,8 @@ public class BorderFactory ...@@ -516,7 +518,8 @@ public class BorderFactory
*<li><code>TitledBorder.ABOVE_BOTTOM</code> *<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line) *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code> *<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (top) *<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul> *</ul>
* @param titleFont a <code>Font</code> object specifying the title font * @param titleFont a <code>Font</code> object specifying the title font
* @param titleColor a <code>Color</code> object specifying the title color * @param titleColor a <code>Color</code> object specifying the title color
......
...@@ -1125,6 +1125,16 @@ public abstract class SunToolkit extends Toolkit ...@@ -1125,6 +1125,16 @@ public abstract class SunToolkit extends Toolkit
return InputEvent.ALT_MASK; return InputEvent.ALT_MASK;
} }
/**
* Tests whether specified key modifiers mask can be used to enter a printable
* character. This is a default implementation of this method, which reflects
* the way things work on Windows: here, pressing ctrl + alt allows user to enter
* characters from the extended character set (like euro sign or math symbols)
*/
public boolean isPrintableCharacterModifiersMask(int mods) {
return ((mods & InputEvent.ALT_MASK) == (mods & InputEvent.CTRL_MASK));
}
/** /**
* Returns a new input method window, with behavior as specified in * Returns a new input method window, with behavior as specified in
* {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}. * {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}.
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册