diff --git a/CHANGES.md b/CHANGES.md index f583b76d5b..a8d0f9858c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ Bug Fixes * [#876](https://github.com/java-native-access/jna/pull/876): Restore java 6 compatibility - [@matthiasblaesing](https://github.com/matthiasblaesing). * [#882](https://github.com/java-native-access/jna/pull/882): Correctly close file in `ELFAnalyser#runDetection`, fix suggested by [@Sylvyrfysh](https://github.com/Sylvyrfysh) in [#880](https://github.com/java-native-access/jna/pull/880) - [@matthiasblaesing](https://github.com/matthiasblaesing). * [#887](https://github.com/java-native-access/jna/issues/887): MacFileUtils.moveToTrash() doesn't work in a sandboxed app fix suggested by [@sobakasu](https://github.com/sobakasu) - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#894](https://github.com/java-native-access/jna/issues/894): NullPointerException can be caused by calling `com.sun.jna.platform.win32.COM.util.ProxyObject#dispose` multiple times - [@matthiasblaesing](https://github.com/matthiasblaesing). Breaking Changes ---------------- diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java index 40560a6b2e..9ffd41fcb3 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java @@ -34,7 +34,6 @@ import com.sun.jna.platform.win32.Guid; import com.sun.jna.platform.win32.Guid.IID; import com.sun.jna.platform.win32.Guid.REFIID; -import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.Kernel32Util; import com.sun.jna.platform.win32.OaIdl; import com.sun.jna.platform.win32.OaIdl.DISPID; @@ -46,7 +45,6 @@ import com.sun.jna.platform.win32.Variant.VARIANT; import com.sun.jna.platform.win32.WinDef; import com.sun.jna.platform.win32.WinDef.DWORDByReference; -import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinNT; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.platform.win32.COM.COMException; @@ -134,7 +132,7 @@ protected void finalize() throws Throwable { } public synchronized void dispose() { - if (! ((Dispatch) this.rawDispatch).getPointer().equals(Pointer.NULL)) { + if (((Dispatch) this.rawDispatch).getPointer() != Pointer.NULL) { this.rawDispatch.Release(); ((Dispatch) this.rawDispatch).setPointer(Pointer.NULL); factory.unregister(this); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java index 5ac09cfce5..65dc70925a 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java @@ -12,7 +12,6 @@ */ package com.sun.jna.platform.win32.COM.util; -import com.sun.jna.Pointer; import static org.junit.Assert.*; import java.io.File; @@ -25,7 +24,6 @@ import com.sun.jna.platform.win32.COM.util.annotation.ComObject; import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; -import com.sun.jna.platform.win32.Ole32; public class ProxyObjectFactory_Test { diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java index 4b6ccee62f..36f4ef6bb3 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java @@ -15,6 +15,8 @@ import com.sun.jna.Pointer; import static org.junit.Assert.*; +import java.lang.reflect.Proxy; + import java.io.File; import org.junit.After; @@ -156,7 +158,8 @@ public void notEquals() { @Test public void accessWhilstDisposing() { MsWordApp comObj1 = this.factory.createObject(MsWordApp.class); - + comObj1.Quit(); + //TODO: how to test this? this.factory.disposeAll(); @@ -186,4 +189,13 @@ public void testVarargsCallWithParameter() { boolean wasDeleted = new File("abcdefg.pdf").delete(); assertTrue(wasDeleted); } + + + @Test + public void testDisposeMustBeCallableMultipleTimes() { + MsWordApp comObj = this.factory.createObject(MsWordApp.class); + comObj.Quit(); + ((ProxyObject) Proxy.getInvocationHandler(comObj)).dispose(); + ((ProxyObject) Proxy.getInvocationHandler(comObj)).dispose(); + } }