Skip to content

Commit 16ddc99

Browse files
committed
PrismLog usage bug fixes.
For example, this was crashing: prism % prism dice.pm -simpath 10 stdout
1 parent 90b45e3 commit 16ddc99

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

prism/src/simulator/GenerateSimulationPath.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import prism.PrismException;
3636
import prism.PrismFileLog;
3737
import prism.PrismLog;
38+
import prism.PrismLogWrapper;
3839
import userinterface.graph.Graph;
3940

4041
/**
@@ -344,7 +345,7 @@ private PathDisplayer generateDisplayerForExport() throws PrismException
344345
if (file != null) {
345346
log = new PrismFileLog(file.getPath());
346347
} else {
347-
log = mainLog;
348+
log = new PrismLogWrapper(mainLog);
348349
}
349350
displayer = new PathToText(log, engine.getModel(), engine.getRewardGenerator());
350351
displayer.setColSep(simPathSep);

prism/src/simulator/PathToText.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public class PathToText extends PathDisplayer
6363
private boolean changed;
6464

6565
/**
66-
* Construct a {@link PathToText} object
66+
* Construct a {@link PathToText} object, which writes to a {@link PrismLog}.
67+
* The log will be {@code close()}d when {@link #close()} is called.
6768
* @param log Log to output path to
6869
* @param modelInfo Model associated with path
6970
* @param rewardGen Rewards associated with path

prism/src/simulator/SimulatorEngine.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,24 +1678,12 @@ public void exportPath(File file, boolean timeCumul, String colSep, ArrayList<In
16781678
*/
16791679
public void exportPath(File file, boolean timeCumul, boolean showRewards, String colSep, ArrayList<Integer> vars) throws PrismException
16801680
{
1681-
PrismLog log = null;
1682-
try {
1683-
if (path == null)
1684-
throw new PrismException("There is no path to export");
1685-
// create new file log or use main log
1686-
if (file != null) {
1687-
log = new PrismFileLog(file.getPath());
1688-
mainLog.println("\nExporting path to file \"" + file + "\"...");
1689-
} else {
1690-
log = mainLog;
1691-
log.println();
1692-
}
1681+
if (path == null) {
1682+
throw new PrismException("There is no path to export");
1683+
}
1684+
try (PrismLog log = getPrismLogForFile(file)) {
1685+
mainLog.println("\nExporting path " + getDestinationStringForFile(file));
16931686
((PathFull) path).exportToLog(log, timeCumul, showRewards, colSep, vars);
1694-
if (file != null)
1695-
log.close();
1696-
} finally {
1697-
if (file != null && log != null)
1698-
log.close();
16991687
}
17001688
}
17011689

0 commit comments

Comments
 (0)