From d8e55dc7aebb2a6234d79f607a18cf3a683e6f4b Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Tue, 21 Nov 2023 13:43:18 -0800 Subject: [PATCH] Use JDK7 and JDK8 Code Features in Platform mappings (#1565) * Use Diamond Operator except for anonymous inner classes * Use try-with-resources * Use Multi-catch * Use constants for system properties --- .../src/com/sun/jna/platform/EnumUtils.java | 2 +- .../src/com/sun/jna/platform/FileMonitor.java | 8 +- .../src/com/sun/jna/platform/FileUtils.java | 2 +- .../sun/jna/platform/RasterRangesUtils.java | 10 +-- .../src/com/sun/jna/platform/WindowUtils.java | 10 +-- .../com/sun/jna/platform/bsd/ExtAttrUtil.java | 2 +- .../com/sun/jna/platform/dnd/DropHandler.java | 2 +- .../src/com/sun/jna/platform/linux/LibC.java | 8 +- .../com/sun/jna/platform/linux/XAttrUtil.java | 2 +- .../sun/jna/platform/mac/MacFileUtils.java | 2 +- .../com/sun/jna/platform/mac/XAttrUtil.java | 4 +- .../platform/unix/aix/SharedObjectLoader.java | 2 +- .../sun/jna/platform/win32/Advapi32Util.java | 16 ++-- .../sun/jna/platform/win32/COM/COMUtils.java | 2 +- .../jna/platform/win32/COM/WbemcliUtil.java | 14 ++-- .../platform/win32/COM/util/ComThread.java | 6 +- .../jna/platform/win32/COM/util/Factory.java | 4 +- .../win32/COM/util/ObjectFactory.java | 6 +- .../win32/COM/util/RunningObjectTable.java | 2 +- .../com/sun/jna/platform/win32/DdemlUtil.java | 40 +++++----- .../src/com/sun/jna/platform/win32/Dxva2.java | 8 +- .../sun/jna/platform/win32/Kernel32Util.java | 10 +-- .../sun/jna/platform/win32/Netapi32Util.java | 12 +-- .../com/sun/jna/platform/win32/PdhUtil.java | 8 +- .../sun/jna/platform/win32/Secur32Util.java | 2 +- .../sun/jna/platform/win32/User32Util.java | 2 +- .../jna/platform/win32/W32FileMonitor.java | 4 +- .../jna/platform/win32/Win32Exception.java | 6 +- .../src/com/sun/jna/platform/win32/WinNT.java | 2 +- .../sun/jna/platform/win32/WininetUtil.java | 4 +- .../jna/platform/RasterRangesUtilsTest.java | 7 +- .../com/sun/jna/platform/WindowUtilsTest.java | 2 +- .../jna/platform/mac/DiskArbitrationTest.java | 2 +- .../com/sun/jna/platform/mac/IOKitTest.java | 2 +- .../jna/platform/unix/aix/PerfstatTest.java | 4 +- .../platform/unix/solaris/LibKstatTest.java | 2 +- .../win32/AbstractWin32TestSupport.java | 4 +- .../sun/jna/platform/win32/Advapi32Test.java | 2 +- .../jna/platform/win32/Advapi32UtilTest.java | 4 +- .../jna/platform/win32/COM/WbemcliTest.java | 10 +-- .../sun/jna/platform/win32/Cfgmgr32Test.java | 2 +- .../sun/jna/platform/win32/GDI32UtilTest.java | 2 +- .../jna/platform/win32/Kernel32UtilTest.java | 73 ++++++++----------- .../com/sun/jna/platform/win32/NtDllTest.java | 2 +- .../com/sun/jna/platform/win32/PdhTest.java | 4 +- .../com/sun/jna/platform/win32/PsapiTest.java | 4 +- .../sun/jna/platform/win32/Shell32Test.java | 7 +- .../sun/jna/platform/win32/User32Test.java | 5 +- .../platform/win32/W32FileMonitorTest.java | 7 +- .../platform/win32/W32ServiceManagerTest.java | 2 +- .../jna/platform/win32/W32ServiceTest.java | 2 +- .../sun/jna/platform/win32/WevtapiTest.java | 4 +- .../jna/platform/win32/Win32ServiceDemo.java | 2 +- .../sun/jna/platform/win32/WinPerfTest.java | 2 +- .../sun/jna/platform/win32/Wtsapi32Test.java | 2 +- 55 files changed, 164 insertions(+), 197 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/EnumUtils.java b/contrib/platform/src/com/sun/jna/platform/EnumUtils.java index 3c9be3b91a..2f343d32f3 100644 --- a/contrib/platform/src/com/sun/jna/platform/EnumUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/EnumUtils.java @@ -82,7 +82,7 @@ public static > E fromInteger(int idx, Class clazz) public static Set setFromInteger(int flags, Class clazz) { T[] vals = clazz.getEnumConstants(); - Set result = new HashSet(); + Set result = new HashSet<>(); for (T val : vals) { diff --git a/contrib/platform/src/com/sun/jna/platform/FileMonitor.java b/contrib/platform/src/com/sun/jna/platform/FileMonitor.java index 5f7e425b28..fff283c7c7 100644 --- a/contrib/platform/src/com/sun/jna/platform/FileMonitor.java +++ b/contrib/platform/src/com/sun/jna/platform/FileMonitor.java @@ -74,8 +74,8 @@ public String toString() { } } - private final Map watched = new HashMap(); - private List listeners = new ArrayList(); + private final Map watched = new HashMap<>(); + private List listeners = new ArrayList<>(); protected abstract void watch(File file, int mask, boolean recursive) throws IOException ; protected abstract void unwatch(File file); @@ -107,13 +107,13 @@ protected void notify(FileEvent e) { } public synchronized void addFileListener(FileListener listener) { - List list = new ArrayList(listeners); + List list = new ArrayList<>(listeners); list.add(listener); listeners = list; } public synchronized void removeFileListener(FileListener x) { - List list = new ArrayList(listeners); + List list = new ArrayList<>(listeners); list.remove(x); listeners = list; } diff --git a/contrib/platform/src/com/sun/jna/platform/FileUtils.java b/contrib/platform/src/com/sun/jna/platform/FileUtils.java index b318bf7c79..2953189bdb 100644 --- a/contrib/platform/src/com/sun/jna/platform/FileUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/FileUtils.java @@ -104,7 +104,7 @@ public void moveToTrash(File... files) throws IOException { if (!trash.exists()) { throw new IOException("No trash location found (define fileutils.trash to be the path to the trash)"); } - List failed = new ArrayList(); + List failed = new ArrayList<>(); for (int i=0;i < files.length;i++) { File src = files[i]; File target = new File(trash, src.getName()); diff --git a/contrib/platform/src/com/sun/jna/platform/RasterRangesUtils.java b/contrib/platform/src/com/sun/jna/platform/RasterRangesUtils.java index 5120b48545..7f1ac32e37 100644 --- a/contrib/platform/src/com/sun/jna/platform/RasterRangesUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/RasterRangesUtils.java @@ -128,11 +128,11 @@ public static boolean outputOccupiedRanges(Raster raster, RangesOutput out) { * @return true if the output succeeded, false otherwise */ public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int w, int h, RangesOutput out) { - Set rects = new HashSet(); + Set rects = new HashSet<>(); Set prevLine = Collections.emptySet(); int scanlineBytes = binaryBits.length / h; for (int row = 0; row < h; row++) { - Set curLine = new TreeSet(COMPARATOR); + Set curLine = new TreeSet<>(COMPARATOR); int rowOffsetBytes = row * scanlineBytes; int startCol = -1; // Look at each batch of 8 columns in this row @@ -201,10 +201,10 @@ public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int * @return true if the output succeeded, false otherwise */ public static boolean outputOccupiedRanges(int[] pixels, int w, int h, int occupationMask, RangesOutput out) { - Set rects = new HashSet(); + Set rects = new HashSet<>(); Set prevLine = Collections.emptySet(); for (int row = 0; row < h; row++) { - Set curLine = new TreeSet(COMPARATOR); + Set curLine = new TreeSet<>(COMPARATOR); int idxOffset = row * w; int startCol = -1; @@ -241,7 +241,7 @@ public static boolean outputOccupiedRanges(int[] pixels, int w, int h, int occup } private static Set mergeRects(Set prev, Set current) { - Set unmerged = new HashSet(prev); + Set unmerged = new HashSet<>(prev); if (!prev.isEmpty() && !current.isEmpty()) { Rectangle[] pr = prev.toArray(new Rectangle[0]); Rectangle[] cr = current.toArray(new Rectangle[0]); diff --git a/contrib/platform/src/com/sun/jna/platform/WindowUtils.java b/contrib/platform/src/com/sun/jna/platform/WindowUtils.java index 66a3819e60..78ea1fa2dd 100644 --- a/contrib/platform/src/com/sun/jna/platform/WindowUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/WindowUtils.java @@ -1043,9 +1043,9 @@ private void setMask(final Component w, final Area area) { int mode = pi.getWindingRule() == PathIterator.WIND_NON_ZERO ? WinGDI.WINDING: WinGDI.ALTERNATE; float[] coords = new float[6]; - List points = new ArrayList(); + List points = new ArrayList<>(); int size = 0; - List sizes = new ArrayList(); + List sizes = new ArrayList<>(); while (!pi.isDone()) { int type = pi.currentSegment(coords); if (type == PathIterator.SEG_MOVETO) { @@ -1239,7 +1239,7 @@ public Dimension getIconSize(final HICON hIcon) { @Override public List getAllWindows(final boolean onlyVisibleWindows) { - final List result = new LinkedList(); + final List result = new LinkedList<>(); final WNDENUMPROC lpEnumFunc = new WNDENUMPROC() { @Override @@ -1576,7 +1576,7 @@ private static Pixmap createBitmap(final Display dpy, } x11.XSetForeground(dpy, gc, new NativeLong(0)); x11.XFillRectangle(dpy, pm, gc, 0, 0, width, height); - final List rlist = new ArrayList(); + final List rlist = new ArrayList<>(); try { RasterRangesUtils.outputOccupiedRanges(raster, new RasterRangesUtils.RangesOutput() { @Override @@ -1686,7 +1686,7 @@ private synchronized long[] getAlphaVisualIDs() { IntByReference pcount = new IntByReference(); info = x11.XGetVisualInfo(dpy, mask, template, pcount); if (info != null) { - List list = new ArrayList(); + List list = new ArrayList<>(); XVisualInfo[] infos = (XVisualInfo[])info.toArray(pcount.getValue()); for (int i = 0; i < infos.length; i++) { diff --git a/contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java index 63df36cf4d..f5628ccd32 100644 --- a/contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/bsd/ExtAttrUtil.java @@ -95,7 +95,7 @@ public static void delete(String path, String name) throws IOException { } private static List decodeStringList(ByteBuffer buffer) { - List list = new ArrayList(); + List list = new ArrayList<>(); while (buffer.hasRemaining()) { int length = buffer.get() & 0xFF; diff --git a/contrib/platform/src/com/sun/jna/platform/dnd/DropHandler.java b/contrib/platform/src/com/sun/jna/platform/dnd/DropHandler.java index 88cf7a58bb..dcd31c71df 100644 --- a/contrib/platform/src/com/sun/jna/platform/dnd/DropHandler.java +++ b/contrib/platform/src/com/sun/jna/platform/dnd/DropHandler.java @@ -388,7 +388,7 @@ public void drop(DropTargetDropEvent e) { * @return whether any of the given flavors are supported */ protected boolean isSupported(DataFlavor[] flavors) { - Set set = new HashSet(Arrays.asList(flavors)); + Set set = new HashSet<>(Arrays.asList(flavors)); set.retainAll(acceptedFlavors); return !set.isEmpty(); } diff --git a/contrib/platform/src/com/sun/jna/platform/linux/LibC.java b/contrib/platform/src/com/sun/jna/platform/linux/LibC.java index ae21e0c9c5..c688f09c92 100644 --- a/contrib/platform/src/com/sun/jna/platform/linux/LibC.java +++ b/contrib/platform/src/com/sun/jna/platform/linux/LibC.java @@ -73,7 +73,7 @@ class Sysinfo extends Structure { */ @Override protected List getFieldList() { - List fields = new ArrayList(super.getFieldList()); + List fields = new ArrayList<>(super.getFieldList()); if (PADDING_SIZE == 0) { Iterator fieldIterator = fields.iterator(); while (fieldIterator.hasNext()) { @@ -88,7 +88,7 @@ protected List getFieldList() { @Override protected List getFieldOrder() { - List fieldOrder = new ArrayList(super.getFieldOrder()); + List fieldOrder = new ArrayList<>(super.getFieldOrder()); if (PADDING_SIZE == 0) { fieldOrder.remove("_f"); } @@ -122,7 +122,7 @@ class Statvfs extends Structure { */ @Override protected List getFieldList() { - List fields = new ArrayList(super.getFieldList()); + List fields = new ArrayList<>(super.getFieldList()); if (NativeLong.SIZE > 4) { Iterator fieldIterator = fields.iterator(); while (fieldIterator.hasNext()) { @@ -137,7 +137,7 @@ protected List getFieldList() { @Override protected List getFieldOrder() { - List fieldOrder = new ArrayList(super.getFieldOrder()); + List fieldOrder = new ArrayList<>(super.getFieldOrder()); if (NativeLong.SIZE > 4) { fieldOrder.remove("_f_unused"); } diff --git a/contrib/platform/src/com/sun/jna/platform/linux/XAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/linux/XAttrUtil.java index 3176a4942f..1a03852042 100644 --- a/contrib/platform/src/com/sun/jna/platform/linux/XAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/linux/XAttrUtil.java @@ -657,7 +657,7 @@ public static void fRemoveXAttr(int fd, String name) throws IOException { private static Collection splitBufferToStrings(byte[] valueMem, String encoding) throws IOException { final Charset charset = Charset.forName(encoding); - final Set attributesList = new LinkedHashSet(1); + final Set attributesList = new LinkedHashSet<>(1); int offset = 0; for(int i = 0; i < valueMem.length; i++) { // each entry is terminated by a single \0 byte diff --git a/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java b/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java index 29cfe7d531..5bc700ebeb 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java @@ -69,7 +69,7 @@ class FSRef extends Structure { @Override public void moveToTrash(File... files) throws IOException { - List failed = new ArrayList(); + List failed = new ArrayList<>(); for (File src: files) { FileManager.FSRef fsref = new FileManager.FSRef(); int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(), diff --git a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java index a8ba9d2fdf..22bf4abffe 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/XAttrUtil.java @@ -41,7 +41,7 @@ public static List listXAttr(String path) { return null; if (bufferLength == 0) - return new ArrayList(0); + return new ArrayList<>(0); Memory valueBuffer = new Memory(bufferLength); long valueLength = XAttr.INSTANCE.listxattr(path, valueBuffer, bufferLength, 0); @@ -97,7 +97,7 @@ protected static String decodeString(ByteBuffer bb) { } protected static List decodeStringSequence(ByteBuffer bb) { - List names = new ArrayList(); + List names = new ArrayList<>(); bb.mark(); // first key starts from here while (bb.hasRemaining()) { diff --git a/contrib/platform/src/com/sun/jna/platform/unix/aix/SharedObjectLoader.java b/contrib/platform/src/com/sun/jna/platform/unix/aix/SharedObjectLoader.java index 8bdac4ba4f..4734f1422b 100644 --- a/contrib/platform/src/com/sun/jna/platform/unix/aix/SharedObjectLoader.java +++ b/contrib/platform/src/com/sun/jna/platform/unix/aix/SharedObjectLoader.java @@ -55,7 +55,7 @@ private static Map getOptions() { int RTLD_MEMBER = 0x40000; // allows "lib.a(obj.o)" syntax int RTLD_GLOBAL = 0x10000; int RTLD_LAZY = 0x4; - Map options = new HashMap(); + Map options = new HashMap<>(); options.put(Library.OPTION_OPEN_FLAGS, RTLD_MEMBER | RTLD_GLOBAL | RTLD_LAZY); return Collections.unmodifiableMap(options); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java index 26dd22d256..a81032fc94 100755 --- a/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java @@ -455,7 +455,7 @@ public static Account[] getTokenGroups(HANDLE hToken) { tokenInformationLength.getValue(), tokenInformationLength)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } - ArrayList userGroups = new ArrayList(); + ArrayList userGroups = new ArrayList<>(); // make array of names for (SID_AND_ATTRIBUTES sidAndAttribute : groups.getGroups()) { Account group; @@ -975,7 +975,7 @@ public static String[] registryGetStringArray(HKEY hKey, String value) { * @return An array of strings corresponding to the strings in the buffer. */ static String[] regMultiSzBufferToStringArray(Memory data) { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); int offset = 0; while (offset < data.size()) { String s; @@ -1995,7 +1995,7 @@ public static String[] registryGetKeys(HKEY hKey) { if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } - ArrayList keys = new ArrayList(lpcSubKeys.getValue()); + ArrayList keys = new ArrayList<>(lpcSubKeys.getValue()); char[] name = new char[lpcMaxSubKeyLen.getValue() + 1]; for (int i = 0; i < lpcSubKeys.getValue(); i++) { IntByReference lpcchValueName = new IntByReference( @@ -2129,7 +2129,7 @@ public static TreeMap registryGetValues(HKEY hKey) { if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } - TreeMap keyValues = new TreeMap(); + TreeMap keyValues = new TreeMap<>(); char[] name = new char[lpcMaxValueNameLen.getValue() + 1]; // Allocate enough memory to hold largest value and two // terminating WCHARs -- the memory is zeroed so after @@ -2200,7 +2200,7 @@ public static TreeMap registryGetValues(HKEY hKey) { break; } case WinNT.REG_MULTI_SZ: { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); int offset = 0; while (offset < byteData.size()) { String s; @@ -2529,7 +2529,7 @@ public EventLogRecord(Pointer pevlr) { } // strings if (_record.NumStrings.intValue() > 0) { - ArrayList strings = new ArrayList(); + ArrayList strings = new ArrayList<>(); int count = _record.NumStrings.intValue(); long offset = _record.StringOffset.intValue(); while (count > 0) { @@ -2700,8 +2700,8 @@ public static ACE_HEADER[] getFileSecurity(String fileName, ACE_HEADER[] aceStructures = dacl.getACEs(); if (compact) { - List result = new ArrayList(); - Map aceMap = new HashMap(); + List result = new ArrayList<>(); + Map aceMap = new HashMap<>(); for (ACE_HEADER aceStructure : aceStructures) { if (aceStructure instanceof ACCESS_ACEStructure) { ACCESS_ACEStructure accessACEStructure = (ACCESS_ACEStructure) aceStructure; diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java index c689958e78..bf2bb315f4 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java @@ -222,7 +222,7 @@ public static ArrayList getAllCOMInfoOnSystem() { HKEYByReference phkResult = new HKEYByReference(); HKEYByReference phkResult2 = new HKEYByReference(); String subKey; - ArrayList comInfos = new ArrayList(); + ArrayList comInfos = new ArrayList<>(); try { // open root key diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java index 828361b7d3..a3e08684fb 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/WbemcliUtil.java @@ -284,12 +284,12 @@ private static > IEnumWbemClassObject selectProperties(IWbemSe */ private static > WmiResult enumerateProperties(IEnumWbemClassObject enumerator, Class propertyEnum, int timeout) throws TimeoutException { - WmiResult values = INSTANCE.new WmiResult(propertyEnum); + WmiResult values = INSTANCE.new WmiResult<>(propertyEnum); // Step 7: ------------------------------------------------- // Get the data from the query in step 6 ------------------- Pointer[] pclsObj = new Pointer[1]; IntByReference uReturn = new IntByReference(0); - Map wstrMap = new HashMap(); + Map wstrMap = new HashMap<>(); HRESULT hres = null; for (T property : propertyEnum.getEnumConstants()) { wstrMap.put(property, new WString(property.name())); @@ -381,11 +381,11 @@ public class WmiResult> { * The enum associated with this map */ public WmiResult(Class propertyEnum) { - propertyMap = new EnumMap>(propertyEnum); - vtTypeMap = new EnumMap(propertyEnum); - cimTypeMap = new EnumMap(propertyEnum); + propertyMap = new EnumMap<>(propertyEnum); + vtTypeMap = new EnumMap<>(propertyEnum); + cimTypeMap = new EnumMap<>(propertyEnum); for (T prop : propertyEnum.getEnumConstants()) { - propertyMap.put(prop, new ArrayList()); + propertyMap.put(prop, new ArrayList<>()); vtTypeMap.put(prop, Variant.VT_NULL); cimTypeMap.put(prop, Wbemcli.CIM_EMPTY); } @@ -486,7 +486,7 @@ public static boolean hasNamespace(String namespace) { ns = namespace.substring(5); } // Test - WmiQuery namespaceQuery = new WmiQuery("ROOT", "__NAMESPACE", NamespaceProperty.class); + WmiQuery namespaceQuery = new WmiQuery<>("ROOT", "__NAMESPACE", NamespaceProperty.class); WmiResult namespaces = namespaceQuery.execute(); for (int i = 0; i < namespaces.getResultCount(); i++) { if (ns.equalsIgnoreCase((String) namespaces.getValue(NamespaceProperty.NAME, i))) { diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java index acc650ac9f..b840ef7e69 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ComThread.java @@ -37,7 +37,7 @@ import com.sun.jna.platform.win32.COM.COMUtils; public class ComThread { - private static ThreadLocal isCOMThread = new ThreadLocal(); + private static ThreadLocal isCOMThread = new ThreadLocal<>(); ExecutorService executor; Runnable firstTask; @@ -116,9 +116,7 @@ public void run() { executor.shutdown(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { + } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { executor.shutdownNow(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java index 06e7fe49e4..41d94fd48e 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/Factory.java @@ -170,9 +170,7 @@ public IRunningObjectTable getRunningObjectTable() { private T runInComThread(Callable callable) { try { return comThread.execute(callable); - } catch (TimeoutException ex) { - throw new RuntimeException(ex); - } catch (InterruptedException ex) { + } catch (TimeoutException | InterruptedException ex) { throw new RuntimeException(ex); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ObjectFactory.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ObjectFactory.java index 7409b499dc..938002f31f 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ObjectFactory.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ObjectFactory.java @@ -180,11 +180,11 @@ IDispatchCallback createDispatchCallback(Class comEventCallbackInterface, ICo // environment and can't be used anymore. registeredObjects is used // to dispose interfaces even if garbadge collection has not yet collected // the proxy objects. - private final List> registeredObjects = new LinkedList>(); + private final List> registeredObjects = new LinkedList<>(); public void register(ProxyObject proxyObject) { synchronized (this.registeredObjects) { - this.registeredObjects.add(new WeakReference(proxyObject)); + this.registeredObjects.add(new WeakReference<>(proxyObject)); } } @@ -203,7 +203,7 @@ public void unregister(ProxyObject proxyObject) { public void disposeAll() { synchronized (this.registeredObjects) { - List> s = new ArrayList>(this.registeredObjects); + List> s = new ArrayList<>(this.registeredObjects); for (WeakReference weakRef : s) { ProxyObject po = weakRef.get(); if (po != null) { diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java index 99db4083c3..767f72ff89 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/RunningObjectTable.java @@ -60,7 +60,7 @@ public Iterable enumRunning() { public List getActiveObjectsByInterface(Class comInterface) { assert COMUtils.comIsInitialized() : "COM not initialized"; - List result = new ArrayList(); + List result = new ArrayList<>(); for (IDispatch obj : this.enumRunning()) { try { diff --git a/contrib/platform/src/com/sun/jna/platform/win32/DdemlUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/DdemlUtil.java index 6af8abb841..9fc499e1cc 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/DdemlUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/DdemlUtil.java @@ -1640,7 +1640,7 @@ public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HS return new WinDef.PVOID(); }; - private final List advstartHandler = new CopyOnWriteArrayList(); + private final List advstartHandler = new CopyOnWriteArrayList<>(); public void registerAdvstartHandler(AdvstartHandler handler) { advstartHandler.add(handler); @@ -1660,7 +1660,7 @@ private boolean onAdvstart(int transactionType, int dataFormat, Ddeml.HCONV hcon return oneHandlerTrue; } - private final List advstopHandler = new CopyOnWriteArrayList(); + private final List advstopHandler = new CopyOnWriteArrayList<>(); public void registerAdvstopHandler(AdvstopHandler handler) { advstopHandler.add(handler); @@ -1676,7 +1676,7 @@ private void onAdvstop(int transactionType, int dataFormat, Ddeml.HCONV hconv, D } } - private final List connectHandler = new CopyOnWriteArrayList(); + private final List connectHandler = new CopyOnWriteArrayList<>(); public void registerConnectHandler(ConnectHandler handler) { connectHandler.add(handler); @@ -1696,7 +1696,7 @@ private boolean onConnect(int transactionType, Ddeml.HSZ topic, Ddeml.HSZ servic return oneHandlerTrue; } - private final List advReqHandler = new CopyOnWriteArrayList(); + private final List advReqHandler = new CopyOnWriteArrayList<>(); public void registerAdvReqHandler(AdvreqHandler handler) { advReqHandler.add(handler); @@ -1716,7 +1716,7 @@ private Ddeml.HDDEDATA onAdvreq(int transactionType, int dataFormat, Ddeml.HCONV return null; } - private final List requestHandler = new CopyOnWriteArrayList(); + private final List requestHandler = new CopyOnWriteArrayList<>(); public void registerRequestHandler(RequestHandler handler) { requestHandler.add(handler); @@ -1736,7 +1736,7 @@ private Ddeml.HDDEDATA onRequest(int transactionType, int dataFormat, Ddeml.HCON return null; } - private final List wildconnectHandler = new CopyOnWriteArrayList(); + private final List wildconnectHandler = new CopyOnWriteArrayList<>(); public void registerWildconnectHandler(WildconnectHandler handler) { wildconnectHandler.add(handler); @@ -1747,7 +1747,7 @@ public void unregisterWildconnectHandler(WildconnectHandler handler) { } private Ddeml.HSZPAIR[] onWildconnect(int transactionType, HSZ topic, HSZ service, CONVCONTEXT convcontext, boolean sameInstance) { - List hszpairs = new ArrayList(1); + List hszpairs = new ArrayList<>(1); for(WildconnectHandler handler: wildconnectHandler) { hszpairs.addAll(handler.onWildconnect(transactionType, topic, service, convcontext, sameInstance)); } @@ -1755,7 +1755,7 @@ private Ddeml.HSZPAIR[] onWildconnect(int transactionType, HSZ topic, HSZ servic } - private final List advdataHandler = new CopyOnWriteArrayList(); + private final List advdataHandler = new CopyOnWriteArrayList<>(); public void registerAdvdataHandler(AdvdataHandler handler) { advdataHandler.add(handler); @@ -1775,7 +1775,7 @@ private int onAdvdata(int transactionType, int dataFormat, HCONV hconv, HSZ topi return Ddeml.DDE_FNOTPROCESSED; } - private final List executeHandler = new CopyOnWriteArrayList(); + private final List executeHandler = new CopyOnWriteArrayList<>(); public void registerExecuteHandler(ExecuteHandler handler) { executeHandler.add(handler); @@ -1795,7 +1795,7 @@ private int onExecute(int transactionType, HCONV hconv, HSZ topic, HDDEDATA comm return Ddeml.DDE_FNOTPROCESSED; } - private final List pokeHandler = new CopyOnWriteArrayList(); + private final List pokeHandler = new CopyOnWriteArrayList<>(); public void registerPokeHandler(PokeHandler handler) { pokeHandler.add(handler); @@ -1815,7 +1815,7 @@ private int onPoke(int transactionType, int dataFormat, HCONV hconv, HSZ topic, return Ddeml.DDE_FNOTPROCESSED; } - private final List connectConfirmHandler = new CopyOnWriteArrayList(); + private final List connectConfirmHandler = new CopyOnWriteArrayList<>(); public void registerConnectConfirmHandler(ConnectConfirmHandler handler) { connectConfirmHandler.add(handler); @@ -1831,7 +1831,7 @@ private void onConnectConfirm(int transactionType, HCONV hconv, HSZ topic, HSZ s } } - private final List disconnectHandler = new CopyOnWriteArrayList(); + private final List disconnectHandler = new CopyOnWriteArrayList<>(); public void registerDisconnectHandler(DisconnectHandler handler) { disconnectHandler.add(handler); @@ -1847,7 +1847,7 @@ private void onDisconnect(int transactionType, Ddeml.HCONV hconv, boolean sameIn } } - private final List errorHandler = new CopyOnWriteArrayList(); + private final List errorHandler = new CopyOnWriteArrayList<>(); public void registerErrorHandler(ErrorHandler handler) { errorHandler.add(handler); @@ -1863,7 +1863,7 @@ private void onError(int transactionType, Ddeml.HCONV hconv, int errorCode) { } } - private final List registerHandler = new CopyOnWriteArrayList(); + private final List registerHandler = new CopyOnWriteArrayList<>(); public void registerRegisterHandler(RegisterHandler handler) { registerHandler.add(handler); @@ -1879,7 +1879,7 @@ private void onRegister(int transactionType, Ddeml.HSZ baseServiceName, Ddeml.HS } } - private final List xactCompleteHandler = new CopyOnWriteArrayList(); + private final List xactCompleteHandler = new CopyOnWriteArrayList<>(); public void registerXactCompleteHandler(XactCompleteHandler handler) { xactCompleteHandler.add(handler); @@ -1895,7 +1895,7 @@ private void onXactComplete(int transactionType, int dataFormat, HCONV hConv, HS } } - private final List unregisterHandler = new CopyOnWriteArrayList(); + private final List unregisterHandler = new CopyOnWriteArrayList<>(); public void registerUnregisterHandler(UnregisterHandler handler) { unregisterHandler.add(handler); @@ -1911,7 +1911,7 @@ private void onUnregister(int transactionType, HSZ baseServiceName, HSZ instance } } - private final List monitorHandler = new CopyOnWriteArrayList(); + private final List monitorHandler = new CopyOnWriteArrayList<>(); public void registerMonitorHandler(MonitorHandler handler) { monitorHandler.add(handler); @@ -1936,15 +1936,13 @@ public static class DdemlException extends RuntimeException { private static final Map ERROR_CODE_MAP; static { - Map errorCodeMapBuilder = new HashMap(); + Map errorCodeMapBuilder = new HashMap<>(); for (Field f : Ddeml.class.getFields()) { String name = f.getName(); if (name.startsWith("DMLERR_") && (!name.equals("DMLERR_FIRST")) && (!name.equals("DMLERR_LAST"))) { try { errorCodeMapBuilder.put(f.getInt(null), name); - } catch (IllegalArgumentException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { + } catch (IllegalArgumentException | IllegalAccessException ex) { throw new RuntimeException(ex); } } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java b/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java index 229d0e9606..c5593e6acc 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Dxva2.java @@ -54,10 +54,10 @@ public interface Dxva2 extends StdCallLibrary, PhysicalMonitorEnumerationAPI, Hi { put(Library.OPTION_TYPE_MAPPER, new DefaultTypeMapper() { { - addTypeConverter(MC_POSITION_TYPE.class, new EnumConverter(MC_POSITION_TYPE.class)); - addTypeConverter(MC_SIZE_TYPE.class, new EnumConverter(MC_SIZE_TYPE.class)); - addTypeConverter(MC_GAIN_TYPE.class, new EnumConverter(MC_GAIN_TYPE.class)); - addTypeConverter(MC_DRIVE_TYPE.class, new EnumConverter(MC_DRIVE_TYPE.class)); + addTypeConverter(MC_POSITION_TYPE.class, new EnumConverter<>(MC_POSITION_TYPE.class)); + addTypeConverter(MC_SIZE_TYPE.class, new EnumConverter<>(MC_SIZE_TYPE.class)); + addTypeConverter(MC_GAIN_TYPE.class, new EnumConverter<>(MC_GAIN_TYPE.class)); + addTypeConverter(MC_DRIVE_TYPE.class, new EnumConverter<>(MC_DRIVE_TYPE.class)); } }); } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java index 27ecd88eb1..1d9bea6723 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java @@ -471,7 +471,7 @@ public static Map getEnvironmentVariables(Pointer lpszEnvironment return null; } - Map vars=new TreeMap(); + Map vars=new TreeMap<>(); boolean asWideChars=isWideCharEnvironmentStringBlock(lpszEnvironmentBlock, offset); long stepFactor=asWideChars ? 2L : 1L; for (long curOffset=offset; ; ) { @@ -755,7 +755,7 @@ public static final SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] getLogicalProcesso } } // Array elements have variable size; iterate to populate array - List procInfoList = new ArrayList(); + List procInfoList = new ArrayList<>(); int offset = 0; while (offset < bufferSize.getValue().intValue()) { SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX information = SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX @@ -1068,8 +1068,8 @@ public static Map> getResourceNames(String path) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } - final List types = new ArrayList(); - final Map> result = new LinkedHashMap>(); + final List types = new ArrayList<>(); + final Map> result = new LinkedHashMap<>(); WinBase.EnumResTypeProc ertp = new WinBase.EnumResTypeProc() { @@ -1180,7 +1180,7 @@ public static List getModules(int processID) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } - List modules = new ArrayList(); + List modules = new ArrayList<>(); modules.add(first); Tlhelp32.MODULEENTRY32W next = new Tlhelp32.MODULEENTRY32W(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java index db8222e769..8a6488ba4d 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java @@ -212,7 +212,7 @@ public static LocalGroup[] getLocalGroups(String serverName) { throw new Win32Exception(rc); } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (entriesRead.getValue() > 0) { LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue()); @@ -261,7 +261,7 @@ public static Group[] getGlobalGroups(String serverName) { throw new Win32Exception(rc); } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (entriesRead.getValue() > 0) { LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue()); @@ -311,7 +311,7 @@ public static User[] getUsers(String serverName) { throw new Win32Exception(rc); } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (entriesRead.getValue() > 0) { LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue()); @@ -370,7 +370,7 @@ public static Group[] getUserLocalGroups(String userName, String serverName) { if (rc != LMErr.NERR_Success) { throw new Win32Exception(rc); } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (entriesread.getValue() > 0) { LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue()); LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue()); @@ -420,7 +420,7 @@ public static Group[] getUserGroups(String userName, String serverName) { throw new Win32Exception(rc); } - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList<>(); if (entriesread.getValue() > 0) { GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue()); @@ -637,7 +637,7 @@ public static DomainTrust[] getDomainTrusts(String serverName) { throw new Win32Exception(rc); } try { - ArrayList trusts = new ArrayList(domainTrustCount.getValue()); + ArrayList trusts = new ArrayList<>(domainTrustCount.getValue()); if(domainTrustCount.getValue() > 0) { DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue()); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java index ebfa8e7f60..51a479e7ef 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java @@ -159,8 +159,8 @@ public static int PdhLookupPerfIndexByEnglishName(String szNameBuffer) { */ public static PdhEnumObjectItems PdhEnumObjectItems(String szDataSource, String szMachineName, String szObjectName, int dwDetailLevel) { - List counters = new ArrayList(); - List instances = new ArrayList(); + List counters = new ArrayList<>(); + List instances = new ArrayList<>(); // Call once to get counter and instance string lengths // If zero on input and the object exists, the function returns PDH_MORE_DATA @@ -285,9 +285,9 @@ public List getInstances() { private List copyAndEmptyListForNullList (List inputList) { if(inputList == null) { - return new ArrayList(); + return new ArrayList<>(); } else { - return new ArrayList(inputList); + return new ArrayList<>(inputList); } } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Secur32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Secur32Util.java index bd90b8669f..cbced1a8a3 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Secur32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Secur32Util.java @@ -97,7 +97,7 @@ public static SecurityPackage[] getSecurityPackages() { throw new Win32Exception(rc); } SecPkgInfo[] packagesInfo = pPackageInfo.toArray(pcPackages.getValue()); - ArrayList packages = new ArrayList(pcPackages.getValue()); + ArrayList packages = new ArrayList<>(pcPackages.getValue()); for (SecPkgInfo packageInfo : packagesInfo) { SecurityPackage securityPackage = new SecurityPackage(); securityPackage.name = packageInfo.Name.toString(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java index b21d02fdee..19d834caf7 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/User32Util.java @@ -213,7 +213,7 @@ public Future runAsync(Callable command) { Logger.getLogger(MessageLoopThread.class.getName()).log(Level.SEVERE, null, ex); } } - FutureTask futureTask = new FutureTask(command); + FutureTask futureTask = new FutureTask<>(command); workQueue.add(futureTask); User32.INSTANCE.PostThreadMessage(nativeThreadId, WinUser.WM_USER, null, null); return futureTask; diff --git a/contrib/platform/src/com/sun/jna/platform/win32/W32FileMonitor.java b/contrib/platform/src/com/sun/jna/platform/win32/W32FileMonitor.java index 0a57eb051a..dc98fa78c2 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/W32FileMonitor.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/W32FileMonitor.java @@ -62,8 +62,8 @@ public FileInfo(File f, HANDLE h, int mask, boolean recurse) { } private Thread watcher; private HANDLE port; - private final Map fileMap = new HashMap(); - private final Map handleMap = new HashMap(); + private final Map fileMap = new HashMap<>(); + private final Map handleMap = new HashMap<>(); private boolean disposing = false; private void handleChanges(FileInfo finfo) throws IOException { diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java b/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java index a3f75edecd..00e36b7302 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java @@ -92,11 +92,7 @@ void addSuppressedReflected(Throwable exception) { } try { addSuppressedMethod.invoke(this, exception); - } catch (IllegalAccessException ex) { - throw new RuntimeException("Failed to call addSuppressedMethod", ex); - } catch (IllegalArgumentException ex) { - throw new RuntimeException("Failed to call addSuppressedMethod", ex); - } catch (InvocationTargetException ex) { + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException("Failed to call addSuppressedMethod", ex); } } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java index 96a1c503d3..29e539f503 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java @@ -3208,7 +3208,7 @@ public void read() { */ @Override protected List getFieldList() { - List fields = new ArrayList(super.getFieldList()); + List fields = new ArrayList<>(super.getFieldList()); Iterator fieldIterator = fields.iterator(); while (fieldIterator.hasNext()) { Field field = fieldIterator.next(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java index 449a53ea70..dc8145d152 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java @@ -47,14 +47,14 @@ public class WininetUtil { * cookie and history entries) */ public static Map getCache() { - List items = new ArrayList(); + List items = new ArrayList<>(); HANDLE cacheHandle = null; Win32Exception we = null; int lastError = 0; // return - Map cacheItems = new LinkedHashMap(); + Map cacheItems = new LinkedHashMap<>(); try { IntByReference size = new IntByReference(); diff --git a/contrib/platform/test/com/sun/jna/platform/RasterRangesUtilsTest.java b/contrib/platform/test/com/sun/jna/platform/RasterRangesUtilsTest.java index fe68bb335e..ba8aee36ec 100644 --- a/contrib/platform/test/com/sun/jna/platform/RasterRangesUtilsTest.java +++ b/contrib/platform/test/com/sun/jna/platform/RasterRangesUtilsTest.java @@ -31,15 +31,16 @@ import java.util.HashSet; import java.util.Set; -import junit.framework.TestCase; - import com.sun.jna.platform.RasterRangesUtils.RangesOutput; +import junit.framework.TestCase; + public class RasterRangesUtilsTest extends TestCase { - Set rects = new HashSet(); + Set rects = new HashSet<>(); RangesOutput out = new RangesOutput() { + @Override public boolean outputRange(int x, int y, int w, int h) { rects.add(new Rectangle(x, y, w, h)); return true; diff --git a/contrib/platform/test/com/sun/jna/platform/WindowUtilsTest.java b/contrib/platform/test/com/sun/jna/platform/WindowUtilsTest.java index a8062d78e7..3f3761e65d 100644 --- a/contrib/platform/test/com/sun/jna/platform/WindowUtilsTest.java +++ b/contrib/platform/test/com/sun/jna/platform/WindowUtilsTest.java @@ -429,7 +429,7 @@ public void run() { WeakReference ref = null; for (int i = 0; i < owned.length; i++) { if (owned[i].getClass().getName().indexOf("Heavy") != -1) { - ref = new WeakReference(owned[i]); + ref = new WeakReference<>(owned[i]); break; } } diff --git a/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java b/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java index 60c106ed79..8bdbfec7bd 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java @@ -75,7 +75,7 @@ public void testDiskCreate() { assertNotNull(session); // Get IOMedia objects representing whole drives and save the BSD Name - List bsdNames = new ArrayList(); + List bsdNames = new ArrayList<>(); PointerByReference iterPtr = new PointerByReference(); CFMutableDictionaryRef dict = IOKit.INSTANCE.IOServiceMatching("IOMedia"); diff --git a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java index 6ab22aa844..8810d452e3 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java @@ -144,7 +144,7 @@ public void testMatching() { public void testIteratorParentChild() { int masterPort = IOKitUtil.getMasterPort(); - Set uniqueEntryIdSet = new HashSet(); + Set uniqueEntryIdSet = new HashSet<>(); // Iterate over USB Controllers. All devices are children of one of // these controllers in the "IOService" plane // On M1 the IOUSBController service doesn't exist so we navigate from root of diff --git a/contrib/platform/test/com/sun/jna/platform/unix/aix/PerfstatTest.java b/contrib/platform/test/com/sun/jna/platform/unix/aix/PerfstatTest.java index 6c5ee9c70f..75fef4a8b2 100644 --- a/contrib/platform/test/com/sun/jna/platform/unix/aix/PerfstatTest.java +++ b/contrib/platform/test/com/sun/jna/platform/unix/aix/PerfstatTest.java @@ -147,7 +147,7 @@ public void testPerfstatProcesses() { assertTrue("Error fetching processes", 0 < ret); // due to race condition ret may return fewer processes than asked for assertTrue("Fetched too many processes", ret <= procCount); - Set pidSet = new HashSet(); + Set pidSet = new HashSet<>(); for (int i = 0; i < ret; i++) { assertTrue("Must have nonempty process name", 0 < Native.toString(proct[i].proc_name).length()); assertFalse("Pid must be unique", pidSet.contains(proct[i].pid)); @@ -160,7 +160,7 @@ public void testPerfstatProcesses() { public void testPerfstatProtocols() { if (Platform.isAIX()) { // Valid protocol names are union field names - Set protocolNames = new HashSet(); + Set protocolNames = new HashSet<>(); for (Field f : perfstat_protocol_t.AnonymousUnionPayload.class.getDeclaredFields()) { protocolNames.add(f.getName()); } diff --git a/contrib/platform/test/com/sun/jna/platform/unix/solaris/LibKstatTest.java b/contrib/platform/test/com/sun/jna/platform/unix/solaris/LibKstatTest.java index 2bb644c575..23d0f5fa1d 100644 --- a/contrib/platform/test/com/sun/jna/platform/unix/solaris/LibKstatTest.java +++ b/contrib/platform/test/com/sun/jna/platform/unix/solaris/LibKstatTest.java @@ -254,7 +254,7 @@ private static Kstat kstatLookup(KstatCtl kc, String module, int instance, Strin * empty list otherwise */ private static List kstatLookupAll(KstatCtl kc, String module, int instance, String name) { - List kstats = new ArrayList(); + List kstats = new ArrayList<>(); int ret = LibKstat.INSTANCE.kstat_chain_update(kc); if (ret < 0) { fail(String.format("Failed to update kstat chain")); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/AbstractWin32TestSupport.java b/contrib/platform/test/com/sun/jna/platform/win32/AbstractWin32TestSupport.java index 159b52494a..acba0ade38 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/AbstractWin32TestSupport.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/AbstractWin32TestSupport.java @@ -62,8 +62,8 @@ public static final void assertNoDuplicateMethodsNames(Class ifc) { */ public static final Set detectDuplicateMethods(Class ifc) { Method[] methods = ifc.getMethods(); - Set nameSet = new HashSet(methods.length); - Set dupSet = new HashSet(); + Set nameSet = new HashSet<>(methods.length); + Set dupSet = new HashSet<>(); for (Method m : methods) { String name = m.getName(); if (!nameSet.add(name)) { diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java index bbddb75e68..18446ccb56 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32Test.java @@ -2146,7 +2146,7 @@ private File createTempFile() throws Exception { file.createNewFile(); FileWriter fileWriter = new FileWriter(file); for (int i = 0; i < 1000; i++) { - fileWriter.write("Sample text " + i + System.getProperty("line.separator")); + fileWriter.write("Sample text " + i + System.lineSeparator()); } fileWriter.close(); return file; diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java index 39c19eacce..1c8a739aeb 100755 --- a/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Advapi32UtilTest.java @@ -788,7 +788,7 @@ public void testGetEnvironmentBlock() { + "\0"; // Order is important to kept checking result simple - Map mockEnvironment = new TreeMap(); + Map mockEnvironment = new TreeMap<>(); mockEnvironment.put("KEY", "value"); mockEnvironment.put("KEY_EMPTY", ""); mockEnvironment.put("KEY_NUMBER", "2"); @@ -934,7 +934,7 @@ private File createTempFile() throws Exception{ file.createNewFile(); FileWriter fileWriter = new FileWriter(file); for (int i = 0; i < 1000; i++) { - fileWriter.write("Sample text " + i + System.getProperty("line.separator")); + fileWriter.write("Sample text " + i + System.lineSeparator()); } fileWriter.close(); return file; diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/WbemcliTest.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/WbemcliTest.java index c6d8e4e56f..3a65c706dc 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/WbemcliTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/WbemcliTest.java @@ -96,7 +96,7 @@ public void unInitCom() { @Test public void testWmiExceptions() { - WmiQuery processQuery = new WmiQuery("Win32_Process", ProcessProperty.class); + WmiQuery processQuery = new WmiQuery<>("Win32_Process", ProcessProperty.class); try { // This query should take more than 0 ms processQuery.execute(0); @@ -142,7 +142,7 @@ public void testNamespace() { @Test public void testWmiProcesses() { - WmiQuery processQuery = new WmiQuery("Win32_Process", ProcessProperty.class); + WmiQuery processQuery = new WmiQuery<>("Win32_Process", ProcessProperty.class); WmiResult processes = processQuery.execute(); // There has to be at least one process (this one!) @@ -199,7 +199,7 @@ public void testShowProperties() { for(IWbemClassObject iwco: results) { resultCount++; - Set names = new HashSet(Arrays.asList(iwco.GetNames(null, 0, null))); + Set names = new HashSet<>(Arrays.asList(iwco.GetNames(null, 0, null))); assertTrue(names.contains("CommandLine")); assertTrue(names.contains("ProcessId")); assertTrue(names.contains("WorkingSetSize")); @@ -276,7 +276,7 @@ public void testShowProperties() { @Test public void testWmiOperatingSystem() { - WmiQuery operatingSystemQuery = new WmiQuery("Win32_OperatingSystem", + WmiQuery operatingSystemQuery = new WmiQuery<>("Win32_OperatingSystem", OperatingSystemProperty.class); WmiResult os = operatingSystemQuery.execute(); @@ -306,7 +306,7 @@ enum Win32_DiskDrive_Values { @Test public void testUnsupportedValues() { - WmiQuery serialNumberQuery = new WmiQuery("Win32_DiskDrive", Win32_DiskDrive_Values.class); + WmiQuery serialNumberQuery = new WmiQuery<>("Win32_DiskDrive", Win32_DiskDrive_Values.class); WmiResult result = serialNumberQuery.execute(); assertTrue(result.getResultCount() > 0); for (int i = 0; i < result.getResultCount(); i++) { diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Cfgmgr32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Cfgmgr32Test.java index ed98d2f12b..987aa8507c 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Cfgmgr32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Cfgmgr32Test.java @@ -124,7 +124,7 @@ public void testDeviceProperties() { int node = outputNode.getValue(); // Navigate the device tree using BFS - Queue deviceQueue = new ArrayDeque(); + Queue deviceQueue = new ArrayDeque<>(); IntByReference child = new IntByReference(); IntByReference sibling = new IntByReference(); // Initialize queue with root node diff --git a/contrib/platform/test/com/sun/jna/platform/win32/GDI32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/GDI32UtilTest.java index 2e191e9a38..7b81d425ee 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/GDI32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/GDI32UtilTest.java @@ -50,7 +50,7 @@ public void testGetScreenshot() { // by checking for 20 distinct colors. // BufferedImages normally start life as one uniform color // so if that's not the case then some data was indeed copied over as a result of the getScreenshot() function. - List distinctPixels = new ArrayList(); + List distinctPixels = new ArrayList<>(); for (int x = 0; x < image.getWidth(); x++) { for (int y = 0; y < image.getHeight(); y++) { int pixel = image.getRGB(x, y); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java index ca57fce349..d045751ced 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java @@ -211,10 +211,10 @@ public void testGetEnvironmentVariable() { public final void testGetPrivateProfileInt() throws IOException { final File tmp = File.createTempFile("testGetPrivateProfileInt", "ini"); tmp.deleteOnExit(); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - writer.println("[Section]"); - writer.println("existingKey = 123"); - writer.close(); + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { + writer.println("[Section]"); + writer.println("existingKey = 123"); + } assertEquals(123, Kernel32Util.getPrivateProfileInt("Section", "existingKey", 456, tmp.getCanonicalPath())); assertEquals(456, Kernel32Util.getPrivateProfileInt("Section", "missingKey", 456, tmp.getCanonicalPath())); @@ -223,10 +223,10 @@ public final void testGetPrivateProfileInt() throws IOException { public final void testGetPrivateProfileString() throws IOException { final File tmp = File.createTempFile("testGetPrivateProfileString", "ini"); tmp.deleteOnExit(); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - writer.println("[Section]"); - writer.println("existingKey = ABC"); - writer.close(); + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { + writer.println("[Section]"); + writer.println("existingKey = ABC"); + } assertEquals("ABC", Kernel32Util.getPrivateProfileString("Section", "existingKey", "DEF", tmp.getCanonicalPath())); assertEquals("DEF", Kernel32Util.getPrivateProfileString("Section", "missingKey", "DEF", tmp.getCanonicalPath())); @@ -235,44 +235,38 @@ public final void testGetPrivateProfileString() throws IOException { public final void testWritePrivateProfileString() throws IOException { final File tmp = File.createTempFile("testWritePrivateProfileString", "ini"); tmp.deleteOnExit(); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - writer.println("[Section]"); - writer.println("existingKey = ABC"); - writer.println("removedKey = JKL"); - writer.close(); + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { + writer.println("[Section]"); + writer.println("existingKey = ABC"); + writer.println("removedKey = JKL"); + } Kernel32Util.writePrivateProfileString("Section", "existingKey", "DEF", tmp.getCanonicalPath()); Kernel32Util.writePrivateProfileString("Section", "addedKey", "GHI", tmp.getCanonicalPath()); Kernel32Util.writePrivateProfileString("Section", "removedKey", null, tmp.getCanonicalPath()); - final BufferedReader reader = new BufferedReader(new FileReader(tmp)); - assertEquals(reader.readLine(), "[Section]"); - assertTrue(reader.readLine().matches("existingKey\\s*=\\s*DEF")); - assertTrue(reader.readLine().matches("addedKey\\s*=\\s*GHI")); - assertEquals(reader.readLine(), null); - reader.close(); + try (BufferedReader reader = new BufferedReader(new FileReader(tmp))) { + assertEquals(reader.readLine(), "[Section]"); + assertTrue(reader.readLine().matches("existingKey\\s*=\\s*DEF")); + assertTrue(reader.readLine().matches("addedKey\\s*=\\s*GHI")); + assertEquals(reader.readLine(), null); + } } public final void testGetPrivateProfileSection() throws IOException { final File tmp = File.createTempFile("testGetPrivateProfileSection", ".ini"); tmp.deleteOnExit(); - final PrintWriter writer0 = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - try { + try (PrintWriter writer0 = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { writer0.println("[X]"); - } finally { - writer0.close(); } final String[] lines0 = Kernel32Util.getPrivateProfileSection("X", tmp.getCanonicalPath()); assertEquals(lines0.length, 0); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp, true))); - try { + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp, true)))) { writer.println("A=1"); writer.println("foo=bar"); - } finally { - writer.close(); } final String[] lines = Kernel32Util.getPrivateProfileSection("X", tmp.getCanonicalPath()); @@ -285,16 +279,13 @@ public final void testGetPrivateProfileSectionNames() throws IOException { final File tmp = File.createTempFile("testGetPrivateProfileSectionNames", "ini"); tmp.deleteOnExit(); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - try { + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { writer.println("[S1]"); writer.println("A=1"); writer.println("B=X"); writer.println("[S2]"); writer.println("C=2"); writer.println("D=Y"); - } finally { - writer.close(); } String[] sectionNames = Kernel32Util.getPrivateProfileSectionNames(tmp.getCanonicalPath()); @@ -307,30 +298,24 @@ public final void testWritePrivateProfileSection() throws IOException { final File tmp = File.createTempFile("testWritePrivateProfileSecion", "ini"); tmp.deleteOnExit(); - final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp))); - try { + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)))) { writer.println("[S1]"); writer.println("A=1"); writer.println("B=X"); writer.println("[S2]"); writer.println("C=2"); writer.println("foo=bar"); - } finally { - writer.close(); } Kernel32Util.writePrivateProfileSection("S1", new String[] { "A=3", "E=Z" }, tmp.getCanonicalPath()); - final BufferedReader reader = new BufferedReader(new FileReader(tmp)); - try { + try (BufferedReader reader = new BufferedReader(new FileReader(tmp))) { assertEquals(reader.readLine(), "[S1]"); assertEquals(reader.readLine(), "A=3"); assertEquals(reader.readLine(), "E=Z"); assertEquals(reader.readLine(), "[S2]"); assertEquals(reader.readLine(), "C=2"); assertEquals(reader.readLine(), "foo=bar"); - } finally { - reader.close(); } } @@ -413,11 +398,11 @@ public void testGetLogicalProcessorInformation() { public void testGetLogicalProcessorInformationEx() { SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] procInfo = Kernel32Util .getLogicalProcessorInformationEx(WinNT.LOGICAL_PROCESSOR_RELATIONSHIP.RelationAll); - List groups = new ArrayList(); - List packages = new ArrayList(); - List numaNodes = new ArrayList(); - List caches = new ArrayList(); - List cores = new ArrayList(); + List groups = new ArrayList<>(); + List packages = new ArrayList<>(); + List numaNodes = new ArrayList<>(); + List caches = new ArrayList<>(); + List cores = new ArrayList<>(); for (int i = 0; i < procInfo.length; i++) { // Build list from relationship diff --git a/contrib/platform/test/com/sun/jna/platform/win32/NtDllTest.java b/contrib/platform/test/com/sun/jna/platform/win32/NtDllTest.java index 4ce1b1947a..3088999d67 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/NtDllTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/NtDllTest.java @@ -130,7 +130,7 @@ private File createTempFile() throws Exception { file.createNewFile(); FileWriter fileWriter = new FileWriter(file); for (int i = 0; i < 1000; i++) { - fileWriter.write("Sample text " + i + System.getProperty("line.separator")); + fileWriter.write("Sample text " + i + System.lineSeparator()); } fileWriter.close(); return file; diff --git a/contrib/platform/test/com/sun/jna/platform/win32/PdhTest.java b/contrib/platform/test/com/sun/jna/platform/win32/PdhTest.java index 45edbc2de5..18cac051ad 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/PdhTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/PdhTest.java @@ -87,7 +87,7 @@ public void testQueryOneCounter() { @Test public void testQueryMultipleCounters() { - Collection names = new LinkedList(); + Collection names = new LinkedList<>(); PDH_COUNTER_PATH_ELEMENTS elems = new PDH_COUNTER_PATH_ELEMENTS(); elems.szObjectName = "Processor"; elems.szInstanceName = "_Total"; @@ -102,7 +102,7 @@ public void testQueryMultipleCounters() { HANDLE hQuery = ref.getValue(); try { - Map handlesMap = new HashMap(names.size()); + Map handlesMap = new HashMap<>(names.size()); try { for (String counterName : names) { ref.setValue(null); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java b/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java index 4b7613d3b6..1014c0df09 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java @@ -133,7 +133,7 @@ public void testEnumProcessModules() { me = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, false, Kernel32.INSTANCE.GetCurrentProcessId()); assertTrue("Handle to my process should not be null", me != null); - List list = new LinkedList(); + List list = new LinkedList<>(); HMODULE[] lphModule = new HMODULE[100 * 4]; IntByReference lpcbNeeded = new IntByReference(); @@ -175,7 +175,7 @@ public void testGetModuleInformation() { me = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, false, Kernel32.INSTANCE.GetCurrentProcessId()); assertTrue("Handle to my process should not be null", me != null); - List list = new LinkedList(); + List list = new LinkedList<>(); HMODULE[] lphModule = new HMODULE[100 * 4]; IntByReference lpcbNeeded = new IntByReference(); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java index a46c22ae66..570b8fbd1d 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Shell32Test.java @@ -228,14 +228,11 @@ public void testShellExecuteEx() { */ private void fillTempFile(File file) throws IOException { file.createNewFile(); - FileWriter fileWriter = new FileWriter(file); - try { + try (FileWriter fileWriter = new FileWriter(file)) { for (int i = 0; i < 10; i++) { fileWriter.write("Sample line of text"); - fileWriter.write(System.getProperty("line.separator")); + fileWriter.write(System.lineSeparator()); } - } finally { - fileWriter.close(); } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java index c3c8321a22..7cb6708ee2 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/User32Test.java @@ -150,10 +150,7 @@ public void testRegisterHotKey() { robot.keyRelease(vk); msg = waitForMessage(500); assertNull(msg); - } catch (AWTException e) { - e.printStackTrace(); - fail(); - } catch (InterruptedException e) { + } catch (AWTException | InterruptedException e) { e.printStackTrace(); fail(); } finally { diff --git a/contrib/platform/test/com/sun/jna/platform/win32/W32FileMonitorTest.java b/contrib/platform/test/com/sun/jna/platform/win32/W32FileMonitorTest.java index 16cbaca68b..392f9ef1ce 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/W32FileMonitorTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/W32FileMonitorTest.java @@ -47,7 +47,7 @@ public static void main(String[] args) { private File tmpdir; protected void setUp() throws Exception { - events = new HashMap(); + events = new HashMap<>(); final FileListener listener = new FileListener() { public void fileChanged(FileEvent e) { events.put(Integer.valueOf(e.getType()), e); @@ -115,11 +115,8 @@ public void testNotifyOnFileModification() throws Exception { monitor.addWatch(tmpdir); File file = File.createTempFile(getName(), ".tmp", tmpdir); file.deleteOnExit(); - final FileOutputStream os = new FileOutputStream(file); - try { + try (FileOutputStream os = new FileOutputStream(file)) { os.write(getName().getBytes()); - } finally { - os.close(); } final FileEvent event = waitForFileEvent(FileMonitor.FILE_MODIFIED); assertNotNull("No file modified event: " + events, event); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceManagerTest.java b/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceManagerTest.java index d9a0f18699..77de21b4b4 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceManagerTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceManagerTest.java @@ -65,7 +65,7 @@ public void testEnumServices() { W32ServiceManager manager = new W32ServiceManager(); // It is expected, that these services are present - List expectedServices = new ArrayList(4); + List expectedServices = new ArrayList<>(4); expectedServices.add("Schedule"); if (VersionHelpers.IsWindows8OrGreater()) { expectedServices.add("SystemEventsBroker"); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceTest.java b/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceTest.java index 3ccaed3d9c..006e9e1a62 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/W32ServiceTest.java @@ -99,7 +99,7 @@ public void testSetAndGetFailureActions() { W32Service service = _serviceManager.openService(svcId, Winsvc.SC_MANAGER_ALL_ACCESS); SERVICE_FAILURE_ACTIONS prevActions = service.getFailureActions(); - List actions = new LinkedList(); + List actions = new LinkedList<>(); SC_ACTION action = new SC_ACTION(); action.type = Winsvc.SC_ACTION_RESTART; diff --git a/contrib/platform/test/com/sun/jna/platform/win32/WevtapiTest.java b/contrib/platform/test/com/sun/jna/platform/win32/WevtapiTest.java index 6b334a911b..cfe096b862 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/WevtapiTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/WevtapiTest.java @@ -255,7 +255,7 @@ public void testEvtOpenLog() throws Exception { public void testEvtOpenChannelEnum() throws Exception { EVT_HANDLE channelHandle = null; - List channelList = new ArrayList(); + List channelList = new ArrayList<>(); try { channelHandle = Wevtapi.INSTANCE.EvtOpenChannelEnum(null, 0); if (channelHandle == null) { @@ -337,7 +337,7 @@ public void testEvtOpenPublisherEnum() throws Exception { Winevt.EVT_RPC_LOGIN_FLAGS.EvtRpcLoginAuthDefault); EVT_HANDLE session = null; EVT_HANDLE publisherEnumHandle = null; - List publisherList = new ArrayList(); + List publisherList = new ArrayList<>(); try { session = Wevtapi.INSTANCE.EvtOpenSession(Winevt.EVT_LOGIN_CLASS.EvtRpcLogin, login, 0, 0); if (session == null) { diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Win32ServiceDemo.java b/contrib/platform/test/com/sun/jna/platform/win32/Win32ServiceDemo.java index a77fa51e4b..b46f13ea35 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Win32ServiceDemo.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Win32ServiceDemo.java @@ -72,7 +72,7 @@ public static void main(String[] args) { public static final String serviceName = "Win32ServiceDemo"; public static final String description = "TestService Description"; - private static final Set SUFFIXES = new HashSet(); + private static final Set SUFFIXES = new HashSet<>(); static { SUFFIXES.add("jna.jar"); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/WinPerfTest.java b/contrib/platform/test/com/sun/jna/platform/win32/WinPerfTest.java index c5913239b8..47a6d920c9 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/WinPerfTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/WinPerfTest.java @@ -122,7 +122,7 @@ public void testPerfDataBLock() { // PERF_INSTANCE_DEFINITION test long perfInstanceOffset = perfObjectOffset + perfObject.DefinitionLength; - Set pidSet = new HashSet(); + Set pidSet = new HashSet<>(); for (int inst = 0; inst < perfObject.NumInstances; inst++) { PERF_INSTANCE_DEFINITION perfInstance = new PERF_INSTANCE_DEFINITION( pPerfData.share(perfInstanceOffset)); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Wtsapi32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Wtsapi32Test.java index ce465b9419..a603b3780c 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Wtsapi32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Wtsapi32Test.java @@ -81,7 +81,7 @@ public void testWTSEnumerateProcessesEx() { WTS_PROCESS_INFO_EX processInfoRef = new WTS_PROCESS_INFO_EX(pProcessInfo); WTS_PROCESS_INFO_EX[] processInfo = (WTS_PROCESS_INFO_EX[]) processInfoRef.toArray(pCount.getValue()); - Set pidSet = new HashSet(); + Set pidSet = new HashSet<>(); for (WTS_PROCESS_INFO_EX procInfo : processInfo) { // PIDs should be unique if (procInfo.ProcessId != 0) {