From 69047a01913637f5933c10d18e06fffecd565493 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?=
Date: Thu, 14 Sep 2017 00:42:47 +0200
Subject: [PATCH] Cleanup deprecated elements
---
CHANGES.md | 38 ++++++++++-
.../jna/platform/win32/COM/TypeLibUtil.java | 2 +-
.../sun/jna/platform/win32/Kernel32Util.java | 12 +---
.../com/sun/jna/platform/win32/OleAuto.java | 4 --
.../com/sun/jna/platform/win32/User32.java | 17 -----
.../com/sun/jna/platform/win32/Variant.java | 22 +------
.../com/sun/jna/platform/win32/WinBase.java | 12 ----
src/com/sun/jna/Native.java | 30 +--------
src/com/sun/jna/Pointer.java | 65 -------------------
src/com/sun/jna/Structure.java | 11 ----
src/com/sun/jna/overview.html | 11 ++--
test/com/sun/jna/NativeTest.java | 9 ---
12 files changed, 46 insertions(+), 187 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index eeb5234265..4388f98001 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -16,12 +16,44 @@ Bug Fixes
Breaking Changes
----------------
-* `Pointer#SIZE` is removed. Its use is replaced by `Native#POINTER_SIZE`
+
+* `com.sun.jna.Pointer#SIZE` is removed. Its use is replaced by `com.sun.jna.Native#POINTER_SIZE`
to prevent a class loading deadlock, when JNA is initialized from multiple threads
-* `SecBufferDesc` was incompatibly changed to match the correct native semantics.
- SecBufferDesc describing more than one buffer were broken. For most usecases
+* `com.sun.jna.Pointer#getString(long offset, boolean wide)` is removed. It was replaced by
+ `com.sun.jna.Pointer#getString(long offset)` or
+ `com.sun.jna.Pointer#getWideString(long offset)`
+* `com.sun.jna.Pointer#getStringArray(long offset, boolean wide)` is removed. It was replaced by
+ `com.sun.jna.Pointer#getStringArray(long offset)` or
+ `com.sun.jna.Pointer#getWideStringArray(long offset)`
+* `com.sun.jna.Pointer#setString(long offset, String value, boolean wide)` is removed. It was replaced by
+ `com.sun.jna.Pointer#setString(long offset, String value)` or
+ `com.sun.jna.Pointer#setWideString(long offset, String value)`
+* `com.sun.jna.Structure#setFieldOrder` is removed. It was replaced by
+ `com.sun.jna.Structure#getFieldOrder` and threw an `java.lang.Error` on call.
+* `com.sun.jna.Native#parseVersion` was removed without replacement
+* `com.sun.jna.Native#setPreserveLastError` and `com.sun.jna.Native#getPreserveLastError`
+ were removed without replacement. They were turned into NOOPs in the past.
+* `com.sun.jna.Native#getDirectByteBuffer` was replaced by `com.sun.jna.Pointer#getByteBuffer`
+* `com.sun.jna.platform.win32.Sspi.SecBufferDesc` was incompatibly changed to
+ match the correct native semantics. SecBufferDesc describing more than one
+ buffer were broken. For most usecases
`com.sun.jna.platform.win32.SspiUtil.ManagedSecBufferDesc` is the best
alternative.
+* `com.sun.jna.platform.win32.WinBase.FILETIME#toLong()` was replaced by
+ `com.sun.jna.platform.win32.WinBase.FILETIME#toTime()`
+* `com.sun.jna.platform.win32.Variant#COM_DAYS_ADJUSTMENT` was removed
+* `com.sun.jna.platform.win32.Variant#MICRO_SECONDS_PER_DAY` was removed
+* `com.sun.jna.platform.win32.Variant.VARIANT#toJavaDate` was removed
+* `com.sun.jna.platform.win32.Variant.VARIANT#fromJavaDate` was removed
+* `com.sun.jna.platform.win32.User32#MonitorFromPoint(Point pt, int dwFlags)`
+ was replaced by
+ `com.sun.jna.platform.win32.User32#MonitorFromPoint(Point.ByValue pt, int dwFlags)`
+* `com.sun.jna.platform.win32.OleAuto.LoadTypeLib(WString, PointerByReference)`
+ was replaced by
+ `com.sun.jna.platform.win32.OleAuto.LoadTypeLib(String, PointerByReference)`
+* `com.sun.jna.platform.win32.Kernel32Util.formatMessageFromHR(HRESULT)`
+ was replaced by
+ `com.sun.jna.platform.win32.Kernel32Util.formatMessage(HRESULT)`
Release 4.5.0
=============
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLibUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLibUtil.java
index 4146c0e544..35fc2746e1 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLibUtil.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLibUtil.java
@@ -106,7 +106,7 @@ public TypeLibUtil(String clsidStr, int wVerMajor, int wVerMinor) {
public TypeLibUtil(String file) {
// load typelib
PointerByReference pTypeLib = new PointerByReference();
- HRESULT hr = OleAuto.INSTANCE.LoadTypeLib(new WString(file), pTypeLib);
+ HRESULT hr = OleAuto.INSTANCE.LoadTypeLib(file, pTypeLib);
COMUtils.checkRC(hr);
// init type lib 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 3e7a11f4c3..9a7892b884 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java
@@ -216,16 +216,6 @@ public static String formatMessage(HRESULT code) {
return formatMessage(code.intValue());
}
- /**
- * @deprecated use {@link #formatMessage(WinNT.HRESULT)} instead.
- * @param code error code
- * @return formatted message
- */
- @Deprecated
- public static String formatMessageFromHR(HRESULT code) {
- return formatMessage(code.intValue());
- }
-
/**
* Format a system message from an error code.
*
@@ -234,7 +224,7 @@ public static String formatMessageFromHR(HRESULT code) {
* @return Formatted message.
*/
public static String formatMessageFromLastErrorCode(int code) {
- return formatMessageFromHR(W32Errors.HRESULT_FROM_WIN32(code));
+ return formatMessage(W32Errors.HRESULT_FROM_WIN32(code));
}
/**
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java b/contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java
index 80a31b89d3..87054d1b9b 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java
@@ -29,7 +29,6 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
-import com.sun.jna.WString;
import com.sun.jna.platform.win32.Guid.GUID;
import com.sun.jna.platform.win32.OaIdl.DISPID;
import com.sun.jna.platform.win32.OaIdl.SAFEARRAY;
@@ -883,9 +882,6 @@ protected List getFieldOrder() {
* @return status
*/
HRESULT LoadTypeLib(String szFile, PointerByReference pptlib);
- /** @deprecated use the String version */
- @Deprecated
- HRESULT LoadTypeLib(WString szFile, PointerByReference pptlib);
/**
* Converts a system time to a variant representation.
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/User32.java b/contrib/platform/src/com/sun/jna/platform/win32/User32.java
index 3a15a81ffb..4416356c4d 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/User32.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/User32.java
@@ -1717,23 +1717,6 @@ HWND CreateWindowEx(int dwExStyle, String lpClassName,
*
*/
int RegisterWindowMessage(String string);
-
- /**
- * Retrieves a handle to the display monitor that contains a specified point.
- * @param pt A POINT structure that specifies the point of interest in virtual-screen
- * coordinates.
- * @param dwFlags Determines the function's return value if the window does not intersect
- * any display monitor. This parameter can be one of the following values.
- * - MONITOR_DEFAULTTONEAREST
- * - MONITOR_DEFAULTTONULL
- * - MONITOR_DEFAULTTOPRIMARY
- * @return If the point is contained by a display monitor, the return value is an HMONITOR
- * handle to that display monitor. If the point is not contained by a display monitor,
- * the return value depends on the value of dwFlags.
- * @deprecated Use {@link #MonitorFromPoint(com.sun.jna.platform.win32.WinDef.POINT.ByValue, int)}
- */
- @Deprecated
- HMONITOR MonitorFromPoint(POINT pt, int dwFlags);
/**
* Retrieves a handle to the display monitor that contains a specified point.
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Variant.java b/contrib/platform/src/com/sun/jna/platform/win32/Variant.java
index 4596382148..baf43ce737 100644
--- a/contrib/platform/src/com/sun/jna/platform/win32/Variant.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/Variant.java
@@ -22,7 +22,6 @@
*/
package com.sun.jna.platform.win32;
-import com.sun.jna.IntegerType;
import java.util.Date;
import java.util.List;
@@ -126,14 +125,6 @@ public interface Variant {
public static VARIANT_BOOL VARIANT_TRUE = new VARIANT_BOOL(0xFFFF);
public static VARIANT_BOOL VARIANT_FALSE = new VARIANT_BOOL(0x0000);
- @Deprecated
- public final static long COM_DAYS_ADJUSTMENT = 25569L; // ((1969 - 1899) *
- // 365) +1 + Leap
- // years = Days
- @Deprecated
- public final static long MICRO_SECONDS_PER_DAY = 86400000L; // 24L * 60L *
- // 60L * 1000L;
-
public static class VARIANT extends Union {
public static class ByReference extends VARIANT implements
@@ -294,8 +285,7 @@ public VARIANT(IDispatch value) {
public VARIANT(Date value) {
this();
- DATE date = this.fromJavaDate(value);
- this.setValue(VT_DATE, date);
+ this.setValue(VT_DATE, new DATE(value));
}
public VARIANT(SAFEARRAY array) {
@@ -610,16 +600,6 @@ public Date dateValue() {
}
}
- @Deprecated
- protected Date toJavaDate(DATE varDate) {
- return varDate.getAsJavaDate();
- }
-
- @Deprecated
- protected DATE fromJavaDate(Date javaDate) {
- return new DATE(javaDate);
- }
-
public static class _VARIANT extends Structure {
public static final List FIELDS = createFieldsOrder("vt",
"wReserved1", "wReserved2", "wReserved3", "__variant");
diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
index 32e111d83b..da3a69435f 100755
--- a/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
+++ b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
@@ -936,18 +936,6 @@ public long toTime() {
return toDate().getTime();
}
- /**
- * Converts this filetime into a number of milliseconds which have
- * passed since January 1, 1970 (UTC).
- * @return This filetime as a number of milliseconds which have passed
- * since January 1, 1970 (UTC)
- * @deprecated Replaced by {@link #toTime()}
- */
- @Deprecated
- public long toLong() {
- return toDate().getTime();
- }
-
/**
* Converts the two 32-bit unsigned integer parts of this filetime
* into a 64-bit unsigned integer representing the number of
diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java
index 86e342e86d..fbed55b717 100644
--- a/src/com/sun/jna/Native.java
+++ b/src/com/sun/jna/Native.java
@@ -147,11 +147,6 @@ public void uncaughtException(Callback c, Throwable e) {
static final int MAX_ALIGNMENT;
static final int MAX_PADDING;
-
- @Deprecated
- public static float parseVersion(String v) {
- return Float.parseFloat(v.substring(0, v.lastIndexOf(".")));
- }
/**
* Version string must have the structure ..
@@ -299,21 +294,6 @@ private Native() { }
*/
public static synchronized native boolean isProtected();
- /** This method is obsolete. The last error value is always preserved.
- * @see #getLastError()
- * @deprecated Last error is always preserved and available via {@link #getLastError()}
- */
- @Deprecated
- public static void setPreserveLastError(boolean enable) { }
-
- /** Indicates whether the system last error result is preserved
- * after every invocation. Always returns true
- * @see #getLastError()
- * @deprecated Last error is always preserved and available via {@link #getLastError()}
- */
- @Deprecated
- public static boolean getPreserveLastError() { return true; }
-
/** Utility method to get the native window ID for a Java {@link Window}
* as a long
value.
* This method is primarily for X11-based systems, which use an opaque
@@ -2189,16 +2169,10 @@ static String getString(Pointer pointer, long offset, String encoding) {
public static native void free(long ptr);
/**
- * Get a direct ByteBuffer mapped to the memory pointed to by the pointer.
- * This method calls through to the JNA NewDirectByteBuffer method.
- *
- * @param addr base address of the JNA-originated memory
- * @param length Length of ByteBuffer
- * @return a direct ByteBuffer that accesses the memory being pointed to
- * @deprecated Use {@link Pointer#getByteBuffer(long, long)} (since 4.3.0)
+ * @deprecated retained to keep native signature
*/
@Deprecated
- public static native ByteBuffer getDirectByteBuffer(long addr, long length);
+ private static native ByteBuffer getDirectByteBuffer(long addr, long length);
private static final ThreadLocal nativeThreadTerminationFlag =
new ThreadLocal() {
diff --git a/src/com/sun/jna/Pointer.java b/src/com/sun/jna/Pointer.java
index 815f2566b1..16ad03fd80 100644
--- a/src/com/sun/jna/Pointer.java
+++ b/src/com/sun/jna/Pointer.java
@@ -653,23 +653,6 @@ public ByteBuffer getByteBuffer(long offset, long length) {
return Native.getDirectByteBuffer(this, this.peer, offset, length).order(ByteOrder.nativeOrder());
}
- /**
- * Copy native memory to a Java String. If wide
is true,
- * access the memory as an array of wchar_t
, otherwise
- * as an array of char
, using the default platform encoding.
- *
- * @param offset byte offset from pointer to obtain the native string
-v * @param wide whether to convert from a wide or standard C string
- * @return the String
value being pointed to
- *
- * @deprecated use {@link #getString(long,String)} or {@link
- * #getWideString(long)} instead.
- */
- @Deprecated
- public String getString(long offset, boolean wide) {
- return wide ? getWideString(offset) : getString(offset);
- }
-
/** Read a wide (const wchar_t *
) string from memory. */
public String getWideString(long offset) {
return Native.getWideString(this, this.peer, offset);
@@ -811,19 +794,6 @@ public String[] getStringArray(long offset, int length) {
return getStringArray(offset, length, Native.getDefaultStringEncoding());
}
- /** Returns an array of String
based on a native array
- * of char*
or wchar_t*
based on the
- * wide
parameter. The array length is determined by a
- * NULL-valued terminating element.
- *
- * @deprecated use {@link #getStringArray(long,String)} or {@link
- * #getWideStringArray(long)} instead.
- */
- @Deprecated
- public String[] getStringArray(long offset, boolean wide) {
- return getStringArray(offset, -1, wide);
- }
-
public String[] getWideStringArray(long offset) {
return getWideStringArray(offset, -1);
}
@@ -832,18 +802,6 @@ public String[] getWideStringArray(long offset, int length) {
return getStringArray(offset, length, NativeString.WIDE_STRING);
}
- /** Returns an array of String
based on a native array
- * of char*
or wchar_t*
based on the
- * wide
parameter, using the given array length.
- *
- * @deprecated use {@link #getStringArray(long,int,String)} or {@link
- * #getWideStringArray(long,int)} instead.
- */
- @Deprecated
- public String[] getStringArray(long offset, int length, boolean wide) {
- return getStringArray(offset, length, wide ? NativeString.WIDE_STRING : Native.getDefaultStringEncoding());
- }
-
/** Returns an array of String
based on a native array
* of char*
or wchar_t*
based on the
* wide
parameter, using the given array length.
@@ -1145,29 +1103,6 @@ public void setPointer(long offset, Pointer value) {
Native.setPointer(this, this.peer, offset, value != null ? value.peer : 0);
}
- /**
- * Copy string value
to the location being pointed to.
- *
- * @param offset byte offset from pointer at which characters in
- * value
must be set
- * @param value java.lang.String
value to set
- * @param wide whether to write the native string as an array of
- * wchar_t
. If false, writes as a NUL-terminated array of
- * char
using the encoding indicated by {@link
- * Native#getDefaultStringEncoding()}.
- *
- * @deprecated use {@link #setWideString(long,String)} instead.
- */
- @Deprecated
- public void setString(long offset, String value, boolean wide) {
- if (wide) {
- setWideString(offset, value);
- }
- else {
- setString(offset, value);
- }
- }
-
/**
* Copy string value
to the location being pointed to as a
* wide string (wchar_t*
).
diff --git a/src/com/sun/jna/Structure.java b/src/com/sun/jna/Structure.java
index be71f4e0c9..5e4b7f7dfb 100644
--- a/src/com/sun/jna/Structure.java
+++ b/src/com/sun/jna/Structure.java
@@ -890,17 +890,6 @@ protected void writeField(StructField structField) {
*/
protected abstract List getFieldOrder();
- /**
- * Force a compile-time error on the old method of field definition
- * @param fields ordered array of field names
- * @deprecated Use the required method getFieldOrder() instead to
- * indicate the order of fields in this structure.
- */
- @Deprecated
- protected final void setFieldOrder(String[] fields) {
- throw new Error("This method is obsolete, use getFieldOrder() instead");
- }
-
/** Sort the structure fields according to the given array of names.
* @param fields list of fields to be sorted
* @param names list of names representing the desired sort order
diff --git a/src/com/sun/jna/overview.html b/src/com/sun/jna/overview.html
index 103c2c501a..4a3f55654b 100644
--- a/src/com/sun/jna/overview.html
+++ b/src/com/sun/jna/overview.html
@@ -683,7 +683,12 @@ Unions
Obtaining "last" error
If a function sets the system error property
-(errno
or GetLastError()
), the error code will be thrown as a {@link com.sun.jna.LastErrorException} if you declare the exception in your JNA mapping. Alternatively, you can use {@link com.sun.jna.Native#getLastError()} to retrieve it, providing that {@link com.sun.jna.Native#setPreserveLastError(boolean)} has been called with a true
value. Throwing an exception is preferred since it has better performance.
+(errno
or
+GetLastError()
),
+the error code will be thrown as a {@link com.sun.jna.LastErrorException} if you
+declare the exception in your JNA mapping. Alternatively, you can use
+{@link com.sun.jna.Native#getLastError()} to retrieve it. Throwing an exception
+is preferred since it has better performance.
Arbitrary Java Object arguments/return values
@@ -743,10 +748,6 @@ Large Structures
com.sun.jna.Structure#writeField(String,Object)} to synch with just the fields
of interest.
Throw exceptions on last error
-To avoid the overhead of preserving the system last error information on every
-native call, invoke
-{@link com.sun.jna.Native#setPreserveLastError setPreserveLastError(false)} or
-set the System property jna.preserve_last_error=false
.
In those methods where you are interested in the value of errno/GetLastError(),
declare your method to throw {@link com.sun.jna.LastErrorException}.