ASF Bugzilla – Attachment 36900 Details for
Bug 63945
NPE when opening a file after file system change
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Use a more consistent logic to choose initial dir for FileChooser
filechooser.patch (text/plain), 3.29 KB, created by
Felix Schumacher
on 2019-11-24 11:19:56 UTC
(
hide
)
Description:
Use a more consistent logic to choose initial dir for FileChooser
Filename:
MIME Type:
Creator:
Felix Schumacher
Created:
2019-11-24 11:19:56 UTC
Size:
3.29 KB
patch
obsolete
>diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/FileDialoger.java b/src/core/src/main/java/org/apache/jmeter/gui/util/FileDialoger.java >index 23c795e144..7fb50bdf97 100644 >--- a/src/core/src/main/java/org/apache/jmeter/gui/util/FileDialoger.java >+++ b/src/core/src/main/java/org/apache/jmeter/gui/util/FileDialoger.java >@@ -20,6 +20,7 @@ package org.apache.jmeter.gui.util; > > import java.awt.Component; > import java.io.File; >+import java.util.Arrays; > > import javax.swing.JFileChooser; > import javax.swing.filechooser.FileFilter; >@@ -27,6 +28,8 @@ import javax.swing.filechooser.FileFilter; > import org.apache.commons.lang3.StringUtils; > import org.apache.jmeter.gui.GuiPackage; > import org.apache.jmeter.gui.JMeterFileFilter; >+import org.slf4j.Logger; >+import org.slf4j.LoggerFactory; > > /** > * Class implementing a file open dialogue >@@ -39,6 +42,8 @@ public final class FileDialoger { > > private static JFileChooser jfc = new JFileChooser(); > >+ private static final Logger LOG = LoggerFactory.getLogger(FileDialoger.class); >+ > /** > * Prevent instantiation of utility class. > */ >@@ -180,19 +185,7 @@ public final class FileDialoger { > } else { > jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); > } >- if(!StringUtils.isEmpty(existingFileName)) { >- File existingFileStart = new File(existingFileName); >- if(existingFileStart.exists() && existingFileStart.canRead()) { >- jfc.setCurrentDirectory(new File(existingFileName)); >- } >- } >- else if (lastJFCDirectory == null) { >- String start = System.getProperty("user.dir", ""); //$NON-NLS-1$//$NON-NLS-2$ >- >- if (start.length() > 0) { >- jfc.setCurrentDirectory(new File(start)); >- } >- } >+ setCurrentDirOnJFC(existingFileName, lastJFCDirectory, System.getProperty("user.dir")); > clearFileFilters(); > if(exts != null && exts.length > 0) { > JMeterFileFilter currentFilter = new JMeterFileFilter(exts); >@@ -200,10 +193,6 @@ public final class FileDialoger { > jfc.setAcceptAllFileFilterUsed(true); > jfc.setFileFilter(currentFilter); > } >- if(lastJFCDirectory==null) { >- lastJFCDirectory = System.getProperty("user.dir", ""); //$NON-NLS-1$//$NON-NLS-2$ >- } >- jfc.setCurrentDirectory(new File(lastJFCDirectory)); > int retVal = jfc.showOpenDialog(parentComponent); > lastJFCDirectory = jfc.getCurrentDirectory().getAbsolutePath(); > >@@ -213,6 +202,22 @@ public final class FileDialoger { > return null; > } > >+ private static void setCurrentDirOnJFC(String... dirNames) { >+ for (String dirName : dirNames) { >+ if (StringUtils.isBlank(dirName)) { >+ continue; >+ } >+ File possibleDir = new File(dirName); >+ if (possibleDir.exists() && possibleDir.canRead()) { >+ jfc.setCurrentDirectory(possibleDir); >+ return; >+ } >+ } >+ LOG.info("No valid initial directory found for: {}", >+ Arrays.asList(dirNames)); >+ jfc.setCurrentDirectory(null); >+ } >+ > private static void clearFileFilters() { > FileFilter[] filters = jfc.getChoosableFileFilters(); > for (FileFilter filter : filters) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 63945
:
36899
| 36900