Skip to content

Commit 469a547

Browse files
author
GWA
committed
Bug fix: Saved Session groups management dialog: Fixed IllegalArgumentException when empty was deleted.
1 parent 82b8df3 commit 469a547

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

sql12/core/doc/changes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Table cell data popup now offers find, Xml/Json-reformatting and export function
6565

6666
Bug fixes:
6767

68+
Saved Session groups management dialog: Fixed IllegalArgumentException when empty was deleted.
69+
6870
Fixed StringIndexOutOfBoundsException when executed SQL contains the German Umlaut sz.
6971

7072
Change tracking, left gutter popup to show deleted changes:

sql12/core/src/net/sourceforge/squirrel_sql/client/session/action/savedsession/SavedSessionsManager.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package net.sourceforge.squirrel_sql.client.session.action.savedsession;
22

3+
import java.io.File;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.util.ArrayList;
7+
import java.util.HashSet;
8+
import java.util.List;
9+
import java.util.Optional;
10+
import java.util.Set;
11+
import java.util.concurrent.ExecutorService;
12+
import java.util.concurrent.Executors;
13+
import java.util.stream.Collectors;
14+
315
import net.sourceforge.squirrel_sql.client.Main;
416
import net.sourceforge.squirrel_sql.client.session.ISession;
517
import net.sourceforge.squirrel_sql.client.session.action.savedsession.savedsessionsgroup.SavedSessionGrouped;
@@ -16,17 +28,6 @@
1628
import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
1729
import org.apache.commons.lang3.StringUtils;
1830

19-
import java.io.File;
20-
import java.nio.file.Files;
21-
import java.nio.file.Path;
22-
import java.util.ArrayList;
23-
import java.util.HashSet;
24-
import java.util.List;
25-
import java.util.Set;
26-
import java.util.concurrent.ExecutorService;
27-
import java.util.concurrent.Executors;
28-
import java.util.stream.Collectors;
29-
3031
public class SavedSessionsManager
3132
{
3233
private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(SavedSessionsManager.class);
@@ -257,9 +258,24 @@ else if(null != group)
257258

258259
public SavedSessionGrouped getSavedSessionGrouped(String groupId)
259260
{
260-
return getSavedSessionsGrouped().stream()
261-
.filter(g -> null != g.getGroup() && StringUtils.equals(g.getGroup().getGroupId(), groupId))
262-
.findFirst().orElseThrow(() -> new IllegalArgumentException("Failed to find group by groupId=" + groupId));
261+
return getSavedSessionGrouped(groupId, true);
262+
}
263+
264+
public SavedSessionGrouped getSavedSessionGrouped(String groupId, boolean throwIfNotExisting)
265+
{
266+
Optional<SavedSessionGrouped> res =
267+
getSavedSessionsGrouped().stream().filter(g -> null != g.getGroup() && StringUtils.equals(g.getGroup().getGroupId(), groupId)).findFirst();
268+
269+
if(res.isEmpty())
270+
{
271+
if(throwIfNotExisting)
272+
{
273+
throw new IllegalArgumentException("Failed to find group by groupId=" + groupId);
274+
}
275+
return null;
276+
}
277+
278+
return res.get();
263279
}
264280

265281
public SavedSessionGrouped getSavedSessionGrouped(SavedSessionJsonBean savedSession)

sql12/core/src/net/sourceforge/squirrel_sql/client/session/action/savedsession/savedsessionsgroup/SavedSessionsGroupCtrl.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package net.sourceforge.squirrel_sql.client.session.action.savedsession.savedsessionsgroup;
22

3+
import java.awt.event.InputEvent;
4+
import java.awt.event.KeyAdapter;
5+
import java.awt.event.KeyEvent;
6+
import java.util.Collections;
7+
import java.util.List;
8+
import java.util.Objects;
9+
import java.util.Optional;
10+
import java.util.stream.Collectors;
11+
import javax.swing.JOptionPane;
12+
import javax.swing.SwingUtilities;
13+
import javax.swing.event.DocumentEvent;
14+
import javax.swing.event.DocumentListener;
15+
316
import net.sourceforge.squirrel_sql.client.Main;
417
import net.sourceforge.squirrel_sql.client.session.ISession;
518
import net.sourceforge.squirrel_sql.client.session.action.savedsession.SaveSessionResult;
@@ -12,18 +25,6 @@
1225
import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
1326
import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
1427

15-
import javax.swing.*;
16-
import javax.swing.event.DocumentEvent;
17-
import javax.swing.event.DocumentListener;
18-
import java.awt.event.InputEvent;
19-
import java.awt.event.KeyAdapter;
20-
import java.awt.event.KeyEvent;
21-
import java.util.Collections;
22-
import java.util.List;
23-
import java.util.Objects;
24-
import java.util.Optional;
25-
import java.util.stream.Collectors;
26-
2728
public class SavedSessionsGroupCtrl
2829
{
2930
private static final StringManager s_stringMgr = StringManagerFactory.getStringManager(SavedSessionsGroupCtrl.class);
@@ -229,8 +230,11 @@ private void onDelete()
229230

230231
if(null != _groupBeingEdited)
231232
{
232-
SavedSessionGrouped groupBeingEdited = Main.getApplication().getSavedSessionsManager().getSavedSessionGrouped(_groupBeingEdited.getGroupId());
233-
Main.getApplication().getSavedSessionsManager().delete(List.of(groupBeingEdited));
233+
SavedSessionGrouped groupBeingEdited = Main.getApplication().getSavedSessionsManager().getSavedSessionGrouped(_groupBeingEdited.getGroupId(), false);
234+
if( null != groupBeingEdited )
235+
{
236+
Main.getApplication().getSavedSessionsManager().delete(List.of(groupBeingEdited));
237+
}
234238
}
235239

236240
String groupNameForMessagePanel = null != _groupBeingEdited ? _groupBeingEdited.getGroupName() : _dlg.txtGroupName.getText();

0 commit comments

Comments
 (0)