Skip to content

Commit

Permalink
Cleanup deprecated elements
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing committed Sep 13, 2017
1 parent fddc668 commit 69047a0
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 187 deletions.
38 changes: 35 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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));
}

/**
Expand Down
4 changes: 0 additions & 4 deletions contrib/platform/src/com/sun/jna/platform/win32/OleAuto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -883,9 +882,6 @@ protected List<String> 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.
Expand Down
17 changes: 0 additions & 17 deletions contrib/platform/src/com/sun/jna/platform/win32/User32.java
Original file line number Diff line number Diff line change
Expand Up @@ -1717,23 +1717,6 @@ HWND CreateWindowEx(int dwExStyle, String lpClassName,
* </p>
*/
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.
* <ul><li>MONITOR_DEFAULTTONEAREST</li>
* <li>MONITOR_DEFAULTTONULL</li>
* <li>MONITOR_DEFAULTTOPRIMARY</li></ul>
* @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.
Expand Down
22 changes: 1 addition & 21 deletions contrib/platform/src/com/sun/jna/platform/win32/Variant.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
package com.sun.jna.platform.win32;

import com.sun.jna.IntegerType;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<String> FIELDS = createFieldsOrder("vt",
"wReserved1", "wReserved2", "wReserved3", "__variant");
Expand Down
12 changes: 0 additions & 12 deletions contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,18 +936,6 @@ public long toTime() {
return toDate().getTime();
}

/**
* <p>Converts this filetime into a number of milliseconds which have
* passed since January 1, 1970 (UTC).</p>
* @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();
}

/**
* <p>Converts the two 32-bit unsigned integer parts of this filetime
* into a 64-bit unsigned integer representing the number of
Expand Down
30 changes: 2 additions & 28 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <major>.<minor>.<revision>
Expand Down Expand Up @@ -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 <code>true</code><p>
* @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 <code>long</code> value.
* This method is primarily for X11-based systems, which use an opaque
Expand Down Expand Up @@ -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<Memory> nativeThreadTerminationFlag =
new ThreadLocal<Memory>() {
Expand Down
65 changes: 0 additions & 65 deletions src/com/sun/jna/Pointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>wide</code> is true,
* access the memory as an array of <code>wchar_t</code>, otherwise
* as an array of <code>char</code>, 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 <code>String</code> 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 (<code>const wchar_t *</code>) string from memory. */
public String getWideString(long offset) {
return Native.getWideString(this, this.peer, offset);
Expand Down Expand Up @@ -811,19 +794,6 @@ public String[] getStringArray(long offset, int length) {
return getStringArray(offset, length, Native.getDefaultStringEncoding());
}

/** Returns an array of <code>String</code> based on a native array
* of <code>char*</code> or <code>wchar_t*</code> based on the
* <code>wide</code> 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);
}
Expand All @@ -832,18 +802,6 @@ public String[] getWideStringArray(long offset, int length) {
return getStringArray(offset, length, NativeString.WIDE_STRING);
}

/** Returns an array of <code>String</code> based on a native array
* of <code>char*</code> or <code>wchar_t*</code> based on the
* <code>wide</code> 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 <code>String</code> based on a native array
* of <code>char*</code> or <code>wchar_t*</code> based on the
* <code>wide</code> parameter, using the given array length.
Expand Down Expand Up @@ -1145,29 +1103,6 @@ public void setPointer(long offset, Pointer value) {
Native.setPointer(this, this.peer, offset, value != null ? value.peer : 0);
}

/**
* Copy string <code>value</code> to the location being pointed to.
*
* @param offset byte offset from pointer at which characters in
* <code>value</code> must be set
* @param value <code>java.lang.String</code> value to set
* @param wide whether to write the native string as an array of
* <code>wchar_t</code>. If false, writes as a NUL-terminated array of
* <code>char</code> 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 <code>value</code> to the location being pointed to as a
* wide string (<code>wchar_t*</code>).
Expand Down
11 changes: 0 additions & 11 deletions src/com/sun/jna/Structure.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,17 +890,6 @@ protected void writeField(StructField structField) {
*/
protected abstract List<String> 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
Expand Down
11 changes: 6 additions & 5 deletions src/com/sun/jna/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,12 @@ <h3>Unions</h3>
<a name="last-error"></a>
<h3>Obtaining "last" error</h3>
If a function sets the system error property
(<code><a href="http://www.opengroup.org/onlinepubs/009695399/functions/errno.html">errno</a></code> or <code><a href="http://msdn.microsoft.com/en-us/library/ms679360(VS.85).aspx">GetLastError()</a></code>), 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 <code>true</code> value. Throwing an exception is preferred since it has better performance.
(<code><a href="http://www.opengroup.org/onlinepubs/009695399/functions/errno.html">errno</a></code> or
<code><a href="http://msdn.microsoft.com/en-us/library/ms679360(VS.85).aspx">GetLastError()</a></code>),
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.

<a name="java-objects"></a>
<h3>Arbitrary Java Object arguments/return values</h3>
Expand Down Expand Up @@ -743,10 +748,6 @@ <h3>Large Structures</h3>
com.sun.jna.Structure#writeField(String,Object)} to synch with just the fields
of interest.
<h3>Throw exceptions on last error</h3>
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 <code>jna.preserve_last_error=false</code>.<p/>
In those methods where you are interested in the value of errno/GetLastError(),
declare your method to throw {@link com.sun.jna.LastErrorException}.
</body>
Expand Down
9 changes: 0 additions & 9 deletions test/com/sun/jna/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ public void testLoadLibraryMethods() throws Exception {
}
}
}

@SuppressWarnings("deprecation")
public void testVersion() {
String[] INPUTS = { "1.0", "1.0.1", "2.1.3" };
float[] EXPECTED = { 1.0f, 1.0f, 2.1f };
for (int i=0;i < INPUTS.length;i++) {
assertEquals("Incorrectly parsed version", EXPECTED[i], Native.parseVersion(INPUTS[i]));
}
}

public void testLongStringGeneration() {
StringBuilder buf = new StringBuilder();
Expand Down

0 comments on commit 69047a0

Please sign in to comment.