Skip to content

Commit

Permalink
NullPointerException can be caused by calling ProxyObject#dispose mul…
Browse files Browse the repository at this point in the history
…tiple times

Closes: java-native-access#894
  • Loading branch information
matthiasblaesing committed Dec 22, 2017
1 parent 10b7584 commit 2ba3b63
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 2ba3b63

Please sign in to comment.