BOB findbugs

This commit is contained in:
str4d
2013-11-20 09:56:57 +00:00
parent a7a7e96188
commit 413ad6b0e6
6 changed files with 20 additions and 19 deletions

View File

@@ -308,7 +308,7 @@ public class BOB {
database.releaseReadLock(); database.releaseReadLock();
database.getWriteLock(); database.getWriteLock();
nickinfo.getWriteLock(); nickinfo.getWriteLock();
nickinfo.add(P_STOPPING, new Boolean(true)); nickinfo.add(P_STOPPING, Boolean.valueOf(true));
nickinfo.releaseWriteLock(); nickinfo.releaseWriteLock();
database.releaseWriteLock(); database.releaseWriteLock();
} else { } else {

View File

@@ -665,7 +665,7 @@ public class DoCMDS implements Runnable {
break die; break die;
} }
try { try {
nickinfo.add(P_QUIET, new Boolean(Boolean.parseBoolean(Arg) == true)); nickinfo.add(P_QUIET, Boolean.valueOf(Arg));
} catch (Exception ex) { } catch (Exception ex) {
try { try {
wunlock(); wunlock();
@@ -989,7 +989,7 @@ public class DoCMDS implements Runnable {
prt = Integer.parseInt(Arg); prt = Integer.parseInt(Arg);
if (prt > 1 && prt < 65536) { if (prt > 1 && prt < 65536) {
try { try {
nickinfo.add(P_INPORT, new Integer(prt)); nickinfo.add(P_INPORT, Integer.valueOf(prt));
} catch (Exception ex) { } catch (Exception ex) {
try { try {
wunlock(); wunlock();

View File

@@ -70,7 +70,7 @@ public class MUXlisten implements Runnable {
this.database.getWriteLock(); this.database.getWriteLock();
this.info.getWriteLock(); this.info.getWriteLock();
this.info.add("STARTING", new Boolean(true)); this.info.add("STARTING", Boolean.valueOf(true));
this.info.releaseWriteLock(); this.info.releaseWriteLock();
this.database.releaseWriteLock(); this.database.releaseWriteLock();
this.database.getReadLock(); this.database.getReadLock();
@@ -160,7 +160,7 @@ public class MUXlisten implements Runnable {
try { try {
wlock(); wlock();
try { try {
info.add("RUNNING", new Boolean(true)); info.add("RUNNING", Boolean.valueOf(true));
} catch (Exception e) { } catch (Exception e) {
lock.set(false); lock.set(false);
wunlock(); wunlock();

View File

@@ -15,6 +15,8 @@
*/ */
package net.i2p.BOB; package net.i2p.BOB;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Internal database to relate nicknames to options to values * Internal database to relate nicknames to options to values
* *
@@ -23,7 +25,9 @@ package net.i2p.BOB;
public class NamedDB { public class NamedDB {
private volatile Object[][] data; 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 * make initial NULL object
@@ -31,27 +35,27 @@ public class NamedDB {
*/ */
public NamedDB() { public NamedDB() {
this.data = new Object[1][2]; this.data = new Object[1][2];
this.index = this.writersWaiting = this.readers = 0; this.index = 0;
} }
synchronized public void getReadLock() { synchronized public void getReadLock() {
while ((writersWaiting != 0)) { while ((writersWaiting.get() != 0)) {
try { try {
wait(); wait();
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
} }
} }
readers++; readers.incrementAndGet();
} }
synchronized public void releaseReadLock() { synchronized public void releaseReadLock() {
readers--; readers.decrementAndGet();
notifyAll(); notifyAll();
} }
synchronized public void getWriteLock() { synchronized public void getWriteLock() {
writersWaiting++; writersWaiting.incrementAndGet();
while (readers != 0 && writersWaiting != 1) { while (readers.get() != 0 && writersWaiting.get() != 1) {
try { try {
wait(); wait();
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
@@ -60,7 +64,7 @@ public class NamedDB {
} }
synchronized public void releaseWriteLock() { synchronized public void releaseWriteLock() {
writersWaiting--; writersWaiting.decrementAndGet();
notifyAll(); notifyAll();
} }

View File

@@ -116,7 +116,6 @@ public class TCPio implements Runnable {
Aout.close(); Aout.close();
} catch (IOException ex) { } catch (IOException ex) {
} }
return;
} }
} }
} }

View File

@@ -70,12 +70,10 @@ public class TCPtoI2P implements Runnable {
* @throws IOException * @throws IOException
*/ */
private static String lnRead(InputStream in) throws IOException { private static String lnRead(InputStream in) throws IOException {
String S; String S = "";
int b; int b;
char c; char c;
S = new String();
while (true) { while (true) {
b = in.read(); b = in.read();
if (b == 13) { if (b == 13) {
@@ -87,7 +85,7 @@ public class TCPtoI2P implements Runnable {
break; break;
} }
c = (char) (b & 0x7f); // We only care about ASCII c = (char) (b & 0x7f); // We only care about ASCII
S = new String(S + c); S = S + c;
} }
return S; return S;
} }
@@ -101,7 +99,7 @@ public class TCPtoI2P implements Runnable {
*/ */
private void Emsg(String e, OutputStream out) throws IOException { private void Emsg(String e, OutputStream out) throws IOException {
// Debugging System.out.println("ERROR TCPtoI2P: " + e); // 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(13);
out.write(10); out.write(10);
out.flush(); out.flush();