Bug 63945 - NPE when opening a file after file system change
Summary: NPE when opening a file after file system change
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.2
Hardware: PC All
: P2 normal (vote)
Target Milestone: JMETER_5.3.0
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2019-11-20 20:05 UTC by Michael
Modified: 2020-03-15 14:36 UTC (History)
1 user (show)



Attachments
Use a more consistent logic to choose initial dir for FileChooser (2.18 KB, patch)
2019-11-24 10:24 UTC, Felix Schumacher
Details | Diff
Use a more consistent logic to choose initial dir for FileChooser (3.29 KB, patch)
2019-11-24 11:19 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2019-11-20 20:05:56 UTC
If you navigate to File > Open in JMeter 5.2 and the directory in which the current file was opened no longer exists, you will get a null pointer exception. The full stack trace is below. I run into this issue when working with a Git repository that holds JMeter scripts. I will open a file, work with it, then switch branches to look at a different script and get the error shown below.

While this shouldn't matter, I am running JMeter under WSL in Windows 10, rather than the Windows 10 binary.

ERROR | Error processing org.apache.jmeter.gui.action.Load@76b224cd
java.lang.NullPointerException
        at java.desktop/javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:971)
        at java.desktop/javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:1091)
        at java.desktop/javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:1004)
        at java.desktop/javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:103)
        at java.desktop/javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:257)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
        at com.bulenkov.darcula.ui.DarculaComboBoxUI.getSizeForComponent(DarculaComboBoxUI.java:129)
        at java.desktop/javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1409)
        at java.desktop/javax.swing.plaf.basic.BasicComboBoxUI.getMinimumSize(BasicComboBoxUI.java:960)
        at java.desktop/javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:949)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
        at java.desktop/javax.swing.plaf.metal.MetalFileChooserUI$1.getPreferredSize(MetalFileChooserUI.java:246)
        at java.desktop/java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:724)
        at java.desktop/java.awt.Container.preferredSize(Container.java:1823)
        at java.desktop/java.awt.Container.getPreferredSize(Container.java:1807)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1682)
        at java.desktop/java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:729)
        at java.desktop/javax.swing.plaf.metal.MetalFileChooserUI.getPreferredSize(MetalFileChooserUI.java:622)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
        at java.desktop/java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:724)
        at java.desktop/java.awt.Container.preferredSize(Container.java:1823)
        at java.desktop/java.awt.Container.getPreferredSize(Container.java:1807)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1682)
        at java.desktop/javax.swing.JRootPane$RootLayout.preferredLayoutSize(JRootPane.java:866)
        at java.desktop/java.awt.Container.preferredSize(Container.java:1823)
        at java.desktop/java.awt.Container.getPreferredSize(Container.java:1807)
        at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1682)
        at java.desktop/java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:724)
        at java.desktop/java.awt.Container.preferredSize(Container.java:1823)
        at java.desktop/java.awt.Container.getPreferredSize(Container.java:1807)
        at java.desktop/java.awt.Window.pack(Window.java:826)
        at java.desktop/javax.swing.JFileChooser.createDialog(JFileChooser.java:819)
        at java.desktop/javax.swing.JFileChooser.showDialog(JFileChooser.java:747)
        at java.desktop/javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:653)
        at org.apache.jmeter.gui.util.FileDialoger.promptToOpenFile(FileDialoger.java:207)
        at org.apache.jmeter.gui.util.FileDialoger.promptToOpenFile(FileDialoger.java:156)
        at org.apache.jmeter.gui.util.FileDialoger.promptToOpenFile(FileDialoger.java:135)
        at org.apache.jmeter.gui.util.FileDialoger.promptToOpenFile(FileDialoger.java:115)
        at org.apache.jmeter.gui.action.Load.doActionAfterCheck(Load.java:76)
        at org.apache.jmeter.gui.action.AbstractActionWithNoRunningTest.doAction(AbstractActionWithNoRunningTest.java:45)
        at org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:88)
        at org.apache.jmeter.gui.action.ActionRouter.lambda$actionPerformed$0(ActionRouter.java:70)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
        at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
        at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
        at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Comment 1 Felix Schumacher 2019-11-24 10:23:50 UTC
Thanks for the report. This seems to be a problem with JDK.

As a workaround, you can try to use another LAF than Metal in JMeter.

@team
While having a look at the code, I found a few places, where we look for the existence of the initial directory on which the file chooser should start.

I extended and simplified those occurrences and think I found a bug in the logic that chooses the initial location in FileDialoger#promptToOpenFile from line 177.

First we look, if existingFileName is pointing to something valid and use that as the initial location or the global initial location, if none location has been used before.

After that a bit further down, we test if a location has been used before and may initialize such a location.

Than -- and this is the potential bug -- we always use that location for the initial location of the file chooser.

Another dodgy logic is that we test for the default initial location in two different ways. First -- when no existingFileName is given -- we test for an empty default location and refuse to use it, if it is empty. The second time, we accept the default location, even if it is empty AND use it as the default location for the next runs.
Comment 2 Felix Schumacher 2019-11-24 10:24:53 UTC
Created attachment 36899 [details]
Use a more consistent logic to choose initial dir for FileChooser
Comment 3 Felix Schumacher 2019-11-24 10:32:29 UTC
This problem -- I still think it is an JDK problem -- might be the cause for a few other reports that I found:

 https://stackoverflow.com/questions/56928382/with-jmeter-5-1-1-r1855137-not-able-to-save-any-script-getting-exceptions-in-l
 https://stackoverflow.com/questions/50097525/jmeter-4-0-unable-to-access-menus
Comment 4 Felix Schumacher 2019-11-24 11:19:56 UTC
Created attachment 36900 [details]
Use a more consistent logic to choose initial dir for FileChooser
Comment 5 Felix Schumacher 2019-11-27 17:29:08 UTC
@Michael, could you test the next nightly, if this fixes your problem?


commit bfabdb8fc84b992ab73c516f591ac5d08da1b0a7
AuthorDate: Sun Nov 24 11:33:32 2019 +0100

    Use a sane initial dir for the file chooser
    
    While having a look at 63945, I found a few places, where we look for the existence
    of the initial directory on which the file chooser should start.
    
    I extended and simplified those occurrences and think I found a bug in the logic that
    chooses the initial location in FileDialoger#promptToOpenFile from line 177.
    
    First we look, if existingFileName is pointing to something valid and use that as the
    initial location or the global initial location, if none location has been used before.
    
    After that a bit further down, we test if a location has been used before and may
    initialize such a location.
    
    Than -- and this is the potential bug -- we always use that location for the initial
    location of the file chooser.
    
    Another dodgy logic is that we test for the default initial location in two different ways.
    First -- when no existingFileName is given -- we test for an empty default location and refuse
    to use it, if it is empty. The second time, we accept the default location, even if it is
    empty AND use it as the default location for the next runs.
    
    Bugzilla Id: 63945
---
 .../org/apache/jmeter/gui/util/FileDialoger.java   | 39 ++++++++++++----------
 xdocs/changes.xml                                  |  2 ++
 2 files changed, 24 insertions(+), 17 deletions(-)
Comment 6 Philippe Mouawad 2019-12-08 16:46:18 UTC
Hello Michael,
Any feedback please ?

Thank you
Comment 7 Michael 2020-03-06 20:53:39 UTC
(In reply to Philippe Mouawad from comment #6)
> Hello Michael,
> Any feedback please ?
> 
> Thank you

Sorry, just getting back to this after a space away.

I tried the most recent nightly (the 2020-03-06 build from https://ci.apache.org/projects/jmeter/nightlies/) and it fixed the problem I was having. After creating a test repo and deleting the directory, the open dialog moved up the tree to a directory that did still exist.
Comment 8 Felix Schumacher 2020-03-07 09:38:33 UTC
Thanks for confirming, that the problem is fixed for you.