Jakarta Commons Cookbook by Tim O'Brien This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated March 26, 2007. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (xiii) Under "Chapter 4, Functors" subheading, 2nd sentence; "...predicates, transformers, and closures, and functors,..." ^^^ should be: "...predicates, transformers, closures, and functors,..." {5}: "import org.apache.commons.lang.builder.ToStringBuilder" should be "import org.apache.commons.lang.builder.ReflectionToStringBuilder" {5}: Error in toString() method: public void toString() { ReflectionToStringBuilder.toString(this); } Should read: public String toString() { return ReflectionToStringBuilder.toString(this); } {6}: Error in toString() method: public void toString() { ReflectionToStringBuilder.toString( this ); } Should be: public String toString() { return ReflectionToStringBuilder.toString( this ); } {10}: "PoliticalCandidate.class.isAssignableFrom(o)" should read "PoliticalCandidate.class.isAssignableFrom(o.getClass())" {10}: Variable misnamed in code example. "PoliticalCandidate pc = (PoliticalCandidate) o;" should be "PoliticalCandidate ps = (PoliticalCandidate) o;" {12}: "public int compareTo(Object o) {" should read "public int compareTo(Object obj) {" {25} code swatch at the center of page 25; Existing example: // Rounding to the nearest hour Date wokeUp = new Date(); Date wokeUpAround = DateUtils.round ( now, Calendar.HOUR ); Proposed change: // Rounding to the nearest hour Date wokeUp = new Date(); Date wokeUpAround = DateUtils.round ( wokeUp, Calendar.HOUR ); [28] 1-16; private Flavor(String name, int value) { super( name, value ); } should be: private Flavor(String name) { super( name ); } {47}: Code sample should be completely replaced with the following: String variables = "{45}, {35}, {120}"; int sum = 0; String[] tokens = StringUtils.split( variables, "," ); for( int i = 0; i < tokens.length; i++ ) { String numberStr = StringUtils.substringBetween(tokens[i], "{", "}"); Integer number = new Integer( numberStr ); sum += number.intValue(); } System.out.println( "Variables: " + variables + ", Sum: " + sum ); {55} Code at top; The line String name2Temp=StringUtils.replaceChars(name1,punctuation,""); should be using name2 instead of name1. {56}: In code listing, "countMatches(,"futility")" should be "countMatches(line,"futility")" (61): The correct Levenshtein distance between "Steve" and "Stereo" is 2. The example output incorrectly lists this as 3. (73) Last lines of top code, formatting error; "This example retrieves the name property of the author property on the Book object, printing "Ralph Waldo Emerson"" should be a seperate paragraph of text. (73) middle of page: "General Exception is caught." should not be the first line of the code example and should be removed. (78) Paragraph under figure; The getProperty() method parses the supplied property name, splitting the name as the period character. should be: The getProperty() method parses the supplied property name, splitting the name at the period character. {86}: Levenshtein distance between "Word" and "World" is one. Output incorrectly lists Levenshtein distance as 2. [87] the code in the Solution; in the book: boolean nameReadable = PropertyUtils.isReadable( book, "name"); boolean nameReadable = PropertyUtils.isWritable( book, "name"); should be: boolean nameReadable = PropertyUtils.isReadable( book1, "name"); boolean nameReadable = PropertyUtils.isWritable( book1, "name"); comments: should be "book1" instead of "book" {88}: There is a missing line, the predicateArray is referenced without being defined. The following changes are necessary: // A Predicate that returns true if the "name" property is not null Predicate teamNotNull = new BeanPredicate( "name", new NotNullPredicate( ) ); // A Predicate that returns true if the "coach.firstName" property // is "Tom" Predicate coachFirstName = new BeanPredicate( "coach.firstName", new EqualsPredicate("Tom") ); // Tie two Predicates together into an AndPredicate Predicate validateTeam = new AllPredicate( predicateArray ); should read: // A Predicate that returns true if the "name" property is not null Predicate teamNotNull = new BeanPredicate( "name", new NotNullPredicate( ) ); // A Predicate that returns true if the "coach.firstName" property // is "Tom" Predicate coachFirstName = new BeanPredicate( "coach.firstName", new EqualsPredicate("Tom") ); Predicate[] predicateArray = new Predicate[] { teamNotNull, coachFirstName }; // Tie two Predicates together into an AndPredicate Predicate validateTeam = new AllPredicate( predicateArray ); {94}: Code references an unknown variable due to typo. Code should be changed as follows: BasicDynaClass politicianClass = new BasicDynaClass( "politician", BasicDynaBean.class, props ); should read: BasicDynaClass politicianClass = new BasicDynaClass( "politician", BasicDynaBean.class, beanProperties ); [95] See Also of 3.18; The See Also section is incorrect. Those things are not covered in the book. {108} Example 4-4; Unintended errata: The suit order isn't right for official Poker or Bridge. To sort in official order, please replace: private String[] suitOrder = { "S", "C", "D", "H" }; with private String[] suitOrder = { "C", "D", "H", "S" }; {138}: "majorQuakes.hasMore()" should be "majorQuakes.hasNext()" {137} Recipe 5.4; Chapter 5, Recipe 5.4 EarthQuake quake1 = new EarthQuake( ); quake1.setLocation( "Chicago, IL" ); quake1.setIntensity( new Float( 6.4f ) ); quake1.setIntensity( new Float( 634.23f ) ); <--- setDepth quake1.setTime( new Date( ) ); quakes.add( quake1 ); EarthQuake quake2 = new EarthQuake( ); quake2.setLocation( "San Francisco, CA" ); quake2.setIntensity( new Float( 4.4f ) ); quake2.setIntensity( new Float( 63.23f ) ); <--- setDepth quake2.setTime( new Date( ) ); quakes.add( quake2 ); {137} Recipe 5.4 / Example 5-1;should be: public void setIntensity(Float intensity) { this.intensity = intensity; } <--- setIntensity (183) Table; getBooleanBalue should be getBooleanValue {229} Chapter 8: "There were significant changes between the pre-release version of Commons Math and the 1.0 release of Commons Math. All of the concepts introduced in Chapter 8 of the Commons Cookbook remain valid, but many of the code examples will not compile as written. You will need to consult the Commons Math API in the 1.0 release." {256 - 9.3} code example line 11.; There should not be a semi-colon after the line 10. String expr = "${opera.name} was composed by ${opera.composer} in ${opera.year}. "; "This opera has ${opera.acts.size( )} acts, and it is performed in " + "${opera.language( )}"; Should read: String expr = "${opera.name} was composed by ${opera.composer} in ${opera.year}. " + "This opera has ${opera.acts.size( )} acts, and it is performed in " + "${opera.language( )}"; {256}: The following line of code should follow "opera.setYear(1791);": opera.setLanguage("German") {256}: "${opera.language()}" should be "${opera.language}". {258}: In the sorting example, there is a missing line in the code example, which will cause every ball to end up in the Misc-bin. A break neds to be added after the call to sendBall() as follows: if( result.booleanValue() == true ) { sendBall( ball, basket ); } Should read: if( result.booleanValue() == true ) { sendBall( ball, basket ); break; } {258}: basket is an undefined variable. "sendBall(ball, basket );" should read "sendBall( ball, bin );" {290}: "FileUtils.sizeOfDirectory()" should read "FileUtils.sizeOfDirectory(dir)" (292) Last paragraph; ".htm" is split across lines as if it were ". htm" (320) Paragraph under discussion; MIME is Multipurpose Internet Mail Extensions, not Main Extensions. {330} First paragraph; The sentence "If ALLOW_CIRCULAR_REDIRECTS is set to true," should read "If ALLOW_CIRCULAR_REDIRECTS is set to false," (341) Paragraph under discussion; XPath is generally used by select nodes in an XML document... should be: XPath is generally used to select nodes in an XML document... (349) line eight of the example is incomplete. It reads: logger.info( "Looking for XML files in " it should be: logger.info( "Looking for XML files in " + dataDir.getAbsolutePath() );