Skip to content

Commit

Permalink
Fix return type of Native#loadLibrary to match unconstrained generic …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
Lyor Goldstein committed Dec 15, 2015
1 parent 4e0388c commit 20dda2b
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 358 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Bug Fixes
* [#549](https://github.com/java-native-access/jna/pull/549): Fixed bug in types derived from XID - [@twall](https://github.com/twall).
* [#536](https://github.com/java-native-access/jna/pull/536): Fixed bug in determining the Library and options associated with types defined outside of a Library - [@twall](https://github.com/twall).
* [#531](https://github.com/java-native-access/jna/pull/531): Ensure direct-mapped callbacks use the right calling convention - [@twall](https://github.com/twall).
* [#565](https://github.com/java-native-access/jna/pull/565): Fix return type of Native#loadLibrary to match unconstrained generic [@lgoldstein](https://github.com/lgoldstein)

Release 4.2.1
=============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MacFileUtils extends FileUtils {

public interface FileManager extends Library {

public FileManager INSTANCE = (FileManager)Native.loadLibrary("CoreServices", FileManager.class);
FileManager INSTANCE = Native.loadLibrary("CoreServices", FileManager.class);

int kFSFileOperationDefaultOptions = 0;
int kFSFileOperationsOverwrite = 0x01;
Expand Down
10 changes: 5 additions & 5 deletions contrib/platform/src/com/sun/jna/platform/unix/X11.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class XImage extends PointerType { }

/** Definition (incomplete) of the Xext library. */
interface Xext extends Library {
Xext INSTANCE = (Xext)Native.loadLibrary("Xext", Xext.class);
Xext INSTANCE = Native.loadLibrary("Xext", Xext.class);
// Shape Kinds
int ShapeBounding = 0;
int ShapeClip = 1;
Expand All @@ -296,7 +296,7 @@ void XShapeCombineMask(Display display, Window window, int dest_kind,

/** Definition (incomplete) of the Xrender library. */
interface Xrender extends Library {
Xrender INSTANCE = (Xrender)Native.loadLibrary("Xrender", Xrender.class);
Xrender INSTANCE = Native.loadLibrary("Xrender", Xrender.class);
class XRenderDirectFormat extends Structure {
public short red, redMask;
public short green, greenMask;
Expand Down Expand Up @@ -338,7 +338,7 @@ protected List getFieldOrder() {
/** Definition of the Xevie library. */
interface Xevie extends Library {
/** Instance of Xevie. Note: This extension has been removed from xorg/xserver on Oct 22, 2008 because it is broken and maintainerless. */
Xevie INSTANCE = (Xevie)Native.loadLibrary("Xevie", Xevie.class);
Xevie INSTANCE = Native.loadLibrary("Xevie", Xevie.class);
int XEVIE_UNMODIFIED = 0;
int XEVIE_MODIFIED = 1;
// Bool XevieQueryVersion (Display* display, int* major_version, int* minor_version);
Expand All @@ -355,7 +355,7 @@ interface Xevie extends Library {

/** Definition of the XTest library. */
interface XTest extends Library {
XTest INSTANCE = (XTest)Native.loadLibrary("Xtst", XTest.class);///usr/lib/libxcb-xtest.so.0
XTest INSTANCE = Native.loadLibrary("Xtst", XTest.class);///usr/lib/libxcb-xtest.so.0
boolean XTestQueryExtension(Display display, IntByReference event_basep, IntByReference error_basep, IntByReference majorp, IntByReference minorp);
boolean XTestCompareCursorWithWindow(Display display, Window window, Cursor cursor);
boolean XTestCompareCurrentCursorWithWindow(Display display, Window window);
Expand Down Expand Up @@ -393,7 +393,7 @@ protected List getFieldOrder() {
}
}

X11 INSTANCE = (X11)Native.loadLibrary("X11", X11.class);
X11 INSTANCE = Native.loadLibrary("X11", X11.class);

/*
typedef struct {
Expand Down
15 changes: 10 additions & 5 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public static List<String> toStringList(char[] buf, int offset, int len) {
* @throws UnsatisfiedLinkError if the library cannot be found or
* dependent libraries are missing.
*/
public static <T extends Library> T loadLibrary(Class<T> interfaceClass) {
public static <T> T loadLibrary(Class<T> interfaceClass) {
return loadLibrary(null, interfaceClass);
}

Expand All @@ -465,7 +465,7 @@ public static <T extends Library> T loadLibrary(Class<T> interfaceClass) {
* dependent libraries are missing.
* @see #loadLibrary(String, Class, Map)
*/
public static <T extends Library> T loadLibrary(Class<T> interfaceClass, Map options) {
public static <T> T loadLibrary(Class<T> interfaceClass, Map options) {
return loadLibrary(null, interfaceClass, options);
}

Expand All @@ -483,7 +483,7 @@ public static <T extends Library> T loadLibrary(Class<T> interfaceClass, Map opt
* dependent libraries are missing.
* @see #loadLibrary(String, Class, Map)
*/
public static <T extends Library> T loadLibrary(String name, Class<T> interfaceClass) {
public static <T> T loadLibrary(String name, Class<T> interfaceClass) {
return loadLibrary(name, interfaceClass, Collections.emptyMap());
}

Expand All @@ -503,7 +503,12 @@ public static <T extends Library> T loadLibrary(String name, Class<T> interfaceC
* @throws UnsatisfiedLinkError if the library cannot be found or
* dependent libraries are missing.
*/
public static <T extends Library> T loadLibrary(String name, Class<T> interfaceClass, Map options) {
public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map options) {
if (!Library.class.isAssignableFrom(interfaceClass)) {
throw new IllegalArgumentException("Interface (" + interfaceClass.getSimpleName() + ")"
+ " of library=" + name + " does not extend " + Library.class.getSimpleName());
}

Library.Handler handler = new Library.Handler(name, interfaceClass, options);
ClassLoader loader = interfaceClass.getClassLoader();
Object proxy = Proxy.newProxyInstance(loader, new Class[] {interfaceClass}, handler);
Expand Down Expand Up @@ -1396,7 +1401,7 @@ public static boolean registered(Class<?> cls) {
/** Unregister the native methods for the given class. */
private static native void unregister(Class<?> cls, long[] handles);

private static String getSignature(Class<?> cls) {
static String getSignature(Class<?> cls) {
if (cls.isArray()) {
return "[" + getSignature(cls.getComponentType());
}
Expand Down
Loading

0 comments on commit 20dda2b

Please # to comment.