Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

BeanLint: A JavaBeans troubleshooting tool, Part 2

Put JavaBeans to the test

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
In last month's JavaBeans column, "BeanLint: A JavaBeans troubleshooting tool," we discussed various problems that may cause JavaBeans to fail -- either not loading into a development environment or, even worse, failing at runtime. We also introduced a troubleshooting tool called BeanLint, which analyzes class files and reports these potential problems. (To get the most out of what's being discussed here, you should read last month's column first; it describes some potential problems JavaBeans might have, and begins to describe how BeanLint works.)

Why BeanLint is important to beans developers

BeanLint is interesting to JavaBeans developers for two reasons. First, it's obviously preferable to find out about bugs in your software during development or testing, rather than from customer service. The second reason this topic is interesting is that it uses several new and/or advanced features of the Java platform, and, as such, provides good working examples of how to use those features.

Last month's topics included examples and a discussion of how to use package java.util.zip to read the contents of a jar file, and it covered the creation of a custom ClassLoader class to convert the jar file contents into usable Java classes. This month, we'll see how BeanLint uses the package java.lang.reflection (a relatively new package introduced in Java 1.1) to analyze class files and look for potential problems.

We'll have an in-depth look at a potential pitfall in Java's object serialization, and go over the solution BeanLint offers. Finally, we'll show how to use the package java.beans.Introspector (part of the standard Java package java.beans) to produce a report of all of the properties, event sets, and other JavaBeans-related attributes of any class file that passes all the tests. But before we start, I'd like to respond to some reader mail.

Several people have said they like the way I've been using scrollable text areas to show code examples in a compact way. Others say they don't like it because the articles, when printed, don't show all the code. Some have made both observations. One of my mottos is, Why choose when you can have both? So, I've continued to put the code in the scrolling text boxes, but any classes or programs I've written will also be accompanied by a link to a printable form of the source. Please write and let me know if this solution doesn't address your concerns.

Checking up on our beans

BeanLint's basic approach to finding potential problems in a class file is to load the file as a class, and then perform a series of checks on the class that look for these problems. Last month, we looked at how to get at the bytes that represent a class file, and then how to convert that byte stream into a class. Now, we'll get into the nitty-gritty of detecting potential problems in our beans. Several of these potential bean flaws have to do with properties of the class methods. The list below covers potential bean problems that can be detected by analyzing a class's methods, and describes how to detect that problem.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Get down to the nitty-gritty of serialization in my previous JavaBeans column "Serialization and the JavaBeans Specification" (February 1998), at http://www.javaworld.com/javaworld/jw-02-1998/jw-02-beans.html
  • Also see "Serialization grab bag" (April 1998), at http://www.javaworld.com/javaworld/jw-04-1998/jw-04-beans.html
  • The documentation for interface java.io.Serializable can be found at http://java.sun.com/products/jdk/1.1/docs/api/java.io.Serializable.html.
  • Download the source for this month's column at http://www.javaworld.com/jw-01-1999/beans/BeanLint.html