My Blog

Welcome! What is this blog for/What will be blogged here? Well, frankly, only time will tell that ... ;-) The plan is to have stuff like ... what I plan to do/Interesting things that I want to share. My interests and hobbies ... and what I'm doing/not doing for it. Random thoughts/Opinions. Just about anything I feel like writing! have fun!

Wednesday, December 29, 2004

Eclipse Bug - Encapsulate Field

Found this bug in Eclipse today while using the Encapsulate field functionality.

Eclipse Version: Version: 3.1.0
Build id: 200412162000

Create this simple class in eclipse -

public class TestEncapsulate {

String a, b;
}

1) Select the Field a
2) Right-click and select Refactor -> Encapsulate Field.
3) Click Ok.
4) The following code is generated -

public class TestEncapsulate {

String b;
private int a;

/**
* @param a The a to set.
*/
void setA(String a) {
this.a = a;
}

/**
* @return Returns the a.
*/
String getA() {
return a;
}
}

Problems
a) The field was changed to a private field even though it was package-private earlier.
This is ok by me, since I typically keep the fields as private.

b) The data type was changed from String to int!!!
This is crazy!

The encapsulate field works fine when there is only one field delared in one line (String a;)
It breaks in the above code for both fields 'a' & 'b' declared in a single line and the fields are non-private (i.e., public, protected or package-private). The type of the field does not matter (of course, if the field type is int, point b above will not hold).

I have reported this Encapsulate field bug.

Blogger Stats

I checked my profile [and the older one] today and was surprised to see that it shows that the last entry in my blog was posted on Oct 28th! On checking the known issues page, realized that stats collection was switched off. Reminds me of the time stats was switched off at Sourceforge - it took a long time for it to be switched on again ...

Tuesday, December 28, 2004

Java 5.0 Crash

I was using the Eclipse Profiler Plugin to launch my application when the 5.0 JVM crashed.

Here's the information -
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

Eclipse Version: 3.1.0
Build id: 200412162000

Plugin: Eclipse Profiler
http://eclipsecolorer.sourceforge.net/index_profiler.html
Plugin Version: 0.5.33

And here's the crash message -
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# Internal Error (455843455054494F4E530E43505000FF), pid=2116, tid=2268
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode)
# An error report file with more information is saved as hs_err_pid2116.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

It created the log file in the project workspace folder. It contained Thread, Stack, Native frames, Heap, Dynamic Libraries, VM, Environment and System information.

Tuesday, December 14, 2004

Eclipse QuickFix problem

Encountered a strange problem while working on Eclipse [In the latest integration build - Version: 3.1.0 Build id: 200412081200]

I wrote a small snippet of code -

if(getContentSpec().equals("Test"))
return true;


The method getContentSpec was not implemented in the class; so it gave a compilation error. I took the QuickFix route and asked Eclipse to generate the stub for me. To my surprise, it generated the following code -

/**
* @return
*/
private AbstractList getContentSpec() {
// TODO Auto-generated method stub
return null;
}


I didn't really expect the method to return a String - but I at least expected it to return an Object. But it ended by returning an AbstractList!!!!! This was s t r a n g e!

To recreate the problem, before I submit the bug, I created a simple class -

public class QuickFixEquals {

public boolean hasChildren() {

return (getContentSpec().equals("Test"));
}
}
Applied QuickFix ... and the code generated was

private Object getContentSpec() {
// TODO Auto-generated method stub
return null;
}


Well, thats what I wanted in the original code ... why did it behave differently here?

I finally tracked it down to ... guess what? ... an import statement.

Try QuickFix on the following code

import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() {

return (getContentSpec().equals("Test"));
}
}
It will generate

 private List getContentSpec() {
// TODO Auto-generated method stub
return null;
}
Better yet, try this code

import java.util.ArrayList;
import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() {
return (getContentSpec().equals("Test"));
}

public List<String> getList() {
return new ArrayList<String>();
}
}


Apply QuickFix, and lo, you get -

private AbstractList<E> getContentSpec() {
// TODO Auto-generated method stub
return null;
}


Here's the link to the QuickFix Bug.

Sunday, December 12, 2004

Metrics Scoreboard

I put in a request in the Metrics project forum to create a Scoreboard, for interested projects, of Metrics data.

<Quote>
Can we have a site similar to the Scoreboard [1] maintained by the PMD site?

We could have the various metrics information, for the submitted projects, listed there.

It would be fun to add a few additional metrics -
1) Longest & shortest variable names.
2) Longest & shortest method names.
3) Longest & shortest class names.

The projects could be sorted on the (max) McCabe Cyclomatic Complexity OR (max) WMC and on the No of Lines of Code.

cheers
Conrad

[1] http://pmd.sourceforge.net/scoreboard.html
</Quote>

I've listed Kaprekar and Matra in the PMD scoreboard. Kaprekar is in the green with 0.08% unused code and Matra is in Yellow with 0.54%.

Friday, December 03, 2004

Languages based on the Java VM

I read the article "GJ: Extending the JavaTM programming language with type parameters" [by Gilad Bracha, Martin Odersky, David Stoutamire, Philip Wadler, March 1998; revised August 1998]. It introduces the GJ compiler that is an extension of Java (during the time of JDK 1.2) which provided generics support. The current generics support in Java 5 is based on GJ.

GJ, per the article, is based on Pizza. "GJ is based closely on the handling of parametric types in Pizza".

This led me to search around for Pizza and other languages based on the Java programming language.

The Pizza compiler is hosted on sourceforge. Its current version is 1.1 [released 03-Jan-2002].

The Pizza language is an extension to Java with three new features:

  • Generics (aka Parametric polymorphism)

  • Function pointers (aka First-class functions)

  • Class cases and pattern matching (aka Algebraic types)



The Pizza Tutorial explains the three new features listed above.

GJ - A Generic Java Language Extension - is currently on version 0.6m. It is a superset of the Java programming language and is compatible with existing libraries.

Bistro is a new programming language that integrates the best features of Smalltalk and Java. It is currently on version 3.5 [21-Apr-2002?]. You can read about Bistro in the language neutrality article.

Kiev is another language derived from Java. It was initially written in (and tries to be source compatible with) Pizza language. It is currently on version 0.09a.

You can check many more languages at the list of languages based on the Java VM.

Wednesday, December 01, 2004

JSR 260: Javadoc Tag Technology Update

JSR260 is tasked with upgrating the javadoc tag technology ... it will be available for public review in march end ... time to wait ...