Merge lp:~tapaal-contributor/tapaal/open-incorrectly-formatted-file into lp:tapaal

Proposed by Lena Ernstsen
Status: Merged
Approved by: Jiri Srba
Approved revision: 1141
Merged at revision: 1148
Proposed branch: lp:~tapaal-contributor/tapaal/open-incorrectly-formatted-file
Merge into: lp:tapaal
Diff against target: 157 lines (+37/-15)
4 files modified
src/dk/aau/cs/gui/TabContent.java (+8/-2)
src/dk/aau/cs/io/TapnXmlLoader.java (+21/-9)
src/pipe/dataLayer/DataLayer.java (+2/-2)
src/pipe/gui/GuiFrameController.java (+6/-2)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/open-incorrectly-formatted-file
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+409350@code.launchpad.net

This proposal supersedes a proposal from 2021-08-18.

Commit message

Incorrectly formatted file will throw an exception when opened

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote : Posted in a previous version of this proposal

It shows the message now but still throws the expection and does not display where ithe problem

review: Needs Fixing
1141. By Lena Ernstsen

Removed print to terminal when exception occurs

Revision history for this message
Jiri Srba (srba) wrote :

Tested and works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/gui/TabContent.java'
2--- src/dk/aau/cs/gui/TabContent.java 2021-08-08 17:15:45 +0000
3+++ src/dk/aau/cs/gui/TabContent.java 2021-09-30 14:12:43 +0000
4@@ -14,6 +14,7 @@
5 import javax.swing.border.BevelBorder;
6
7 import dk.aau.cs.TCTL.*;
8+import dk.aau.cs.TCTL.Parsing.ParseException;
9 import dk.aau.cs.debug.Logger;
10 import dk.aau.cs.gui.components.BugHandledJXMultisplitPane;
11 import dk.aau.cs.gui.components.NameVisibilityPanel;
12@@ -589,6 +590,10 @@
13 ModelLoader loader = new ModelLoader();
14 LoadedModel loadedModel = loader.load(file);
15
16+ if (loadedModel == null) {
17+ throw new Exception("Could not open the selected file, as it does not have the correct format.");
18+ }
19+
20 if (loadedModel.getMessages().size() != 0) {
21 new Thread(new Runnable() {
22 @Override
23@@ -615,8 +620,9 @@
24 tab.setFile(null);
25
26 return tab;
27- } catch (Exception e) {
28- //throw new Exception("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.toString());
29+ } catch (ParseException e) {
30+ throw new ParseException("TAPAAL encountered an error while loading the file: " + name + "\n\nPossible explanations:\n - " + e.getMessage());
31+ } catch (Exception e) {
32 throw e;
33 }
34
35
36=== modified file 'src/dk/aau/cs/io/TapnXmlLoader.java'
37--- src/dk/aau/cs/io/TapnXmlLoader.java 2020-10-09 07:59:49 +0000
38+++ src/dk/aau/cs/io/TapnXmlLoader.java 2021-09-30 14:12:43 +0000
39@@ -78,20 +78,32 @@
40
41 }
42
43- public LoadedModel load(InputStream file) throws FormatException {
44+ public LoadedModel load(InputStream file) throws Exception {
45 Require.that(file != null, "file must be non-null and exist");
46
47 Document doc = loadDocument(file);
48 if(doc == null) return null;
49- return parse(doc);
50+ try {
51+ return parse(doc);
52+ } catch (FormatException | NullPointerException e) {
53+ throw e;
54+ } catch (Exception e) {
55+ throw new Exception("One or more necessary attributes were not found\n - One or more attribute values have an incorrect type");
56+ }
57 }
58
59- public LoadedModel load(File file) throws FormatException {
60+ public LoadedModel load(File file) throws Exception {
61 Require.that(file != null && file.exists(), "file must be non-null and exist");
62
63 Document doc = loadDocument(file);
64 if(doc == null) return null;
65- return parse(doc);
66+ try {
67+ return parse(doc);
68+ } catch (FormatException | NullPointerException e) {
69+ throw e;
70+ } catch (Exception e) {
71+ throw new Exception("One or more necessary attributes were not found\n - One or more attribute values have an incorrect type");
72+ }
73 }
74
75
76@@ -427,7 +439,7 @@
77 int initialMarkingInput = Integer.parseInt(place.getAttribute("initialMarking"));
78 String invariant = place.getAttribute("invariant");
79 boolean displayName = place.getAttribute("displayName").equals("false") ? false : true;
80-
81+
82
83 if (idInput.length() == 0 && nameInput.length() > 0) {
84 idInput = nameInput;
85@@ -436,7 +448,7 @@
86 if (nameInput.length() == 0 && idInput.length() > 0) {
87 nameInput = idInput;
88 }
89-
90+
91 if(nameInput.toLowerCase().equals("true") || nameInput.toLowerCase().equals("false")) {
92 nameInput = "_" + nameInput;
93 if(firstPlaceRenameWarning) {
94@@ -444,7 +456,7 @@
95 firstPlaceRenameWarning = false;
96 }
97 }
98-
99+
100 idResolver.add(tapn.name(), idInput, nameInput);
101
102 TimedPlace p;
103@@ -461,7 +473,7 @@
104 nameGenerator.updateIndicesForAllModels(nameInput);
105 TimedPlaceComponent placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameOffsetXInput, nameOffsetYInput, lens);
106 placeComponent.setUnderlyingPlace(p);
107-
108+
109 if (!displayName){
110 placeComponent.setAttributesVisible(false);
111 }
112@@ -500,7 +512,7 @@
113
114 int _endx = targetIn.getX() + targetIn.centreOffsetLeft();
115 int _endy = targetIn.getY() + targetIn.centreOffsetTop();
116-
117+
118 //Get weight if any
119 Weight weight = new IntWeight(1);
120 if(arc.hasAttribute("weight")){
121
122=== modified file 'src/pipe/dataLayer/DataLayer.java'
123--- src/pipe/dataLayer/DataLayer.java 2020-06-19 11:34:53 +0000
124+++ src/pipe/dataLayer/DataLayer.java 2021-09-30 14:12:43 +0000
125@@ -792,8 +792,8 @@
126 }
127 }
128
129- return null;
130- }
131+ throw new NullPointerException("One or more arcs are connected to a place/transition, which can not be found in the net");
132+ }
133
134 public void redrawVisibleTokenLists() {
135 for (Place place : placesArray) {
136
137=== modified file 'src/pipe/gui/GuiFrameController.java'
138--- src/pipe/gui/GuiFrameController.java 2021-07-23 21:16:09 +0000
139+++ src/pipe/gui/GuiFrameController.java 2021-09-30 14:12:43 +0000
140@@ -305,11 +305,15 @@
141 List<TabContent> tabs = get();
142 openTab(tabs);
143 } catch (Exception e) {
144+ String message = e.getMessage();
145+
146+ if (message.contains("Exception:")) {
147+ message = message.split(":", 2)[1];
148+ }
149 JOptionPane.showMessageDialog(CreateGui.getApp(),
150- e.getMessage(),
151+ message,
152 "Error loading file",
153 JOptionPane.ERROR_MESSAGE);
154- e.printStackTrace();
155 return;
156 }finally {
157 CreateGui.getAppGui().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

Subscribers

People subscribed via source and target branches