Monday, April 28, 2014

NetBeans and the UTF-8 Nag

I had a mildly annoying experience with the NetBeans IDE recently, and I'm making a note to myself here what to do if it happens again.

I was debugging a Java program that I wrote using an open-source library, and it became necessary for me to set a breakpoint in the library code. This was a first time experience for me: I use open-source libraries extensively, but I virtually never open the source code, and in fact I usually don't bother to include the path to the source code when I define the library in NetBeans. I've found that nothing spoils the taste of the sausage quite like seeing how it was made. :-)

At any rate, when I opened the source file to insert the breakpoint, NetBeans warned me that the source file "cannot be safely opened with encoding UTF-8" and asked if I wanted to open it anyway. I said yes, it opened, I set the breakpoint, found the bug (in my code), closed the source file and that was that. Or so I thought. There's a discussion of this warning on the NetBeans support forum, including various possible remedies (including converting the source library to UTF-8). That wasn't necessary or worth the effort in my case, since I was opening one file, one time only.

The first occurrence of the UTF-8 warning wasn't bothersome. What was annoying was that every time thereafter that I opened the project in NetBeans, I got the warning. Whether I answered the "really do it?" question yes or no did not matter; none of the source files opened, and the IDE thereafter gave me no grief ... until the next time I went into that project.

It turns out that I had left the breakpoint in the source file set. Even though the source file was closed, and I was not attempting to reopen it, the presence of the breakpoint was apparently causing NetBeans to look at the file, see the non-UTF-8 encoding, and nag me. Once I figured that out, the solution was simple: remove the breakpoint. Note to self: be extra careful to remove breakpoints from foreign source code in the future.


2 comments:

  1. Note: To avoid declaring the libraries jars and their sources jars too, open a pom.xml file (if they provide one for their examples) with NetBeans and it will configure the rest automatically. (example details).

    ReplyDelete
  2. Thanks for the tip Geoffrey. I just searched all the Java libraries I have installed, and only two of them provide a pom.xml file. :-( I'll keep an eye out for it in future downloads.

    ReplyDelete

If this is your first time commenting on the blog, please read the Ground Rules for Comments. In particular, if you want to ask an operations research-related question not relevant to this post, consider asking it on OR-Exchange.