New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE on invoking JFrames with tray within AssertJSwingJUnitTestCase #197

Open
angeloBerlin opened this Issue Jan 2, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@angeloBerlin

angeloBerlin commented Jan 2, 2017

Running the test results in an NPE. Doing the same without extending AssertJSwingJUnitTestCase works fine.

import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;

import javax.swing.JFrame;

public class TrayFrame extends JFrame {

	public TrayFrame() {

		setSize(200, 100);

		if (SystemTray.isSupported()) {

			SystemTray tray = SystemTray.getSystemTray();
			Image image = Toolkit.getDefaultToolkit().getImage("");
			TrayIcon trayIcon = new TrayIcon(image);

			try {
				tray.add(trayIcon);
			} catch (AWTException e) {
				e.printStackTrace();
			}
		}

		setVisible(true);
	}

	public static void main(String[] args) {
		new TrayFrame();
	}
}
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.edt.GuiQuery;
import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
import org.junit.Test;

public class TrayTest extends AssertJSwingJUnitTestCase {

	@Override
	protected void onSetUp() {
	}

	@Test
	public void openFrameWithGuiRunner() {
		GuiActionRunner.execute(new GuiQuery<TrayFrame>() {

			@Override
			protected TrayFrame executeInEDT() {
				return new TrayFrame();
			}
		});
	}
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at org.assertj.core.util.Preconditions.checkNotNull(Preconditions.java:76)
	at org.assertj.swing.input.InputState.screenLocation(InputState.java:129)
	at org.assertj.swing.input.InputState.update(InputState.java:112)
	at org.assertj.swing.input.InputState$1.processEvent(InputState.java:72)
	at org.assertj.swing.listener.EventDispatchThreadedEventListener.eventDispatched(EventDispatchThreadedEventListener.java:79)
	at org.assertj.swing.input.EventNormalizer.delegate(EventNormalizer.java:92)
	at org.assertj.swing.input.EventNormalizer.eventDispatched(EventNormalizer.java:87)
	at org.assertj.swing.listener.WeakEventListener.eventDispatched(WeakEventListener.java:82)
	at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2425)
	at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2317)
	at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
	at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2275)
	at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:721)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:763)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.awt.EventQueue$3.run(EventQueue.java:703)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.awt.EventQueue$4.run(EventQueue.java:731)
	at java.awt.EventQueue$4.run(EventQueue.java:729)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
@croesch

This comment has been minimized.

Show comment
Hide comment
@croesch

croesch May 16, 2017

Collaborator

On which system and version are you runngin?

Using the latest AssertJ Swing under Linux works well for me. I copied your test and it runs normally - no exception, no test failures.

Collaborator

croesch commented May 16, 2017

On which system and version are you runngin?

Using the latest AssertJ Swing under Linux works well for me. I copied your test and it runs normally - no exception, no test failures.

@croesch croesch assigned croesch and angeloBerlin and unassigned croesch and angeloBerlin May 16, 2017

@angeloBerlin

This comment has been minimized.

Show comment
Hide comment
@angeloBerlin

angeloBerlin May 16, 2017

Its running fine on MacOS but fails on Windows 10

angeloBerlin commented May 16, 2017

Its running fine on MacOS but fails on Windows 10

@croesch

This comment has been minimized.

Show comment
Hide comment
@croesch

croesch May 16, 2017

Collaborator

Thx for the quick answer

Collaborator

croesch commented May 16, 2017

Thx for the quick answer

@bernardobreder

This comment has been minimized.

Show comment
Hide comment
@bernardobreder

bernardobreder Jun 1, 2017

I have the same problem in my project and i have no idea how to solve.

I am using this assert library: assertj-core-3.5.1.jar, assertj-swing-3.4.0.jar, assertj-swing-jide-3.4.0.jar, assertj-swing-junit-3.4.0.jar, assertj-swing-testng-3.4.0.jar, bsh-2.0b4.jar, fest-reflect-1.4.1.jar, fest-util-1.2.5.jar, jcommander-1.48.jar, slf4j-api-1.7.16.jar, testng-6.9.10.jar

In the StackTrace, the part org.assertj.swing.input.InputState.screenLocation(InputState.java:129) has event with toString: java.awt.event.MouseEvent[MOUSE_MOVED,(27,382),absolute(27,382),clickCount=0] on java.awt.TrayIcon@530271d6
and the java.awt.event.ComponentEvent.getComponent() say that TrayIcon can not has a Component:
public Component getComponent() {
return (source instanceof Component) ? (Component)source : null;
}

My question is, why this event happened in Windows 10 ?

Sistema Operacional: Windows 10 10.0
Timezone: sun.util.calendar.ZoneInfo[id="GMT-03:00",offset=-10800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
JVM: 1.8.0_131
Exceção:
Tipo: java.lang.NullPointerException
Mensagem: null
Pilha de execução:
java.lang.NullPointerException
at org.assertj.core.util.Preconditions.checkNotNull(Preconditions.java:76)
at org.assertj.swing.input.InputState.screenLocation(InputState.java:129)
at org.assertj.swing.input.InputState.update(InputState.java:112)
at org.assertj.swing.input.InputState$1.processEvent(InputState.java:72)
at org.assertj.swing.listener.EventDispatchThreadedEventListener.eventDispatched(EventDispatchThreadedEventListener.java:79)
at org.assertj.swing.input.EventNormalizer.delegate(EventNormalizer.java:92)
at org.assertj.swing.input.EventNormalizer.eventDispatched(EventNormalizer.java:87)
at org.assertj.swing.listener.WeakEventListener.eventDispatched(WeakEventListener.java:82)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2425)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2317)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2275)
at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:721)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:763)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

bernardobreder commented Jun 1, 2017

I have the same problem in my project and i have no idea how to solve.

I am using this assert library: assertj-core-3.5.1.jar, assertj-swing-3.4.0.jar, assertj-swing-jide-3.4.0.jar, assertj-swing-junit-3.4.0.jar, assertj-swing-testng-3.4.0.jar, bsh-2.0b4.jar, fest-reflect-1.4.1.jar, fest-util-1.2.5.jar, jcommander-1.48.jar, slf4j-api-1.7.16.jar, testng-6.9.10.jar

In the StackTrace, the part org.assertj.swing.input.InputState.screenLocation(InputState.java:129) has event with toString: java.awt.event.MouseEvent[MOUSE_MOVED,(27,382),absolute(27,382),clickCount=0] on java.awt.TrayIcon@530271d6
and the java.awt.event.ComponentEvent.getComponent() say that TrayIcon can not has a Component:
public Component getComponent() {
return (source instanceof Component) ? (Component)source : null;
}

My question is, why this event happened in Windows 10 ?

Sistema Operacional: Windows 10 10.0
Timezone: sun.util.calendar.ZoneInfo[id="GMT-03:00",offset=-10800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
JVM: 1.8.0_131
Exceção:
Tipo: java.lang.NullPointerException
Mensagem: null
Pilha de execução:
java.lang.NullPointerException
at org.assertj.core.util.Preconditions.checkNotNull(Preconditions.java:76)
at org.assertj.swing.input.InputState.screenLocation(InputState.java:129)
at org.assertj.swing.input.InputState.update(InputState.java:112)
at org.assertj.swing.input.InputState$1.processEvent(InputState.java:72)
at org.assertj.swing.listener.EventDispatchThreadedEventListener.eventDispatched(EventDispatchThreadedEventListener.java:79)
at org.assertj.swing.input.EventNormalizer.delegate(EventNormalizer.java:92)
at org.assertj.swing.input.EventNormalizer.eventDispatched(EventNormalizer.java:87)
at org.assertj.swing.listener.WeakEventListener.eventDispatched(WeakEventListener.java:82)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2425)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2317)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit$ToolkitEventMulticaster.eventDispatched(Toolkit.java:2316)
at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2275)
at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:721)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:763)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@bernardobreder

This comment has been minimized.

Show comment
Hide comment
@bernardobreder

bernardobreder Jan 23, 2018

Someone have any idea how to solve the problem ?

bernardobreder commented Jan 23, 2018

Someone have any idea how to solve the problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment