Findbugs and working with gradlew run

This commit is contained in:
Bruce Eckel 2017-05-01 17:43:21 -06:00
parent 4f795333a6
commit bb8b445649
18 changed files with 27 additions and 22 deletions

View File

@ -28,7 +28,8 @@ public class AtUnitExample2 {
}
@Test
void exceptionExample() throws IOException {
new FileInputStream("nofile.txt"); // Throws
try(FileInputStream fis =
new FileInputStream("nofile.txt")) {} // Throws
}
@Test
boolean assertAndReturn() {

View File

@ -14,7 +14,7 @@ public class UseCaseTracker {
if(uc != null) {
System.out.println("Found Use Case " +
uc.id() + "\n " + uc.description());
useCases.remove(new Integer(uc.id()));
useCases.remove(Integer.valueOf(uc.id()));
}
}
useCases.forEach(i ->

View File

@ -14,7 +14,7 @@ class Bob {
public class SimpleSetAll {
public static final int SZ = 8;
public static int val = 1;
static int val = 1;
static char[] chars = "abcdefghijklmnopqrstuvwxyz"
.toCharArray();
static char getChar(int n) { return chars[n]; }

View File

@ -8,7 +8,7 @@ import typeinfo.pets.*;
import java.util.*;
public class MapOfList {
public static Map<Person, List< ? extends Pet>>
public static final Map<Person, List< ? extends Pet>>
petPeople = new HashMap<>();
static {
petPeople.put(new Person("Dawn"),

View File

@ -39,7 +39,7 @@ public class CanonicalMapping {
int size = 1000;
// Or, choose size via the command line:
if(args.length > 0)
size = new Integer(args[0]);
size = Integer.valueOf(args[0]);
Key[] keys = new Key[size];
WeakHashMap<Key,Value> map =
new WeakHashMap<>();

View File

@ -31,7 +31,7 @@ public class References {
int size = 10;
// Or, choose size via the command line:
if(args.length > 0)
size = new Integer(args[0]);
size = Integer.valueOf(args[0]);
LinkedList<SoftReference<VeryBig>> sa =
new LinkedList<>();
for(int i = 0; i < size; i++) {

View File

@ -9,7 +9,7 @@ public class CompletableOperations {
static CompletableFuture<Integer> cfi(int i) {
return
CompletableFuture.completedFuture(
new Integer(i));
Integer.valueOf(i));
}
public static void main(String[] args) {
showr(cfi(1)); // Basic test

View File

@ -9,7 +9,7 @@ public class CountingTask implements Callable<Integer> {
public CountingTask(int id) { this.id = id; }
@Override
public Integer call() {
Integer val = new Integer(0);
Integer val = 0;
for(int i = 0; i < 100; i++)
val++;
System.out.println(id + " " +

View File

@ -3,6 +3,7 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Hidden deadlock
// {ValidateByHand} Gradle has trouble
import java.util.*;
import java.util.concurrent.*;
import onjava.Nap;

View File

@ -5,7 +5,7 @@
public class InterferingTask implements Runnable {
final int id;
private static Integer val = new Integer(0);
private static Integer val = 0;
public InterferingTask(int id) { this.id = id; }
@Override
public void run() {

View File

@ -10,7 +10,7 @@ import java.util.concurrent.atomic.*;
import java.nio.file.*;
public class ParallelStreamPuzzle2 {
public static Deque<String> trace =
public static final Deque<String> trace =
new ConcurrentLinkedDeque<>();
static class
IntGenerator implements Supplier<Integer> {

View File

@ -46,7 +46,7 @@ public class Equality {
neq = eqf.make(99, "Bob", 1.618);
e.test("null", "false", null);
e.test("same object", "true", e);
e.test("different type", "false", new Integer(99));
e.test("different type", "false", Integer.valueOf(99));
e.test("same values", "true", eq);
e.test("different values", "false", neq);
}

View File

@ -7,7 +7,7 @@ import java.util.function.*;
public class Closure7 {
IntSupplier makeFun(int x) {
Integer i = new Integer(0);
Integer i = Integer.valueOf(0);
i = i + 1;
return () -> x + i;
}

View File

@ -24,7 +24,7 @@ public class GreenhouseController {
if(args.length == 1)
gc.addEvent(
new GreenhouseControls.Terminate(
new Integer(args[0])));
Integer.valueOf(args[0])));
gc.run();
}
}

View File

@ -5,8 +5,8 @@
public class EqualsMethod {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
Integer n1 = 47;
Integer n2 = 47;
System.out.println(n1.equals(n2));
}
}

View File

@ -5,8 +5,8 @@
public class Equivalence {
public static void main(String[] args) {
Integer n1 = new Integer(47);
Integer n2 = new Integer(47);
Integer n1 = 47;
Integer n2 = 47;
System.out.println(n1 == n2);
System.out.println(n1 != n2);
}

View File

@ -6,7 +6,7 @@
import java.io.*;
class Blip1 implements Externalizable {
Blip1() {
public Blip1() {
System.out.println("Blip1 Constructor");
}
@Override

View File

@ -8,9 +8,12 @@ import java.io.*;
public class FreezeAlien {
public static void
main(String[] args) throws Exception {
ObjectOutput out = new ObjectOutputStream(
new FileOutputStream("X.file"));
Alien quellek = new Alien();
out.writeObject(quellek);
try(
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("X.file"));
) {
Alien quellek = new Alien();
out.writeObject(quellek);
}
}
}