Errata

Java NIO

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date Submitted
Printed Page 192
Figure 6-1

The last byte of the encoding should be 3F instead of 37

Anonymous  May 04, 2010 
Printed Page 228
1st paragraph after Example 6-4

The name of the file starts with directory "META_INF".
In fact, it's "META-INF" (a dash instead of an underscore character).

Anonymous  Apr 11, 2010 
Other Digital Version 213
Implementation of decodeChannel() function

In example implementation of decodeChannel() function, when CoderResult.UNDERFLOW result is processed function clear() is called on bb object. However in case of underflow compact() function should be actually called, as there might be still unprocessed input bytes in input buffer.

if (result == CoderResult.UNDERFLOW) {
// decoder consumed all input, prepare to refill
bb.clear(); // ERROR!!! Should be "bb.compact();"

// fill the input buffer, watch for EOF
eof = (source.read (bb) == -1);

// prepare the buffer for reading by decoder
bb.flip();
}


The same problem applies to downloadable source code.

Anonymous  Mar 09, 2009 
Printed Page 21
1st code example + penultimate normal paragraph

The code example
for (int i = 0; buffer.hasRemaining(), i++) {
myByteArray [i] = buffer.get()
}
is claimed to be inefficient but thread-safe.

Actually it isn't thread-safe because another thread could call get() between the
hasRemaining() and get() call, so the hasRemaining() test doesn't guarantee that
get() won't throw a BufferUnderflowException.

Anonymous   
Printed Page 26
4th pargraph (1st paragraph after figure2-10)

description of compareTo()'s behavior is incorrect.

Book says: "returns an integer that is negative, zero, or positive if the buffer
argument is less than, equal to, or greater than, respectively, the object instance
on which compareTo() was invoked."

JavaDoc for compareTo():

Compares this object with the specified object for order. Returns a negative integer,
zero, or a positive integer as this object is less than, equal to, or greater than
the specified object.

Anonymous   
Printed Page 93
Class ServerSocketChannel

method accept() returns SocketChannel, not ServerChannel.

Anonymous   
Printed Page 93
Class SocketChannel

Both open() methods return SocketChannel, not ServerSocketChannel.

Anonymous   
Printed Page 96
API of ServerSocketChannel

The return type of accept() should be SocketChannel.

Anonymous   
Printed Page 140-141
Listing Sample (4-1)

the sample code references a non instantiated "buffer" object

Anonymous   
Printed Page 141
sayHello() method

in registerChannel() method, if( channel == null ) was checked. Samething could
happen here. You may get a NullException when calling channel.write( buffer ).

Anonymous   
Printed Page 160
Table 5-2

the column regex="d" is incorrect from row limit=5 through row limit=0

the column should only have two "tokens" as follows

"poo", "le zoo"

for each of those columns (the columns each have three tokens AND the z is missing) ...

Anonymous   
Printed Page 208
2nd Paragraph and CoderResult API

The text and the API state that CoderResult uses the type-safe enumeration pattern.
This is not the case, the statics on the CoderResult object are private and ints.
This also means that example 6-2 is incorrect

Anonymous