From ed6ebbd4abec0389f8af780c24c4f53200a21db5 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Fri, 13 Mar 2015 21:43:57 +0100 Subject: [PATCH] DroidFish: Fixed compiler warnings. --- CuckooChessEngine/src/chess/TreeLogger.java | 4 +++- CuckooChessEngine/src/guibase/ChessController.java | 3 +++ DroidFish/src/org/petero/droidfish/ChessBoard.java | 2 ++ .../petero/droidfish/activities/EditOptions.java | 2 ++ .../org/petero/droidfish/activities/EditPGN.java | 3 +++ .../org/petero/droidfish/activities/LoadFEN.java | 4 +--- .../petero/droidfish/engine/ExternalEngine.java | 14 ++++++++------ .../petero/droidfish/engine/InternalStockFish.java | 8 ++++---- .../droidfish/gamelogic/DroidChessController.java | 1 + 9 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CuckooChessEngine/src/chess/TreeLogger.java b/CuckooChessEngine/src/chess/TreeLogger.java index c36cb89..8e45a95 100644 --- a/CuckooChessEngine/src/chess/TreeLogger.java +++ b/CuckooChessEngine/src/chess/TreeLogger.java @@ -81,9 +81,9 @@ public final class TreeLogger { /** Get a logger object set up for analyzing a log file. */ public static final TreeLogger getAnalyzer(String filename) { + RandomAccessFile raf = null; try { TreeLogger log = new TreeLogger(); - RandomAccessFile raf; raf = new RandomAccessFile(filename, "rw"); log.fc = raf.getChannel(); long len = raf.length(); @@ -95,6 +95,8 @@ public final class TreeLogger { throw new RuntimeException(); } catch (IOException e) { throw new RuntimeException(); + } finally { + if (raf != null) try { raf.close(); } catch (IOException e) {} } } diff --git a/CuckooChessEngine/src/guibase/ChessController.java b/CuckooChessEngine/src/guibase/ChessController.java index 780afaa..65e165a 100644 --- a/CuckooChessEngine/src/guibase/ChessController.java +++ b/CuckooChessEngine/src/guibase/ChessController.java @@ -268,6 +268,7 @@ public class ChessController { } } pgn = out.toString(); + sc.close(); } // Parse tag section @@ -315,6 +316,7 @@ public class ChessController { } // Parse move text section + sc.close(); sc = new Scanner(pgn); sc.useDelimiter("\\s+"); while (sc.hasNext()) { @@ -326,6 +328,7 @@ public class ChessController { break; game.processString(strMove); } + sc.close(); } public void setFENOrPGN(String fenPgn) throws ChessParseError { diff --git a/DroidFish/src/org/petero/droidfish/ChessBoard.java b/DroidFish/src/org/petero/droidfish/ChessBoard.java index 4cadfb4..8f3d7e3 100644 --- a/DroidFish/src/org/petero/droidfish/ChessBoard.java +++ b/DroidFish/src/org/petero/droidfish/ChessBoard.java @@ -705,6 +705,8 @@ public abstract class ChessBoard extends View { else s = "0"; break; + case NONE: + break; } if (s != null) { Rect bounds = new Rect(); diff --git a/DroidFish/src/org/petero/droidfish/activities/EditOptions.java b/DroidFish/src/org/petero/droidfish/activities/EditOptions.java index 1df21ab..8c7e707 100644 --- a/DroidFish/src/org/petero/droidfish/activities/EditOptions.java +++ b/DroidFish/src/org/petero/droidfish/activities/EditOptions.java @@ -255,6 +255,8 @@ public class EditOptions extends Activity { modified = true; break; } + case BUTTON: + break; } } if (modified) diff --git a/DroidFish/src/org/petero/droidfish/activities/EditPGN.java b/DroidFish/src/org/petero/droidfish/activities/EditPGN.java index 29c51fd..1f653e3 100644 --- a/DroidFish/src/org/petero/droidfish/activities/EditPGN.java +++ b/DroidFish/src/org/petero/droidfish/activities/EditPGN.java @@ -432,6 +432,9 @@ public class EditPGN extends ListActivity { } }); break; + case CANCEL: + case OK: + break; } setResult(RESULT_CANCELED); finish(); diff --git a/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java b/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java index 693e807..4a88241 100644 --- a/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java +++ b/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java @@ -303,15 +303,13 @@ public class LoadFEN extends ListActivity { Pair> p = fenFile.getFenInfo(this, progress); if (p.first != FenInfoResult.OK) { fensInFile = new ArrayList(); - switch (p.first) { - case OUT_OF_MEMORY: + if (p.first == FenInfoResult.OUT_OF_MEMORY) { runOnUiThread(new Runnable() { public void run() { Toast.makeText(getApplicationContext(), R.string.file_too_large, Toast.LENGTH_SHORT).show(); } }); - break; } setResult(RESULT_CANCELED); finish(); diff --git a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java index 44800d0..be3ff57 100644 --- a/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java +++ b/DroidFish/src/org/petero/droidfish/engine/ExternalEngine.java @@ -288,17 +288,19 @@ public class ExternalEngine extends UCIEngineBase { if (to.exists()) to.delete(); to.createNewFile(); - FileChannel inFC = null; - FileChannel outFC = null; + FileInputStream fis = null; + FileOutputStream fos = null; try { - inFC = new FileInputStream(from).getChannel(); - outFC = new FileOutputStream(to).getChannel(); + fis = new FileInputStream(from); + FileChannel inFC = fis.getChannel(); + fos = new FileOutputStream(to); + FileChannel outFC = fos.getChannel(); long cnt = outFC.transferFrom(inFC, 0, inFC.size()); if (cnt < inFC.size()) throw new IOException("File copy failed"); } finally { - if (inFC != null) { try { inFC.close(); } catch (IOException ex) {} } - if (outFC != null) { try { outFC.close(); } catch (IOException ex) {} } + if (fis != null) { try { fis.close(); } catch (IOException ex) {} } + if (fos != null) { try { fos.close(); } catch (IOException ex) {} } to.setLastModified(from.lastModified()); } return to.getAbsolutePath(); diff --git a/DroidFish/src/org/petero/droidfish/engine/InternalStockFish.java b/DroidFish/src/org/petero/droidfish/engine/InternalStockFish.java index 869ecae..15a2e50 100644 --- a/DroidFish/src/org/petero/droidfish/engine/InternalStockFish.java +++ b/DroidFish/src/org/petero/droidfish/engine/InternalStockFish.java @@ -79,14 +79,14 @@ public class InternalStockFish extends ExternalEngine { } private final void writeCheckSum(File f, long checkSum) { - OutputStream os = null; + DataOutputStream dos = null; try { - os = new FileOutputStream(f); - DataOutputStream dos = new DataOutputStream(os); + OutputStream os = new FileOutputStream(f); + dos = new DataOutputStream(os); dos.writeLong(checkSum); } catch (IOException e) { } finally { - if (os != null) try { os.close(); } catch (IOException ex) {} + if (dos != null) try { dos.close(); } catch (IOException ex) {} } } diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java index 7ff8b06..ad89f9b 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java @@ -1089,6 +1089,7 @@ public class DroidChessController { case SEARCH: s.thinking = true; break; case PONDER: s.ponder = true; break; case ANALYZE: s.analyzing = true; break; + case NONE: break; } } else { if ((s.state == GameState.DRAW_REP) || (s.state == GameState.DRAW_50))