StringBuilder in a class field may cause memory leaks, it's not GCed, so it's a better way to store all errors just in string field

This commit is contained in:
vraskulin 2017-02-28 11:37:31 +03:00
parent eb58391fe2
commit 3600d03e2c

View file

@ -40,7 +40,8 @@ import org.apache.log4j.Logger;
public abstract class DeckImporter { public abstract class DeckImporter {
private static final Logger logger = Logger.getLogger(DeckImporter.class); private static final Logger logger = Logger.getLogger(DeckImporter.class);
protected StringBuilder sbMessage = new StringBuilder();
protected String errors;
protected int lineCount; protected int lineCount;
public DeckCardLists importDeck(String file) { public DeckCardLists importDeck(String file) {
@ -51,6 +52,7 @@ public abstract class DeckImporter {
return deckList; return deckList;
} }
lineCount = 0; lineCount = 0;
StringBuilder sbMessage = new StringBuilder();
sbMessage.setLength(0); sbMessage.setLength(0);
try { try {
try (Scanner scanner = new Scanner(f)) { try (Scanner scanner = new Scanner(f)) {
@ -68,11 +70,12 @@ public abstract class DeckImporter {
} catch (Exception ex) { } catch (Exception ex) {
logger.fatal(null, ex); logger.fatal(null, ex);
} }
errors = sbMessage.toString();
return deckList; return deckList;
} }
public String getErrors(){ public String getErrors(){
return sbMessage.toString(); return errors;
} }
protected abstract void readLine(String line, DeckCardLists deckList); protected abstract void readLine(String line, DeckCardLists deckList);