06 Feb 2012

feedPlanetJava

Javable: YourKit Java Profiler 7.0 released

The major update to YourKit Java Profiler has been released. Version 7.0 includes

06 Feb 2012 11:01am GMT

Javable: Sun phases out mobile Java

Sun will gradually phase out mobile Java (Java Micro Edition) and move respective services to Standard Edition. "We're trying to converge

06 Feb 2012 11:01am GMT

Javable: Ruby on Rails 2.0 released

Ruby on Rails 2.0 has been released. "Rails 2.0 is finally finished

06 Feb 2012 11:01am GMT

Javable: NetBeans 6.0 released

New version of pure Java IDE has been released, with support for many new

06 Feb 2012 11:01am GMT

Javable: Java SE 6 Performance White Paper

Java SE 6 Performance White Paper includes detailed

06 Feb 2012 11:01am GMT

Javable: JUG.RU meeting

JUG.RU will held a scheduled meeting on Feb 23d. Read on for details.

06 Feb 2012 11:01am GMT

Javable: JUG.RU meeting on November 24th

JUG.RU will be hosting its meeting in Saint Petersburg, Russia, on November 24th. More details in our

06 Feb 2012 11:01am GMT

Javable: Happy New Year!

We wish a Happy New Year to all our readers and contributers. Hope to see you all in 2008.

06 Feb 2012 11:01am GMT

Javable: Google Android SDK is available

The development kit and API for Google mobile platform, Android, has been released.

06 Feb 2012 11:01am GMT

Javable: Consumer JRE Early Access

Sun has started an early access program to Java SE 6 Update N (formerly known as the "Consumer

06 Feb 2012 11:01am GMT

The Aquarium: POJOMapping in Jersey for type-safe clients

Over on his blog, Jason Lee has a detailed post on the new POJOMapping feature in Jersey/GlassFish which offers strongly-typed client API's and illustrates this with a GlassFish Cluster administration sample.

ALT_DESCR

The post shows how to enable POJOMapping with a Jersey servlet initialization parameter and goes on to show the Cluster domain model. An archive with the entire sample is available there.

06 Feb 2012 7:54am GMT

feedJavalobby - The heart of the Java developer community

Java.lang.VerifyError: Expecting a stackmap frame at branch target – JDK 7

Right now, when I try to persist an object in Google App Engine, I'm facing the error "Java.lang.VerifyError: Expecting a stackmap frame at branch target". I'm using JDK 7 and it seems like the problem lies with this JDK. After googling a bit, I found that there seems to be two solutions to fix this problem. Solution 1: Change to JDK 6 As simple as is, change your JDK to version 6 and you...

06 Feb 2012 5:51am GMT

Documentation that is useful

I was reading this article by Neil Mcallister on his Fatal Exception blog entitled "How to get developers to document their code". Now it begs the question: What documentation is actually useful? Well, like all things in general I don't think it's a simple answer, best I could say is; what works well in your context. Preview Text: I...

06 Feb 2012 5:49am GMT

Adding Version Information to your JAR’s Manifest

One of the handy things about using Maven is that, by default, the names of the artifacts it creates include the current version number from the POM's version tag. It doesn't matter what type of artifact it is, whether it's a JAR, WAR or EAR you generally end up with something like this: Preview Text: One of the handy things about using...

06 Feb 2012 5:46am GMT

A Simple Reminder for Maven/Gradle/Ivy Users: Proxy Central

Over the course of the past few years, I've interacted with hundreds of people when talking about build tools and repository management. It continues to surprise me how many people don't realize where these artifacts come from. When you run a build and these JARs just show up alongside all of their dependencies, it's like magic to most people. If you know how it works, it's very...

06 Feb 2012 5:39am GMT

Refreshing AppFuse's UI with Twitter Bootstrap

The last time AppFuse had an update done to its look and feel was in way back in 2006. I've done a lot of consulting since then, which has included a fair bit of page speed optimization, HTML5 development and integrating smarter CSS. It was way back in '05 when we first started looking at adding a CSS Framework to AppFuse. Preview Text: ...

06 Feb 2012 5:35am GMT

05 Feb 2012

feedJavalobby - The heart of the Java developer community

Building updated packages for sun-java6 6u30

Recently, Oracle withdrew the ability for Linux distributions to repackage Java and distribute their own packages. This has been widely regarded as a bad idea. I tend to agree. So, let's re-roll an old sun-java6 deb file, with a new content to contain the latest 6u30 java release. You will need: Preview Text: Recently, Oracle...

05 Feb 2012 4:41pm GMT

How To: Install graylog2 on CentOS 5 with RVM + Passenger

Graylog2 is an open-source self-hosted centralized log management tool. Think of it as a do-it-yourself version of loggly.com, or perhaps a simpler alternative to Splunk. Logs are stored in a MongoDB database. I won't go into too much detail, so if you want more info check out graylog2.org Preview Text: I decided to see if RVM - Ruby Version...

05 Feb 2012 6:00am GMT

Informer is dead: long live Informer!

Well, who'd have guessed it? After two long years, the new edition of Informer is finally out. Preview Text: Read several articles by search experts like Charlie Hull and Tyler Tate. A great resource for enterprise search followers. Mitchell Pronsc...

05 Feb 2012 5:59am GMT

The Best Default Setting is not to Have a Setting

It is easy to think that letting users change all aspects of an app UI makes the UI better. We've all heard the "if they don't like it they can change it" argument. It is also very easy to come up with theoretical scenarios where users would actually want to change any one aspects of the UI. Preview Text: It is easy to think...

05 Feb 2012 5:40am GMT

jOOX and XSLT. An XML love story, continued

The somewhat functional way of thinking involved with jOOX's XML manipulation cries for an additional API enhancement simply supporting XSLT. XSL transformation has become quite a standard way of transforming large amounts of XML into other structures, where normal DOM manipulation (or jOOX manipulation) becomes too tedious. Let's have a look at how things are done in standard Java ...

05 Feb 2012 5:38am GMT

04 Feb 2012

feedJavalobby - The heart of the Java developer community

Getting started with the Sensu monitoring framework

I'm excited about Sensu, a new open source monitoring framework, and I'd like to help others get started with it as well. So, after observing the frequent questions from new visitors to #sensu on Freenode I thought perhaps the best way to do that is to write a blog article to help folks get started. If you still have questions after reading this, feel free to come by #sensu on...

04 Feb 2012 10:42pm GMT

Using the Android Parcel

A short definition of an Android Parcel would be that of a message container for lightweight, high-performance Inter-process communication (IPC). On Android, a "process" is a standard Linux one, and one process cannot normally access the memory of another process, so with Parcels, the Android system decomposes objects into primitives that can be marshaled/unmarshaled across process...

04 Feb 2012 10:36pm GMT

Master/worker or P2P Grid? How about You choose?

What is possible? Simple master/worker topology In its initial design, JPPF is a distributed parallel processing framework based on a master/worker architecture. A JPPF grid is made of 3 sorts of components that communicate with each other: clients which submit the work to the grid, nodes which execute the work, and servers which receive the work from clients and distribute it to the nodes in...

04 Feb 2012 10:35pm GMT

I don't like NullPointerExceptions

I don't like NullPointerExceptions. Actually I don't like the message of NullPointer Exceptions, i. e. "null". Such a message is usually not very helpful. I created a few rules for myself how to avoid certain exceptions and actually define pre- and post-conditions for methods. Let me please give you a few examples. In the beginning of a non-private method I usually check all method...

04 Feb 2012 10:35pm GMT

Why does my Maven build suddenly fail?

I want to share something a software developer or operations guy every now and then encounters. And which I did yesterday. It all started with our nightly Maven build failing last Saturday Jan 28 on a java.lang.NoClassDefFoundError: javax/xml/bind/ValidationEventLocator The interesting snippet from the concole output from this build looked like this: Preview Text: ...

04 Feb 2012 10:19pm GMT

feedPlanetJava

Planet Eclipse: Stephan Herrmann: Help the JDT Compiler helping you! - 2: Resource leaks - continued

In my previous post I showed the basics of a new analysis that I originally introduced in the JDT compiler as of 3.8 M3 and improved for M5. This post will give yet more insight into this analysis, which should help you in writing code that the compiler can understand.

Flow analysis - power and limitation

An advantage of implementing leak analysis in the compiler lies in the synergy with the existing flow analysis. We can precisely report whether a resource allocation is definitely followed by a close() or if some execution paths exist, where the close() call is by-passed or an early exit is taken (return or due to an exception). This is pretty cool, because it shows exactly those corner cases in your implementation, that are so easy to miss otherwise.

However, this flow analysis is only precise if each resource is uniquely bound to one local variable. Think of declaring all resource variables as final. If that is possible, our analysis is excellent, if you have multiple assignments to the same variable, if assignments happen only on some path etc, then our analysis can only do a best-effort attempt at keeping track of your resources. As a worst case consider this:

  Reader r = new FileReader(f);
  Reader r2 = null;
  while (goOn()) {
     if(hasMoreContent(r)) {
        readFrom(r);
     } else {
        r.close(); // close is nice, but which resource exactly is being closed??
     }
     if (maybe()) {
        r2 = r;
     }             // at this point: which resource is bound to r2??
     if (hasMoreFiles()) {
        r = new FileReader(getFile()); // wow, we can allocate plenty of resources in a loop
     }
  }
  if (r2 != null)
    r2.close();

This code may even be safe, but there's no way our analysis can keep track of how many resources have been allocated in the loop, and which of these resources will be closed. Which one is the resource flowing into r2 to be closed at the end? We don't know. So if you want the compiler to help you, pretty please, avoid writing this kind of code :)

So what rules should you follow to get on terms with the compiler? To understand the mentioned limitation it helps to realize that our analysis is mostly connected to local variables, keeping some status bits for each of them. However, when analyzing variables the analysis has no notion of values, i.e., in the example the compiler can only see one variable r where at runtime an arbitrary number of Reader instances will be allocated, bound and dropped again.

Still, there are three special situations which the analysis can detect:

1
2
3
4
5
6
7
  Reader r = new FileReader("someFile");
  r = new FileReader("otherFile");
  r = new BufferedReader(r);
  Reader r2 = getReader();
  if (r2 != null) {
     r2.close();
  }
  1. In line 2 we're leaking the instance from line 1, because after the assignment we no longer have a reference to the first reader and thus we cannot close it.
  2. However, line 3 is safe, because the same reader that is being dropped from r is first wrapped into a new BufferedReader and indirectly via that wrapper it is still reachable.
  3. Finally at the end of the example snippet, the analysis can see that r2 is either null or closed, so all is safe.

You see the compiler understands actually a lot of the semantics.

My fundamental advice is:

If the compiler warns about leaking resources and if you think the warning is unnecessary, try to better explain why you think so, first of all by using exactly one local variable per resource.

Resource ownership

Still not every method lacking a close() call signifies a resource leak. For an exact and definite analysis we would need one more piece of information: who owns any given resource?

Consider a group of methods happily passing around some resources among themselves. For them the same happens as for groups of people: diffusion of responsibility:

Well, no, I really thought that you were going to close this thing?!!?".

If we had a notion of ownership we'd simple require the unique owner of each resource to eventually close that resource. However, such advanced concepts, while thoroughly explored in academia, are lacking from Java. To mitigate this problem, I made the following approximations of an ownership model:

  1. If a method allocates a resource, it owns it - initially.
  2. If a method obtains a resource by calling another method, it may potentially be responsible, since we cannot distinguish ownership from lending
  3. If a method passes a resource as an argument to another method (or constructor), it may or may not transfer ownership by this call.
  4. If a method receives a resource as a parameter, it assumes the caller is probably still responsible
  5. If a method passes a resource as its return value back to the caller, it rejects any responsibility
  6. If a resource is ever stored in a field, no single method feels responsible.
  7. If a resource is wrapped in an array we can no longer track the resource, but maybe the current method is still responsible?

In this list, green means: the compiler is encouraged to report anything fishy as a bug. Blue means, we still do the reporting, but weaken the message by saying "Potential resource leak". Red means, the compiler is told to shut up because this code could only be checked by whole system analysis (which is not feasible for an incremental compiler).

The advice that follows from this is straight-forward:

Keep the responsibility for any resource local.

Do not pass it around and don't store it in fields.

Do not talk to any strangers about your valuable resources!

In this regard, unclean code will actually cancel the leak analysis. If ownership of a resource is unclear, the compiler will just be quiet. So, do you think we should add a warning to signal whenever this happens? Notably, a warning when a resource is stored in a field?

The art of being quiet

Contrary to naive thinking, the art of good static analysis is not in reporting many issues. The art is in making yourself heard. If the compiler just rattles on with lots of uninteresting findings, no one will listen, no one will have the capacity to listen to all that.

A significant part of the work on resource leak analysis has gone into making the compiler quieter. And of course this is not just a matter of turning down the volume, but a matter of much smarter judgment of what the user might be interested in hearing.

By way of two recently resolved bugs (358903 and 368546) we managed to reduce the number of resource leak warnings reported against the sources of the Eclipse SDK from almost 100 down to 8. Calling this a great success may sound strange at first, but that it is.

At the level we reached now, I can confidently encourage everybody to enable this analysis (my recommendation: resource leaks = error, potential resource leaks = warning). The "Resource leak" problems indeed deserve a closer look, and also the potential ones could give valuable hints.

For each issue reported by the compiler you have three options:

  1. Agree that this is a bug
  2. Explain to the compiler why you believe the code is safe (unique assignment to locals, less passing around)
  3. Add @SuppressWarnings("resource") to tell the compiler that you know what you are doing.

But remember the nature of responsibility: if you say you don't want to here any criticism you'd better be really sure. If you say you take the responsibility the compiler will be the humble servant who quietly forgets all worries.

Finally, if you are in the lucky position to use Java 7 for your projects, do the final step: enable "Resource not managed with try-with-resource" analysis. This was actually the start of this long journey: to let the compiler give hints where this new syntax would help to make your code safer and to make better visible why it is safe - with respect to resource leaks.

Final note: one of the bugs mentioned above was only resolved today. So with M5 you will still see some avoidable false positives. The next build from now should be better :)

I'll be back, soon, with more on our favorite exception: NPE.

04 Feb 2012 8:11pm GMT

Java.net Weblogs: Night Dreams about NetBeans 7.1, etc.; Day Work Configuring CentOS Linux for JavaFX 2.1

Last night I dreamed seemingly all night about NetBeans 7.1, the JavaFX 2.1 Developer Preview, the JDK 6 and JDK 7 installations on my CentOS Linux system, Java threads, the JDK 7 Fork/Join framework, closures... and probably a few more things were in there too. That kind of thing happens to me sometimes after a late night of programming or development-related brainstorming.

Now, if these dreams happen when I have looming deadline, I usually consider it a nightmare -- because I'll often "work" all night "solving" some problem that doesn't exist in my day world. But I'm hoping last night's dreams will ultimately prove to have been at least a little bit productive. There were plenty of curious ideas mixed in there. I'll find out if any of it's useful over the next several days...

Day work: JavaFX 2.1 Developer Preview on Linux

It's daytime now, so I'll get down to some practical work. First, there's some good news for developers who want to try out JavaFX 2.1 Developer Preview on Linux: Linux Release Notes and installation instructions are now available (that wasn't the case when I wrote my Getting Started (Very Preliminarily)... blog post a couple weeks ago). Also, the 2.1 Developer Preview is has advanced to build b11 (I originally downloaded build b9).

The instructions for JavaFX 2.1 on Linux identify the following system requirements:

I'm running CentOS 5.5, not Ubuntu; my current JDK 6 is prior to update 26; and rpm -q gtk2 tells me that I have gtk2 Version 2.10.4-20.el5. Not the perfect starting point... But, my guess is that likely I'll be able to get a proper configuration in place.

The latest GTK2 that's available via yum for CentOS 5.5 is still in the Version 2.10 sequence. So, I downloaded the last stable GTK2 (Version 2.24.9), and tried installing it. The result of ./configure was a bunch of missing dependencies (too old a version of GLib, and missing atk, pango, cairo, and gdk-pixbuf-2.0). Using yum to see what prepackaged versions of these are available for my CentOS system, I found that in all cases the available packages predate the required versions.

Stepping back to GTK+ 2.18 would help some, but still the dependencies could not be met by simply using the yum package manager.

So, it's a dilemma. I'd like to try out the JavaFX 2.1 Developer Preview on my CentOS system, but there's a pretty big gulf between the CentOS 5.5 packages and what's required for JavaFX 2.1. Attempting big jumps in package versions can break a stable Linux system, in my experience. And the idea of upgrading to a newer operating system isn't all that appealing (that means downtime, and I do have development deadlines to meet). In addition, there are other things I'd like to be working on as well (such as experimenting with the performance differences between various strategies for efficiently utilizing multicore computers -- all that non-JavaFX stuff I was dreaming about last night).

I'll have to think about this for a while... Or, perhaps another night of Java-centric dreaming will provide a solution!


Java.net Weblogs

Since my last blog post, several people have posted new java.net blogs:


Poll

Our current java.net poll asks Under JCP 2.8, EC members lose their voting rights if they miss two consecutive meetings. Your view on this?. Voting will be open until Friday, February 17.


Articles

Our latest Java.net article is Michael Bar-Sinai's PanelMatic 101.


Java News

Here are the stories we've recently featured in our Java news section:


Spotlights

Our latest java.net Spotlight is Heather Van Cura's JCP 2.8 Spec Lead Materials & Adopt-a-JSR update:

Following the upgrade to the JCP 2.8 Program, the Program Office has made available the following materials for Spec Leads on the Multimedia page of jcp.org: -Transparency (December 2011 call) -JCP 2.8 Overview (October 2011 call)...

Previously, we featured Jasper Potts' Curve fitting and styling AreaChart:

I was experimenting today with extending AreaChart to do curve fitting for some example code I was hacking on. It is also a example of what can be done with styling JavaFX charts with CSS. Here is the result...


Subscriptions and Archives: You can subscribe to this blog using the java.net Editor's Blog Feed. You can also subscribe to the Java Today RSS feed and the java.net blogs feed. You can find historical archives of what has appeared the front page of java.net in the java.net home page archive.

-- Kevin Farnham

Twitter: @kevin_farnham

04 Feb 2012 6:28pm GMT

The Server Side: x += x++ * x++ * x++; Really? Just a little mock OCAJP exam question to get you thinking.

x += x++ * x++ * x++; Now that's a little annoying. You'd shoot a developer who worked that into a program, but it's they type of thing you'd see on a certification exam. Maybe it's a little too difficult for the OCAJP, the Associate exam from Oracle, but it's probably pretty good fodder for the new OCPJP exam for Java 7.



Add to digg Add to StumbleUpon Add to del.icio.us Add to Google

04 Feb 2012 2:13pm GMT

The Aquarium: Tab Sweep - Remote GlassFish on EC2, JavaEE 6 intro, Java 7 readiness, WADL, losing JCP voting rights, ...

Note: if you're reading this using a feedreader, please make sure you've updated to the updated TheAquarium feed.

Recent Tips and News on Java, Java EE 6, GlassFish & more :

Radio Receiver

Asadmin with Remote GlassFish (on EC2) (Bobby)

Easy OAuth using DaliCore and GlassFish (Joeri)

Introduction to Java Enterprise Edition 6 (JTV Technology Blog)

Container based authentication with JSPWiki, GlassFish and OpenDJ (Dave)

Exception "java.lang.IllegalArgumentException: object is not an instance of declaring class" And Solution (Adam)

JCP's Evolution into Openness Continues: Lost Voting Rights and JSR 355 (java.net)

Server side action methods on JSF ValueChange events using AJAX listeners (Lincoln)

Gentle introduction to WADL (in Java) (Tomasz)

Is your project ready for Java 7? (Dmitry)

XMPP/Vorpal Screencast: Are you there? (Chuk)

04 Feb 2012 1:37pm GMT

Planet Eclipse: Gunnar Wagenknecht: Eclipse at FOSDOM 2012

It's my first out of two days at FOSDEM 2012. It took us quite a ride to get from the hotel to the ULB. We tried to order a taxi but the people at the reception told us that it would take at least 1.5 hours till a taxi arrives. Luckily, Mike and Andrew know someone who has been at FOSDEM a couple of times before. He guided us safely to ULB using a combination of walking, metro, tram and more walking.

We quickly setup an Eclipse stand over there and Mike, Andrew and myself are showing demos and talking to people. BTW, thanks to the FOSDEM organizer to have it well prepared so that we just needed to setup our banner and our notebooks for the demos.

So far we have a great mixture of questions from developers using Eclipse for their day-to-day work, programming questions of Eclipse plug-in developers and people interested in Orion. There are also people stepping by that have no questions - they introduce themselves as happy Eclipse users and appreciate what the committers of the various projects have built over time. Thanks for those kind words folks!

3-IMG_1243 1-IMG_1241 2-IMG_1242 4-IMG_1246

Share on Facebook

04 Feb 2012 1:35pm GMT