Welcome to Giant Robots Smashing Into Other Giant Robots — a weblog about development, business, design and technology — written by thoughtbot.

Java will bite you

You know that burning flushed feeling you get when you just got a really good zinger tossed in your face, possibly by your best friend, possibly by your worst enemy. Doesn’t matter. Anyway, on the “worst enemy” part, Java just threw one of those my way, except it wasn’t a zinger, it was the stinging burn of a day and a half of wasted effort.

In Windows, a File object will report false to the functions delete() and renameTo() if the file is currently in use. This does not happen on Linux, where I had originally tested it. I was trying to be all nice about it and use those functions because I figured they were the “right” way of doing it.

Java only responds to authority, it seems.

Changing to a flat out frontal assault (that is, FileOutputStream) on the file in question resulted in it being properly overwritten. What annoys me about this is that when I was originally testing yesterday whether or not I could copy over running files in Windows, I was using the copy command. This, like File.renameTo(), politely says the file is in use and to come back when the other program is finished, thank you and have a nice day. Later, I was messing around with xcopy because I was desperately seeking another venue for copying the damned files, and it overwrote them no problem. I guess, being xcopy, was more eXtreme than copy and the filesystem’s culture shock allowed xcopy to slip by. As such, I emulated its barbarian tactics, broke the door down, and I was in.

The moral of the story is, no more Mr. Nice Java for me. Forcibly inserting a URL into the System Classloader at runtime? Yes, ma’am. I’ll do all that and more. I’m a bad boy now.


About this entry

 

thoughtbot is hiring

We are hiring web developers and web designers in both Boston and New York, NY.

What are we up to?

We built Shoulda, an eclectic set of additions to Test::Unit; Paperclip to manage uploaded files without hassle; Jester, a REST/ActiveResource client library written in Javascript, and Squirrel, an enhancement for ActiveRecord's find syntax; — amongst some other projects.


Chad (President) and Jon (CTO) co-authored a technical book titled Pro Active Record: Databases with Ruby and Rails, which explores the ins and outs of the ActiveRecord ruby library. You can buy it today at Amazon.com.

About thoughtbot, inc.

We are a small web application development consulting business, with offices in Boston, MA and New York, NY. If you're looking to find a team for your next web development project or your new web application — get in touch.