diff --git a/src/sqlancer/Main.java b/src/sqlancer/Main.java index 7df750bf1..ff7415d1e 100644 --- a/src/sqlancer/Main.java +++ b/src/sqlancer/Main.java @@ -167,7 +167,7 @@ private FileWriter getLogFileWriter() { public FileWriter getCurrentFileWriter() { if (!logEachSelect) { - throw new UnsupportedOperationException(); + return null; // Instead of throwing an exception } if (currentFileWriter == null) { try { @@ -177,7 +177,7 @@ public FileWriter getCurrentFileWriter() { } } return currentFileWriter; - } + } public FileWriter getQueryPlanFileWriter() { if (!logQueryPlan) { @@ -209,16 +209,18 @@ public FileWriter getReduceFileWriter() { public void writeCurrent(StateToReproduce state) { if (!logEachSelect) { - throw new UnsupportedOperationException(); + return; // Skip logging if logEachSelect is false } - printState(getCurrentFileWriter(), state); - try { - currentFileWriter.flush(); - - } catch (IOException e) { - e.printStackTrace(); + FileWriter writer = getCurrentFileWriter(); + if (writer != null) { + printState(writer, state); + try { + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + } } - } + } public void writeCurrent(String input) { write(databaseProvider.getLoggableFactory().createLoggable(input)); @@ -230,16 +232,18 @@ public void writeCurrentNoLineBreak(String input) { private void write(Loggable loggable) { if (!logEachSelect) { - throw new UnsupportedOperationException(); + return; // Skip writing if logging is disabled } - try { - getCurrentFileWriter().write(loggable.getLogString()); - - currentFileWriter.flush(); - } catch (IOException e) { - throw new AssertionError(); + FileWriter writer = getCurrentFileWriter(); + if (writer != null) { + try { + writer.write(loggable.getLogString()); + writer.flush(); + } catch (IOException e) { + throw new AssertionError(e); + } } - } + } public void writeQueryPlan(String queryPlan) { if (!logQueryPlan) { @@ -795,4 +799,4 @@ public void run() { }, 5, 5, TimeUnit.SECONDS); } -} +} \ No newline at end of file