Subtle But Deadly Java Date Bug

All of the college professors who have never worked in the real world oooh and aaahhh over Java. I’ve never been a big fan of the language, in part because it is one of the most inefficient languages on the planet, but mostly, because any tool in the marketplace with that much hype surrounding it generally turns out to be a shiny new turd. (How many of you are old enough to remember PowerBuilder? How about all of those different “Case Tool” products which were going to completely eliminate programmers?)

I was forced to use Java on a recent project and came face to face with a known bug which has been allowed to exist for a very long time. Please examine the following:


  1. import*;
  2. import java.util.Date;
  3. import java.util.Calendar;
  4. import java.text.*;
  5. public class badDateBugs {
  6. public static void main(String args[]){
  7. DateFormat screenFmt = new SimpleDateFormat( “yyyy/MM/dd”);
  8. DateFormat badScreenFmt = new SimpleDateFormat( “yyyy/mm/dd”);
  9. String original_date_str = “2008/09/01”;
  10. System.out.println( “Original date ” + original_date_str);
  11. System.out.println( “Result when good date format string used”);
  12. Calendar d1 = Calendar.getInstance();
  13. try {
  14. d1.setTime( screenFmt.parse( original_date_str));
  15. d1.add( Calendar.DATE, -7); // last week
  16. System.out.println( “One week prior was ” + screenFmt.format( d1.getTime()));
  17. } catch( ParseException p) {
  18. System.out.println( “Error parsing date1”);
  19. }
  20. Calendar d2 = Calendar.getInstance();
  21. System.out.println( “\n\nResult when bad date format string used”);
  22. try {
  23. d1.setTime( badScreenFmt.parse( original_date_str));
  24. d1.add( Calendar.DATE, -7); // last week
  25. System.out.println( “One week prior was ” + screenFmt.format( d1.getTime()));
  26. } catch( ParseException p) {
  27. System.out.println( “Error parsing date2”);
  28. }
  29. } // end main method
  30. } // end class badDateBugs


You probably don’t even notice the subtle typo which causes this problem. Listing lines 11 and 12 contain it. All you have to do is enter “mm” instead of “MM” and this bug rears its ugly head.

roland@logikaldesktop:~/java_date_example$ java badDateBugs
Original date 2008/09/01
Result when good date format string used
One week prior was 2008/08/25

Result when bad date format string used
One week prior was 2007/12/25


You will notice that none of the much vaulted “ exceptions” were thrown. The parse engine simply went on its way, and Java was happy to give you the wrong answer without any indication of a problem. Nice, very nice.


Software Books – The New Piracy Niche

I had heard this statement for quite some time, but had never really paid much attention to it, until this week. Thanks to the progression of technology and free software to edit/manipulate PDF files, book piracy is becoming a serious epidemic.Most of you reading this know that I have a computer book series entitled “The Minimum You Need to Know”. The current focus of this series is the OpenVMS marketplace. These books are on the high end and without competition. By “high end” I mean both price and the fact that 10,000 copies over 10 years is a lofty goal for the series. There simply aren’t many dedicated technical professionals out there willing to invest in their careers.

If you enter the computer book writing/publishing arena and focus on the high end topics, not the oatmeal $35 list price books, but the higher end topics, you will hear a saying: “You only sell one copy to all of India”. Before you go tagging me as a racist, you should know that I didn’t create the saying, and less than a month ago had an experience which tends to give it weight.

Yes, about a month ago I got an email from a person working for an Indian off-shore IT consulting company. They had just been assigned to work on a COBOL and FMS system for a client, and they didn’t even know how to log into an OpenVMS machine. They did a Web search and found my book previews on the Google Book site. You only get a few pages with the preview (not nearly few enough though since the smallest amount of a book you can expose is 20%, it needs to be 5%). This person took it upon themselves to email me and ask me to send them the entire contents of the book in a Word doc. I kid you not. They wanted it for free in a form their company could use to train others. I kid you not.

This got me to thinking about the advances in both technology and OpenSource software. For basically no money you can download or obtain a free set of CD’s containing the new industry standard desktop (Ubuntu). Bundled with it is the latest OpenOffice software and a rash of other programs to make your life (personal and professional) much easier. There is even free scanning software and free programs which will let you edit/manipulate PDF files, assuming you cannot get OpenOffice to open the PDF you are interested in editing.

All of this was supposed to make our lives better. But, like the Internet, nobody building it stopped to consider the downside.

Printer vendors have been working long and hard to make POD (Print On Demand) a viable solution for all. Many of these printers can now even print the cover and bind the entire book in one automatic process if it is one of the standard supported sizes. It truly is a marvel. In a few years they will figure out how to put a finish coat on the page so the toner can’t be felt by a reader and doesn’t remelt when the book is left in the sun.

Given all of these advances it truly is a wonderful time to be an author. You don’t have to care one hoot about finding a publisher. You can buy some ISBN numbers and publish your own books. Not only that, you can sell them on-line for list price with just a little bit of effort.

This week, the downside of this really hit home. I was taking a break from writing and surfing around the Web checking on my books. Seeing who was saying what, their ranking at various sites, and who was selling them. Lo and behold, there was a vendor on the Amazon site claiming to be selling new copies of “The Minimum You Need to Know to Be an OpenVMS Application Developer” for $65. I had never heard of this vendor. I had never sold them any books. The price they were selling for was below the normal wholesale price, so they would have had to purchase more than 300 copies to make that price profitable. My distributor hadn’t contacted me for a restock in a while, so I contacted them. They had never sold to this vendor either.

Curiouser and Curiouser.

You couldn’t get an actual physical address for the vendor at Amazon, but you could send them email through the Amazon site. I sent them an email asking where they obtained “new” copies since there are only two sources for them and neither of us had sold to them. A few days later I got the following reply from an AOL address.


We wouldn’t know where to begin.

We are supplied with books for re-sale from over 1,000 sources.


Yes, I left off the email address and vendor name. After getting this response and forwarding it to my distributor, I had them contact Amazon. The vendor is now gone, but we still haven’t found out how many copies they sold through Amazon. The problem is, good intentions have been abused. That vendor sales page doesn’t have any background checking because it was supposed to be for people who wanted to unload used copies and for authors wanting to sell a few copies themselves for more than wholesale. Now, it’s an eight lane highway for book piracy.

Not all books are a candidate for this kind of piracy. While it is true that an offshore operation like that can print an 800 page book with the included CD for around $5.00/copy because they don’t pay anything resembling wages to their workers and their supplies cost next to nothing, they don’t pirate just any books. They look for the slow moving, high end technical books. Why? Because they are selling these books in their own country for a lot of money via book stores which have no Internet presence. $25/copy is a lot of money when you aren’t paying anyone for it and have less than $5/copy in the printing.

It should be noted, that this vendor claimed a US location (somewhere in Virginia), but a little poking around on the Internet found a Nigerian printing house by the same name. Coincidence? Do the math. You pay someone $10/day to scan a copy of the book into a series of PDF files, then paste them all into one file. Probably takes them less than a week. You bought the original copy through a used book vendor so you paid way less than list for it. You chose your target by talking with an off-shore consulting company that was looking to train developers in a specific technology. You get them to agree to buy 200 copies at $25/copy, then print a 500 copy run to bring your costs below $5/book. Next you have a friend or employee living in the US put “ new” copies up on Amazon and a few other Internet sites offering a $90 book up for $65. In just a few weeks your 500 copies are gone. Your less than $500 investment in the book production netted you thousands, and you have no author to pay.

I post this blog not to whine, but to inform the other authors and publishers out there putting out high end books. You have invested well over a year putting these books together (I know it took over a year for the book in question here). Now, there are people out there making knockoffs for very little money and taking food out of your mouth. It’s not just you they are raping though. It’s every IT worker in every country where you have to pay for an education to work in IT. They are taking your jobs and not even paying for an education to do it.