This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new a26ed2f When importing example test plan JMeter displays an
NullPointerException
a26ed2f is described below
commit a26ed2fc61b039334e4a065bb5ee6afa48527a0d
Author: Felix Schumacher <[email protected]>
AuthorDate: Tue Dec 29 12:39:10 2020 +0100
When importing example test plan JMeter displays an NullPointerException
The fix has introduced a bug, where newly added files might be left as
duplicates in the menu.
Bugzilla Id: 64957, 65032
---
.../jmeter/gui/action/LoadRecentProject.java | 44 ++++++++++------------
1 file changed, 20 insertions(+), 24 deletions(-)
diff --git
a/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java
b/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java
index af1bfaa..1793354 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java
@@ -27,6 +27,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.prefs.Preferences;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
@@ -114,41 +116,31 @@ public class LoadRecentProject extends Load {
* been loaded
*/
public static void updateRecentFileMenuItems(List<JComponent> menuItems,
String loadedFileName) {
- // Get the preference for the recent files
-
- Deque<String> newRecentFiles = new ArrayDeque<>();
- // Check if the new file is already in the recent list
- boolean alreadyExists = false;
- for(int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) {
- String recentFilePath = getRecentFile(i);
- if (recentFilePath == null) {
- continue;
- }
- if(!loadedFileName.equals(recentFilePath)) {
- newRecentFiles.add(recentFilePath);
- }
- else {
- alreadyExists = true;
- }
+ // Do nothing, when no real file was given
+ if (loadedFileName == null) {
+ return;
}
- // Add the new file at the start of the list
+ // Get the preference for the recent files
+ Deque<String> newRecentFiles = IntStream.range(0, NUMBER_OF_MENU_ITEMS)
+ .mapToObj(i -> getRecentFile(i))
+ .filter(s -> s != null)
+ .filter(s -> !(s.equals(loadedFileName)))
+ .collect(Collectors.toCollection(ArrayDeque::new));
newRecentFiles.addFirst(loadedFileName);
- // Remove the last item from the list if it was a brand new file
- if(!alreadyExists) {
- newRecentFiles.removeLast();
- }
+
// Store the recent files
int index = 0;
for (String fileName : newRecentFiles) {
- if (fileName == null) {
- continue;
- }
setRecentFile(index, fileName);
index++;
if (index >= NUMBER_OF_MENU_ITEMS) {
break;
}
}
+ while (index < NUMBER_OF_MENU_ITEMS) {
+ removeRecentFile(index);
+ index++;
+ }
// Update menu items to reflect recent files
updateMenuItems(menuItems);
}
@@ -250,6 +242,10 @@ public class LoadRecentProject extends Load {
prefs.put(USER_PREFS_KEY + index, fileName);
}
+ private static void removeRecentFile(int index) {
+ prefs.remove(USER_PREFS_KEY + index);
+ }
+
/**
* @param fileLoadRecentFiles List of JMenuItem
* @return true if at least on JMenuItem is visible