From 413ad6b0e64f986a830a2b31edcccf7d33aafe1b Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Wed, 20 Nov 2013 09:56:57 +0000 Subject: [PATCH] BOB findbugs --- apps/BOB/src/net/i2p/BOB/BOB.java | 2 +- apps/BOB/src/net/i2p/BOB/DoCMDS.java | 4 ++-- apps/BOB/src/net/i2p/BOB/MUXlisten.java | 4 ++-- apps/BOB/src/net/i2p/BOB/NamedDB.java | 20 ++++++++++++-------- apps/BOB/src/net/i2p/BOB/TCPio.java | 1 - apps/BOB/src/net/i2p/BOB/TCPtoI2P.java | 8 +++----- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/apps/BOB/src/net/i2p/BOB/BOB.java b/apps/BOB/src/net/i2p/BOB/BOB.java index 517146dac1..409d516743 100644 --- a/apps/BOB/src/net/i2p/BOB/BOB.java +++ b/apps/BOB/src/net/i2p/BOB/BOB.java @@ -308,7 +308,7 @@ public class BOB { database.releaseReadLock(); database.getWriteLock(); nickinfo.getWriteLock(); - nickinfo.add(P_STOPPING, new Boolean(true)); + nickinfo.add(P_STOPPING, Boolean.valueOf(true)); nickinfo.releaseWriteLock(); database.releaseWriteLock(); } else { diff --git a/apps/BOB/src/net/i2p/BOB/DoCMDS.java b/apps/BOB/src/net/i2p/BOB/DoCMDS.java index a4708f009c..ea4c88ae4b 100644 --- a/apps/BOB/src/net/i2p/BOB/DoCMDS.java +++ b/apps/BOB/src/net/i2p/BOB/DoCMDS.java @@ -665,7 +665,7 @@ public class DoCMDS implements Runnable { break die; } try { - nickinfo.add(P_QUIET, new Boolean(Boolean.parseBoolean(Arg) == true)); + nickinfo.add(P_QUIET, Boolean.valueOf(Arg)); } catch (Exception ex) { try { wunlock(); @@ -989,7 +989,7 @@ public class DoCMDS implements Runnable { prt = Integer.parseInt(Arg); if (prt > 1 && prt < 65536) { try { - nickinfo.add(P_INPORT, new Integer(prt)); + nickinfo.add(P_INPORT, Integer.valueOf(prt)); } catch (Exception ex) { try { wunlock(); diff --git a/apps/BOB/src/net/i2p/BOB/MUXlisten.java b/apps/BOB/src/net/i2p/BOB/MUXlisten.java index faaf2899a9..e9f492eaf5 100644 --- a/apps/BOB/src/net/i2p/BOB/MUXlisten.java +++ b/apps/BOB/src/net/i2p/BOB/MUXlisten.java @@ -70,7 +70,7 @@ public class MUXlisten implements Runnable { this.database.getWriteLock(); this.info.getWriteLock(); - this.info.add("STARTING", new Boolean(true)); + this.info.add("STARTING", Boolean.valueOf(true)); this.info.releaseWriteLock(); this.database.releaseWriteLock(); this.database.getReadLock(); @@ -160,7 +160,7 @@ public class MUXlisten implements Runnable { try { wlock(); try { - info.add("RUNNING", new Boolean(true)); + info.add("RUNNING", Boolean.valueOf(true)); } catch (Exception e) { lock.set(false); wunlock(); diff --git a/apps/BOB/src/net/i2p/BOB/NamedDB.java b/apps/BOB/src/net/i2p/BOB/NamedDB.java index 46796136dd..b3c0741f57 100644 --- a/apps/BOB/src/net/i2p/BOB/NamedDB.java +++ b/apps/BOB/src/net/i2p/BOB/NamedDB.java @@ -15,6 +15,8 @@ */ package net.i2p.BOB; +import java.util.concurrent.atomic.AtomicInteger; + /** * Internal database to relate nicknames to options to values * @@ -23,7 +25,9 @@ package net.i2p.BOB; public class NamedDB { private volatile Object[][] data; - private volatile int index, writersWaiting, readers; + private volatile int index; + private final AtomicInteger writersWaiting = new AtomicInteger(); + private final AtomicInteger readers = new AtomicInteger(); /** * make initial NULL object @@ -31,27 +35,27 @@ public class NamedDB { */ public NamedDB() { this.data = new Object[1][2]; - this.index = this.writersWaiting = this.readers = 0; + this.index = 0; } synchronized public void getReadLock() { - while ((writersWaiting != 0)) { + while ((writersWaiting.get() != 0)) { try { wait(); } catch (InterruptedException ie) { } } - readers++; + readers.incrementAndGet(); } synchronized public void releaseReadLock() { - readers--; + readers.decrementAndGet(); notifyAll(); } synchronized public void getWriteLock() { - writersWaiting++; - while (readers != 0 && writersWaiting != 1) { + writersWaiting.incrementAndGet(); + while (readers.get() != 0 && writersWaiting.get() != 1) { try { wait(); } catch (InterruptedException ie) { @@ -60,7 +64,7 @@ public class NamedDB { } synchronized public void releaseWriteLock() { - writersWaiting--; + writersWaiting.decrementAndGet(); notifyAll(); } diff --git a/apps/BOB/src/net/i2p/BOB/TCPio.java b/apps/BOB/src/net/i2p/BOB/TCPio.java index e684d53278..f54cb574e7 100644 --- a/apps/BOB/src/net/i2p/BOB/TCPio.java +++ b/apps/BOB/src/net/i2p/BOB/TCPio.java @@ -116,7 +116,6 @@ public class TCPio implements Runnable { Aout.close(); } catch (IOException ex) { } - return; } } } diff --git a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java index d83c061a00..2cfda2f56b 100644 --- a/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java +++ b/apps/BOB/src/net/i2p/BOB/TCPtoI2P.java @@ -70,12 +70,10 @@ public class TCPtoI2P implements Runnable { * @throws IOException */ private static String lnRead(InputStream in) throws IOException { - String S; + String S = ""; int b; char c; - S = new String(); - while (true) { b = in.read(); if (b == 13) { @@ -87,7 +85,7 @@ public class TCPtoI2P implements Runnable { break; } c = (char) (b & 0x7f); // We only care about ASCII - S = new String(S + c); + S = S + c; } return S; } @@ -101,7 +99,7 @@ public class TCPtoI2P implements Runnable { */ private void Emsg(String e, OutputStream out) throws IOException { // Debugging System.out.println("ERROR TCPtoI2P: " + e); - out.write("ERROR ".concat(e).getBytes()); + out.write("ERROR ".concat(e).getBytes("UTF-8")); out.write(13); out.write(10); out.flush(); -- GitLab