Thứ Ba, 7 tháng 9, 2010

JavaOne 2010 Abstract of the Day #3: Defective Java Code: Mistakes That Matter

UPDATE (Presentation Canceled): Todd pointed out that Bill Pugh has sent out a Twitter message stating that he will not be presenting at JavaOne 2010 "since I am a visiting scientist at Google, and for other reasons."  See the feedback comments below for additional details.  While not explicitly stated, I assume this Tweet references the "Defective Java Code" presentation I highlighted in this post, but that it also applies to the "Java Puzzlers: Scraping the Bottom of the Barrel" (S314408) presentation scheduled to be co-presented with Josh Bloch. At this time, I'm leaning toward taking advantage of this available slot to attend either "JavaFX Graphics" (S313960) or the Panel Session "Showdown at the Java Virtual Machine Corral" (S313946).  Because this presentation is apparently canceled (at least by Tweet), I am going to use my previous highlighting of 97 Things Every Programmer Should Know presentation as the third of my series of highlighted JavaOne 2010 presentations.






The third JavaOne 2010 presentation that I have chosen to highlight is "Defective Java Code: Mistakes That Matter" (S314504).  This presentation by Bill Pugh is currently scheduled to begin at 4:45 pm on Wednesday, September 22, in Grand Ballroom B of Hilton San Francisco.  William Pugh is a six-time JavaOne Rock Star and is a professor in the Computer Science department at the University of Maryland.  His work with FindBugs (project lead) makes him uniquely qualified for a presentation of Java bugs and defects.  Here is the text of the abstract for this presentation:
This talk will describe programming mistakes or puzzlers found in production code and discuss lessons learned about how to construct high-quality software. While there are many types of mistakes, some mistakes are much more common than others. And for various reasons, many blatant errors in code never cause any problems in production. This session is intended for intermediate to advanced Java developers and will cover: 
* The Java language and API puzzlers encountered in production code
* Techniques such as dynamic instrumentation, logging tricks, and using FindBugs (or other static analysis tools) to detect serious coding mistakes
* Ways to effectively apply these techniques to find the mistakes that matter
I think the selection of this topic is more evidence of this year's JavaOne's commitment to core Java topics.  That being said, Pugh gave a very similarly titled presentation last year.  That presentation, "Defective Java Code: Mistakes That Matter" (TS-5335), is still available in PDF form as of this writing.  The abstract from last year's (2009) presentation reads:
[2009] Drawing lessons from the FindBugs static analysis tool and eight months at Google as a visiting scientist, this session's speaker discusses programming mistakes that cause real problems in practice and presents techniques for preventing and/or catching these mistakes early. He discusses some of the elements of the Java programming language, libraries, and IDEs that can cause problems and offers lessons learned from them, such as the dangers of trusting refectoring tools. He also talks about mistakes that can be found with static analysis and problems that have been identified by defect postmortems and dynamic techniques. [2009] 
Last year's presentation was heavily based on Pugh's experiences as a "visiting scientist at Google" for ten months.  So, even if Google is not present at JavaOne 2010, its presence will still be felt.

Thứ Hai, 6 tháng 9, 2010

Different Headlines from "An Update on JavaOne"

Just about anyone who spends anytime in the Java blogosphere has heard about Google's pulling out of JavaOne 2010 as first announced in Josh Bloch's blog post An Update on JavaOne.  There have been numerous posts and articles spawned from this announcement.  In my own post on the subject (The Impact of a Googless JavaOne), I stated that it wasn't clear to me whether this was an Oracle-led action or a Google-led action. Since then, I've found it somewhat interesting to see how different authors, bloggers, and presumably editors have chosen to headline this announcement. It is interesting how different people can imply different things in their headlines for essentially the same story. In this post, I summarize some of these headlines with links to the underlying blog or article.  When reading these headlines, keep in mind that the "blog post that started it all" was simply understated as "An Update on JavaOne."


⇒ Oracle's Lawsuit Preventing Google from Participating at JavaOne (Sean Brunett, Android Central)

⇒ Google Pulls Out of JavaOne in Snit (Maureen O'Gara, JDJ)

⇒ Google Not Attending JavaOne Conference (Dustin Karnes, Talk Android)

⇒ Google Opts Out of JavaOne Conference Due to Lawsuit (John van Wunnik, Android Headlines)

⇒ Google Turns a Cold Shoulder to JavaOne (Justin, Gone Googling)

⇒ Sued by Oracle, Google Shuns JavaOne (Om Malik)

⇒ Google Withdraws from JavaOne (Thom Holwerda, OS News)

⇒ Google Bails on Oracle/Sun JavaOne Conference (Seth Weintraub, Fortune Tech)

⇒ Google Won't Be at JavaOne (Scotsman on a Horse)

⇒ Google Drops Out of JavaOne (Billy Bob Bain, Bain Labs)

⇒ Google Pulls Out of JavaOne Conference Due to Oracle (Quentyn KennemerPhandroid)

⇒ Google Bows Out of JavaOne Due to Lawsuit (Nancy Gohring, CIO)

⇒ Google Cancels JavaOne Participation

⇒ Google Boycotts JavaOne (Mitch Pronschinske, JavaLobby/DZone)

⇒ Google to Give JavaOne a Miss Due to Oracle Lawsuit (Pullkit Chandna, Maximum PC)

⇒ Google Exits Conferences Due to Oracle Suit (Doug Caverly, WebPro News)


Much of the content of each of these posts is very similar and most include a quote or two from the original Bloch post.  However, the different headlines alone show where different authors place the emphasis for who is to blame.

By the way, as of this writing, Google is still shown as a Bronze Sponsor on the JavaOne page and there are still 17 presentations associated with Google presenters shown in Schedule Builder.

JavaOne 2010 Abstract of the Day #2: Polyglot Programming in the Java Virtual Machine (JVM)

At the end of my previous post (A Fortnight to JavaOne 2010), I provided brief focus on a JavaOne 2010 presentation abstract of interest.  I plan to focus on one JavaOne 2010 abstract of interest to me each day until the beginning of JavaOne. This blog post is the second in that series and its focus is the presentation "Polyglot Programming in the Java Virtual Machine (JVM)" (S314424).

Andres Almiray is currently scheduled to present "Polyglot Programming in the Java Virtual Machine (JVM)" on Wednesday, September 22, at 1 pm at Parc 55 in Divisidero.  Here is the abstract for Andres's presentation:
The Java language boasts one of the largest software ecosystems. You can find libraries, components, and servers of all sizes, types, colors, and flavors. This is what's made it the choice language for many. But the Java Virtual Machine (JVM) is also open enough to let other languages live in it; languages that provide new features and concepts that the Java language does not have. Some of these languages are even Java friendly. In this session, we'll discover the benefits of adding a bit of spice to your Java development skills by exploring Groovy's metaprogramming techniques, Scala's functional side, and Clojure's approach to managing concurrency.
Like many in the Java development community, I believe that alternative JVM languages will play a huge part in the future of the JVM.  I have definitely found Groovy to be a welcome scripting tool in my standard and enterprise Java development. I plan to attend several JavaOne presentations on alternative JVM languages, but this abstract is particularly interesting to me because of its combination of generality (covering multiple JVM languages) with specific illustrative details related to Groovy's metaprogramming, Scala's functional programming, and Clojure's concurrency handling.

Chủ Nhật, 5 tháng 9, 2010

A Fortnight to JavaOne 2010

With two weeks to JavaOne 2010, the frequency of blog posts related to JavaOne is rising as excitement for the coming conference builds.  In this post, I reference and summarize several of these.  I also begin what I hope is a once-per day (until JavaOne begins) focus on a JavaOne 2010 abstract that seems particularly interesting to me. For today, that will be at the end of this post.

Several people with long experience with Java development and with JavaOne conferences have recognized this year's JavaOne's focus on core and fundamental Java technologies.  Back in February, Oracle Technology Network (OTN) editor Justin Kestelyn called this year's edition a "return to purity."  In that post (which highlighted the call for papers), Justin stated, "the conference is going back to its roots: 100% focus on Java technology and its related ecosystem and community - no distractions. ... Sometimes, simpler is better."  Those selecting abstracts for presentation seemed to adhere to that statement.

Approximately a week after Kestyln's "A Return to Purity" post, Java.net editor Kevin Farnham observed:
In a sense, I think this year's JavaOne will actually be more focused on core Java topics. Wasn't the old JavaOne really a kind of "SunOne" or "SunWorld" conference, in ways? That's how it felt to me, anyway. Just about anything and everything "Sun" was present at JavaOne, in one form or another.
With the presentations selected, the idea of JavaOne focusing less on a particular company (Sun or Oracle) and focusing more on the Java ecosystem seems to have been realized.  I have posted my opinion of this and Adam Bien has also observed this.  In his post JavaOne Sessions Schedule Completed - First Impression, Some Criticism, he states:
Last week I managed to schedule sessions I would like to attend. The topics are interesting and technical - really looking forward to it. Product pitches are not existent - at least I didn't found any. From the topic / session perspective - I really looking forward to this conference. From the content perspective it should be at least as good as the previous ones.

Some had previously feared that the combining of Oracle OpenWorld with JavaOne would take away from JavaOne's Java developer focus.  Had these conferences been combined into the same conference, these fears might have been realized.  However, by having them co-located but separate, Oracle has managed to keep its more proprietary and Oracle-focused presentations in Oracle OpenWorld and Oracle Develop and leave JavaOne as a purely Java-focused conference.  Although my blogger pass allows me to attend all three conferences, there is no doubt that the vast majority of my time will be spent attending JavaOne presentations.

Although I'm pleased that the topics presented at JavaOne this year tend to be core and fundamental, I am also very much looking forward to hearing the keynotes at this conference.  In the case of keynotes, I often am looking for future trends and directions and the Java Strategy and Directions keynote holds a lot of promise in this area.  Terrence Barr appears to feel the same way and states (with his emphasis), "At the top of the list is certainly the Monday keynote Java Strategy and Directions (Monday, 5:45 pm to 7:15 pm)." I also agree with Barr that "another must-attend is the Tuesday keynote JavaOne Technical General Session (Tuesday, 2:30 pm to 4:00 pm) with Greg Bollella, Roberto Chinnici, and Mark Reinhold."

The most recent JavaOne 2010 posts are not without criticism.  Douglas Bullard wonders why he has not been notified of the cancellation of GWT presentations associated with Google employees.  I think that's a good question.  Have the individual speakers not notified the conference organizers that they will not be presenting?  Or, have the conference organizers been notified and failed to update Schedule Builder and send out the cancellations?  If the only "notification" has been Josh Bloch's blog post, then I'd argue that a single blog post (even one as viral as this) is insufficient basis to cancel several individuals' separate presentations.  For every conference that I've presented at, it has been the speaker's responsibility to contact the conference organizers to state that he or she won't be presenting.  That may have happened here, but I don't want to jump to any conclusions without knowing more details.  It could be the conference organizer's fault for not notifying conference attendees with these presentations on their schedule of their cancellation, but it could also be the fault of the presenters not communicating to the organizers that they won't be presenting.

Adam Bien is not impressed with Schedule Builder and writes that "schedule builder software isn't a usability show case."  He lists several ways it could be better.

JavaOne 2010 begins two weeks from today in San Francisco, California.



JavaOne 2010 Highlighted Abstract of the Day (Day #1)
Java Unleashed: Java Virtual Machine Tuning from the Pros
One JavaOne 2010 presentation that looks particularly interesting to me and is evidence of the "return to purity" and greater "focus on core Java topics" is "Java Unleashed: Java Virtual Machine Tuning from the Pros" (S313949).  This session will be presented by an IBM employee, Trent Gray-Donald, and will be held Thursday, September 23, 12:30 pm at Parc 55 in Cyril Magnin III.  Here is the abstract for this presentation:
Worried you're not getting every last ounce of performance out of your application running on a Java Virtual Machine (JVM)? Not sure where to start? Come hear some of the leading JVM implementers describe how to tune an application until it flies. This session will provide insights into different approaches to performance tuning, from low-level profiling through application-centered approaches. We'll use several helpful free tools, including VisualVM, the IBM Visual Performance Analyzer, and the Eclipse Memory Analyzer, to get unique insights into running Java programs and unlock new levels of performance from your applications. You'll leave with an appreciation of what JVM teams use to analyze and solve many performance bottlenecks.
I like to use VisualVM, but I'm not as familiar with the IBM Visual Performance Analyzer or the Eclipse Memory Analyzer (see also Acquire Heap Dump from MAT) and look forward to learning more about them.  However, what I am most interested in are the general JVM performance tuning tactics that I can glean from this presentation.

Thứ Bảy, 4 tháng 9, 2010

Log Level Inflation

There are many types of inflation.  The best known inflation, economic inflation, represents a "rise in the general level of prices of goods and services in an economy over a period of time" (Wikipedia article).  The rise in prices makes the money people have worth less (can purchase less with the same money).  Cost of living wage increases and minimum wage increases are often used to try to help people lose less of their purchasing power, but such increases also impact the very inflation whose effect they are intended to address.

Log Level Inflation works in much the same way: developers may "temporarily" (read sometimes permanently through accident or intent) increase the log level of logged messages to make them stand out more (have more value) from the crowd of logged messages.  The problem is that this can lead to messages logged at those higher levels now being reduced in value (more difficult to find) because the messages of truly less import are now artificially valued at the higher level.  This can become a cyclic effect if left unchecked, making the logs virtually useless and often resulting in having to turn logging off or turn it up to log only the highest level messages (FATAL in Log4j or SEVERE in java.util.logging for example).

Fortunately, dealing with logging issues effectively, although difficult, is not as difficult as dealing with complex economic policies.  In this blog post, I look at some of the reasons log level inflation occurs and will look at steps that can be taken to stop or slow down log level inflation.


What Causes Log Level Inflation?

There are several intentional and accidental causes of log level inflation.

Overzealous Logging
Too much logging can lead to log level inflation because developers feel the need to turn up the log level of their messages to stand out from the crowd.  This is a natural reaction to having a difficult time finding relevant logs in the middle of the verbose logs.

Neglecting 'Temporary' Logging
It is not uncommon for a developer to add logging temporarily to help diagnose and fix a particular problem.  This includes adding logging that would not otherwise be included or adjusting logging to a higher severity to make it stand out while debugging the problem.  If the developer forgets to remove this extraneous logging or to turn it back to do its typical level, the new logging remains in the code base and contributes to log level inflation.

Log Levels Not Well Understood
If the meaning or severity of log levels is not well advertised or understood, developers are more likely to place their log messages at the wrong level.  This can lead to log level inflation when developers inadvertently set messages at a higher level than they are worth.

Using Logging Less Effectively
Logging may not always be the best diagnostic tool for debugging.  When logging is used in cases where there is a better alternative, it is more likely to lead to log level inflation.


Reducing or Eliminating Log Level Inflation

Fortunately, stopping or minimizing log level inflation is not as difficult as doing the same to economic inflation. However, it still can be difficult. Here are some ways to do this.

Use the Correct Tool for the Job
In some cases, adding logging may not be the best way to diagnose the problem at hand.  Logging should be considered in conjunction with other diagnostic tools such as debuggers, monitoring tools and approaches (such as via JMX), unit tests, and code analysis.  The best tool should be used for the particular job.

Choose Clear Guidelines for Log Levels
On the surface, Log4j log levels such as TRACE, DEBUG, INFO, WARN, ERROR, and FATAL might sound self-explanatory.  However, it is useful to make sure developers understand the sometimes subtle differences between adjoining levels (such as DEBUG versus INFO).  Developers who understand the purpose of each log level may still choose to put messages at the wrong level to make them stand out, but at least they won't inadvertently do so.  With log levels such as FINE, FINER, and FINEST that come with java.util.logging, this definition of the levels is even more of a necessity.

Include Logging Frequency and Level in Code Reviews
Logging is one of those things that often is neglected in reviews because of its simplicity.  However, for long-term benefit, it is worth reviewing the choice of logging and the level of logging used during code reviews.  This can help prevent log level inflation.  In my undergraduate electrical engineering program, the department chose to prevent grade inflation from occurring by forcing instructors to give grades in any given class that had an average of a B-.  Similar policies could be used to ensure that log levels are appropriate and not inflated in importance.

Explicitly Remove Temporary Logging before Placing Under Source Control
Developers should also review their own code before checking it into the configuration management system to ensure that temporary logging has been removed.  Many developers use tactics to try to mark logging code that is intended for removal.  Such tactics include different/no indentation, inclusion of special symbols, and comments stating the temporary nature.  If such tactics were standardized, scripts and other tools could be used automatically remove these log calls from the source code before merging in into source control.

Use Tools and Scripts to Emphasize Current Logs of Interest
One way to combat log level inflation that occurs as a natural result of developers using inappropriately high levels of logging to emphasize logic related to the problem being worked on is to use tools (such as Chainsaw) and scripts to highlight those logs rather than setting them to an inappropriately high log level. A tool or script can make it easier to find relevant log statements without artificially changing their log level.

Purge and Adjust Logging Regularly
Logging seems like a simple thing, but bad things can happen when simple things get out of hand.  If excessive logging or logging at incorrect levels gets out of hand, it is worth the effort to review code and logged output to determine what can be removed or reduced in severity.

Log Effectively
One way to reduce log level inflation is to log effectively.  Effective logging reduces log level inflation through the concept of quality over quantity.  High-quality logging messages with carefully selected content placed in strategic locations with the program logic can often reduce the need for additional logging messages.  There are numerous online resources that provides ideas for more effective logging.  These include Keith Gregory's Effective Logging (on a totally unrelated note, see his recent and brief Agile Isn't New post), Eric's Effective Logging, About Effective Logging (a PDF), Effective Logging Practices Ease Enterprise Development, StackOverflow thread on Logging Best Practices and related StackOverflow thread on What Do We Log and Why Do We Log?

Conclusion

Log level inflation has many negatives effects on software development, maintenance, and bug diagnosis.  It can even have real effects on the performance of the software in extreme cases.  Therefore, it's important to take steps to prevent log level inflation and to fix any inflation that occurs.  In this post, I've quickly reviewed some of the reasons log level inflation occurs and ways to prevent it or fix it.

Thứ Năm, 2 tháng 9, 2010

Building Anticipation for JavaOne 2010

In Excitement brewing for JavaOne 2010, with or without Google, Neil McAllister lists some reasons JavaOne 2010 "could be the platform's most significant conference ever."  There is, of course, the potential drama and controversy surrounding the recent Oracle/Google Android lawsuit, the announcement of Google withdrawing from participation in the event, and the wearing of slogan-bearing t-shirts.  However, there is also the potential to learn more about the future direction of the Java language, the Java platform, and the Java ecosystem.  Paul Krill has recently written a post on these subjects called Why the Java Frenzy Shouldn't Worry Anyone.  I personally have liked the focus on core Java topics at this year's event.  OTN Editor Justin Kestelyn called this a "return to purity" and this is what I prefer in software development conferences: deep technical insight into core subjects that I'm likely using or will use.

Terrence Barr writes in JavaOne 2010 Approaching Fast that "JavaOne is only a little more than two weeks away. Even though JavaOne is, for the first time this year, co-located with Oracle Develop, JavaOne is still very much an event in its own right."

The Java Community Process (JCP) Program Office has issued an invitation to activities related to the JCP.  These activities include two Birds of a Feather sessions called "Java ME Checkpoint: Current Status and Future Directions" and "Java Community Process: What You Like and What You Don't." It appears that both are being held at the same time on the date (7 pm on Tuesday, September 21).  The Java.net Activities at JavaOne post contains details about the Java.net activities at JavaOne being hosted in the Mason Street Tent.

The Eclipse Foundation is offering an opportunity to win a pass to JavaOne 2010.  To enter this raffle, submit a story of how you and/or your organization uses Eclipse by September 9.  See the related Wiki page for more details.

Students can obtain complimentary "Discover Passes" to JavaOne 2010 that allow them to attend sessions in the "Java Frontier track for students."  The Discover Pass sessions are described as "designed for those with some or no programming experience. Students with no programming experience will discover tools and projects related to programming."  "Qualifying students" get to attend the keynotes for the simultaneous conferences (JavaOne, Oracle Develop, and Oracle OpenWorld), the exhibition halls, and the Mason Street Tent.  Also, when space permits, the students with these passes can attend JavaOne and Oracle Develop technical sessions as well.  See the Calling All Student Developers: Get Into JavaOne and Oracle Developer for Free! post on the JavaOne conference blog for additional details on who qualifies and how to obtain this pass.

There has been some talk that JavaOne May be Dead, but as I started this post with, there is also talk that this could be one of the most momentous editions of JavaOne.


Thứ Tư, 1 tháng 9, 2010

Finding RMI Ports with Groovy

In a previous blog post, I demonstrated using a simple Groovy script to display all names bound to a particular RMI registry on a specified host/port.  This script is easy to understand and use, but does require knowing which host and port to extract the bound names for.  The candidate ports could be identified via a tool like netstat or based on error information in a log message (such as stating an AlreadyBoundException).  In this blog post, I demonstrate another approach using Groovy to looking over a range of ports to find RMI bound names.  This is not a particularly efficient approach, but can be used to check over a range of ports for potential RMI registries and for listing their bound names.

rmiFinder.groovy
import java.rmi.ConnectException
import java.rmi.RemoteException
import java.rmi.registry.LocateRegistry
import java.rmi.registry.Registry

if (!args || args.length < 3)
{
println "Provide name of host and range of ports (lowest and highest) on which to look for RMI-exposing ports."
System.exit(-1)
}
def host = args[0]
def initialPort = args[1] as Integer
def finalPort = args[2] as Integer

println "Searching for RMI-exposed ports on host ${host} within port range ${initialPort}:${finalPort}"
for (port in initialPort..finalPort)
{
registry = LocateRegistry.getRegistry(host, port)

try
{
def boundNames = registry.list()
println "\nRMI Registry found on host:port ${host}:${port} with service names"
boundNames.each{println "\t${it}"}
}
catch (ConnectException connectEx)
{
print "."
// no RMI registry or cannot connect to it
}
catch (RemoteException remoteEx)
{
print "."
// no RMI registry or cannot connect to it remotely (covers AccessException)
}
}
println "\nNo ports with RMI exposed services found on host ${host} within range ${initialPort}:${finalPort}"

The simple rmiFinder.groovy script makes use of the approach demonstrated in the previous post regarding looking up a registry's bound names on a particular registry, but adds a simple looping mechanism to loop over a range of ports on the specified host rather than looking at a single specified port on that host.

The Registry.list() method can throw a RemoteException or its child AccessException or a ConnectException.  All three of these lead to giving up on the particular port being tried in the loop and moving onto the next port.  If none of these expected possible exceptions are caught, then the names of RMI services bounds to that port are displayed.  I actually could have caught a RemoteException only because both AccessException and ConnectException extend RemoteException.

This approach is not particularly speedy.  It takes a relatively long time to attempt the Registry.list() invocation and handle the inevitable exception handling that occurs for all non-RMI ports.  Because of this incredible slowness, I had the script print out a period (.) for each failed attempt to indicate some progress being made.

The following screen snapshot shows this simple script in action.  I started a simple Java application with an exposed RMI service on port 2999 to demonstrate.  Because I had the luxury of knowing the port I was looking for, I could keep my example to a small range (2990 to 3000).  This made it relatively quick.


The simple script did its job: it found an RMI registry on port 2999 and listed the single name bound to that registry: "jmxrmi".

It is quickest to use netstat, a similar tool, or logged output to determine a few likely candidate ports for the RMI port in question and then run the previously covered script against those.  However, the script demonstrated in this post could be used to check against an arbitrary range of ports for RMI-exposed services in a more automated (albeit slower) approach.  Another approach to automate this might be a script that runs a tool like netstat, parses its output, and tries only ports specified in that output that can not be ruled out as non-RMI ports.  But that is left for a possible future blog post.