ERRATA
Effective Java Programming Language Guide
by Joshua Bloch
Foreword by Guy Steele


 

This page contains the errata - those things that are wrong or lead you astray in the first edition of the book. The parenthesized number on the first line of each entry on this page represents the printing in which the erratum was fixed.

If you find an error in the book, please check to see if it is already known before reporting it. If you do not find it in the list, please mail me the relevant information, including page numbers. All errata will be fixed in the next possible printing.


Page xv: Acknowledgements (2)
The list of reviewers contains an omission:
I am extremely grateful to David Holmes for all of his contributions and deeply sorry for this omission.

Page 3: Introduction (5)
The sentence "The examples have been tested on releases 1.3." should be:
The examples have been tested on release 1.3.

Pages 10, 15, 75, 86, 92, 115, 127: (Various items) (2)
The reference to Design Patterns by Gamma, Helm, Johnson and Vlissides has the wrong year. Instead of [Gamma98], it should be:
[Gamma95]

Page 15: Item 4, Creating and destroying objects (5)
The first sentence of the third paragraph is imprecise. The word "immutable" shold be replaced by the phrase:
not modified after initialization

Page 16: Item 4, Creating and destroying objects (4)
The reference to Item 32 should be a reference to Item 24. It should read:
The present item says: "Don't create a new object when you should reuse an existing one," while Item 24 says: "Don't reuse an existing object when you should create a new one."

Page 19: Item 5, Eliminate obsolete object references (5)
When discussing the code example on page 17, the phrase "the items array" occurs twice. The array name in the prose does not match the one in the code. The phrase should be:
the elements array

Page 23: Item 6, Avoid Finalizers (4)
The sentence that ends "the finalizer guardian becomes eligible for finalization immediately prior to the enclosing instance" should end:
the finalizer guardian becomes eligible for finalization at the same time as the enclosing instance.

Page 28: Item 7, Obey the general contract when overriding equals (4)
The sentence that begins "Let's suppose that we have one case-sensitive string" should begin:
Let's suppose that we have one case-insensitive string

Page 31: Item 7, Obey the general contract when overriding equals (4)
In the sentence that begins, "The TimeStamp class is an anomaly," TimeStamp should be:
Timestamp

Page 43: Item 9: Always override toString (4)
The comment for the toString method exchanges the terms extension and exchange. It should read:
* The string consists of fourteen characters whose format
* is "(XXX) YYY-ZZZZ", where XXX is the area code, YYY is
* the exchange, and ZZZZ is the extension
...
* For example, if the value of the extension is 123, the last
* four characters of the string representation will be "0123".

Page 44: Item 9, Always override toString (5)
The last precondition in the comment of the toPaddedString method at the top of the page is incorrect. "Integer.toString(i) <= length" should be:
Integer.toString(i).length() <= length

Page 46: Item 10: Override clone judiciously (5)
The fifth line of the fourth paragraph is missing a period. The portion that reads, "of the original object The fields" should read:
of the original object. The fields

Page 47: Item 10, Override clone judiciously (4)
In the sentence, "You will quickly find that your program produces nonsensical results or throws ArrayIndexOutOfBounds." ArrayIndexOutOfBounds should be NullPointerException:
You will quickly find that your program produces nonsensical results or throws a NullPointerException.

Page 48: Item 10, Override clone judiciously (2)
The sentence that begins, "Note that this solution would not work if the buckets field were final" should begin:
Note that this solution would not work if the elements field were final

Page 49: Item 10, Override clone Judiciously (5)
The if statement in the corrected clone method contains an unnecessary (though harmless) cast. It should read:
if (buckets[i] != null)
    result.buckets[i] = buckets[i].deepCopy();

Page 55: Item 11, Consider implementing Comparable (2)
The sentence that begins "For example, consider the Float class" should begin:
For example, consider the BigDecimal class
All occurrences of Float in this paragraph should be:
BigDecimal
The instance creation expression new Float(-0.0f) should be:
new BigDecimal("1.0")
The instance creation expression new Float(0.0f) should be:
new BigDecimal("1.00")

Page 57: Item 11, Consider implementing Comparable (5)
The sentence that ends "less than or equal to INTEGER.MAX_VALUE (231-1)." should end:
less than or equal to Integer.MAX_VALUE (231-1).

Page 64: Item 13, Favor immutability (2)
The equals method contains this return statement:
return (Float.floatToIntBits(re) ==   // See page 33 to
        Float.floatToIntBits(c.re))&& // find out why
       (Float.floatToIntBits(im) ==   // floatToIntBits
        Float.floatToIntBits(im));    // is used.
The final line is missing the characters "c." after the open parenthesis; the return statement should be:
return (Float.floatToIntBits(re) ==   // See page 33 to
        Float.floatToIntBits(c.re))&& // find out why
       (Float.floatToIntBits(im) ==   // floatToIntBits
        Float.floatToIntBits(c.im));  // is used.

Page 66: Item 13, Favor immutability (4)
The beginning of the sentence "An immutable object can provide static factories that cache" should be:
An immutable class can provide static factories that cache

Page 68: Item 13, Favor Immutability (5)
The class Complex has a private constructor but is supposed to be extensible from inside its package. For this the constructor needs to be package-private. The line that reads:
private Complex(float re, float im) {
should read:
Complex(float re, float im) {

Page 69: Item 13, Favor immutability (4)
In the example code that begins:
// Cached, lazily initialized function of an immutable object
private volatile Foo cachedFooVal = UNLIKELY_FOO_VALUE;

public Foo foo() {
    int result = cachedFooVal;
the result variable should be of type Foo. Also, the method fooVal is erroneously invoked as fooValue(). The example should read:
// Cached, lazily initialized function of an immutable object
private volatile Foo cachedFooVal = UNLIKELY_FOO_VALUE;

public Foo foo() {
    Foo result = cachedFooVal;
    if (result == UNLIKELY_FOO_VALUE)
        result = cachedFooVal = fooVal();

Page 73: Item 14, Favor composition over inheritance (5)
The sentence that begins, "If you've given the subclass a method with exactly the same signature" is imprecise. It should read:
If you've given the subclass a method with the same signature and return type

Page 81: Item 15, Design and document for inheritance or else prohibit it (5)
The phrase, "before the subclass's clone methods has a chance" should read:
before the subclass's clone method has a chance

Page 84: Item 16, Prefer interfaces to abstract classes (5)
On the bottom of the page the name of the method Sing is incorrectly capitalized. It should be:
sing

Page 87: Item 16, Prefer interfaces to abstract classes (5)
On the bottom of the page comment above the hashCode method incorrectly capitalizes hashCode. The comment should read:
// Implements the general contract of Map.Entry.hashCode

Page 89: Item 17, Use interfaces only to define types (4)
In the sentence that begins, "There are several constant interfaces in the java platform libraries," java should be capitalized:
There are several constant interfaces in the Java platform libraries

Page 91: Item 18, Favor static member classes over nonstatic (2)
The beginning of the sentence, "A nested classes should exist" should be:
A nested class should exist

Page 91: Item 18, Favor static member classes over nonstatic (4)
The two sentences, "Within instance methods of a nonstatic member class, it is possible to invoke methods on the enclosing instance. Given a reference to an instance of a nonstatic member class, it is possible to obtain a reference to the enclosing instance." should be replaced by the single sentence:
Within instance methods of a nonstatic member class, it is possible to invoke methods on the enclosing instance, or to obtain a reference to the enclosing instance using the qualified this construct [JLS, 15.8.4].

Page 111: Item 21, Replace enum constructs with classes (5)
In the code example, the Operation constants PLUS, MINUS, TIMES and DIVIDE should be declared final:
public static final Operation PLUS   ...

public static final Operation MINUS  ...

public static final Operation TIMES  ...

public static final Operation DIVIDE ...
This was a moderately serious typo. In the absence of the final modifier, a malicious or careless client could wreak havoc by changing the values of the enum constants.

Page 113: Item 21, Replace enum constructs with classes (4)
The sentence that ends, "because they're amenable to automatic method dispatching by the JVM, as in the Operator example." should end:
because they're amenable to automatic method dispatching by the JVM, as in the Operation example.

Page 114: Item 21, Replace enum constructs with classes (4)
The sentence that ends, "this problem in unlikely to be noticeable in practice." should end:
this problem is unlikely to be noticeable in practice.

Page 132: Item 26, Use overloading judiciously (2)
The sentence that begins "With the introduction of the Comparable interface, all of the these classes" should begin:
With the introduction of the Comparable interface, all of these classes

Page 139: Item 28, Write doc comments for all exposed API elements (5)
The sentence that referred to Doclint was changed because the URL for the utility is no longer active. The sentence now reads:
Also, there are utilities to check adherence to these rules [DocCheck].

Page 139: Item 28, Write doc comments for all exposed API elements (5)
The sentence that referred to the weblint utility was changed because the URL that once referred to the utility is now a disruptive page of advertising. The sentence now reads:
Several HTML validity checkers are available for download.

Page 147: Item 30, Know and use the libraries (2)
The sentence "The framework is based on six collection interfaces (Collection, Set, List, Map, SortedList, and SortedMap)." contains "SortedList" in place of "SortedSet." The sentence should read:
The framework is based on six collection interfaces (Collection, Set, List, Map, SortedSet, and SortedMap).

Page 150: Item 31, Avoid float and double if exact answers are required (2)
Missing apostrophe: "its slower" should be:
it's slower

Page 154: Item 32, Avoid strings where other types are more appropriate (5)
The reference to java.util.ThreadLocal should be:
java.lang.ThreadLocal

Page 159: Item 35, Prefer interfaces to reflection (5)
The line, "s.addAll(Arrays.asList(args).subList(1, args.length-1);" should read:
s.addAll(Arrays.asList(args).subList(1, args.length);

Page 173: Item 40, Use checked exceptions for recoverable conditions (4)
In the sentence, "It has no benefits over an ordinary checked exceptionality would serve merely to confuse the user of your API." exceptionality should be "exception and":
It has no benefits over an ordinary checked exception and would serve merely to confuse the user of your API.

Page 177: Item 42, Favor the use of standard exceptions (4)
The sentence that begins "While these are by far are the most commonly reused exceptions" should be:
While these are by far the most commonly reused exceptions

Page 178: Item 43, Throw exceptions appropriate to the abstraction (4)
The phrase "an example of exception transaction" should be:
an example of exception translation

Page 193: Item 48, Synchronize access to shared mutable data (5)
The statement, "In general, the double-check idiom does not work, although it does work if the shared variable contains a primitive value rather than an object reference [Pugh01b]." is too general. It should read:
In general, the double-check idiom does not work, although it does work if the shared variable contains a primitive value other than a long or double [Pugh01b].

Page 202: Item 50, Never invoke wait outside a loop (4)
The reference in the phrase "(as in the WorkQueue example, Item 50)" should be:
(as in the WorkQueue example, Item 49)

Page 202: Item 50, Never invoke wait outside a loop (5)
Technically, a series does not have a sum; it is a sequence of sums. Therefore, the sentence "The sum of this series is O(n2)." should read:
"This series is O(n2)."

Page 203: Item 50, Never invoke wait outside a loop (5)
The reference to Lea99 is incorrect. The reference and surrounding text should read:
Specific Notification [Cargill96, Lea00].

Page 221: Item 55, Consider using a custom serialized form (4)
The local variable size in the readObject method should be renamed to avoid shadowing the size field in StringList. This is not a bug, but shadowing should be avoided on general principle, as it tends to be confusing. Instead of size the variable should be named:
numElements

Page 234: References (5)
The Doclint URL is no longer functional, and has been replaced with a reference to Doc Check. (At the time of publication, Doc Check had not yet been released.) The reference is now:
[DocCheck] Doc Check. Sun Microsystems. October 2001.
< http://java.sun.com/j2se/javadoc/doccheck/index.html>.

Page 237: References (5)
The weblint URL is now a disruptive page of advertising. The reference has been removed.