<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Bruce Chapman&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/" />
<modified>2008-03-26T09:24:36Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, brucechapman</copyright>
<entry>
<title>List Separators</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/03/list_separators.html" />
<modified>2008-03-26T09:24:36Z</modified>
<issued>2008-03-26T01:58:16Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.8489</id>
<created>2008-03-26T01:58:16Z</created>
<summary type="text/plain"> In his Disturbing Thoughts from a Developing Mind blog, fellow kiwi Mark Derricutt discusses a situation where new for loops don&apos;t provide enough power for a particular case. (And yes this blog has been sitting drafted but unpublished for...</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>
In his <a href="http://www.talios.com/writing_your_last_forloop__beautiful_code.htm">Disturbing Thoughts from a Developing Mind</a> blog, fellow kiwi Mark Derricutt discusses a situation where new for loops don't provide enough power for a particular case. (And yes this blog has been sitting drafted but unpublished for ages :(  )
</p><p>
The case in point is building a String from the concatenation of a List  of Strings with some separator between them, in this case a semi-colon.
</p><p>
The problem is expressed as "<em>append the separator after each element, except the last one</em>". What seems to have evaded Mark and his commenters is that the problem can be expressed differently.
</p><p>
If you restate the problem as "<em>append the separator before each item except the first one</em>" then you are one step away from what seems to me to be an elegant solution, at least compared to the others offered.
</p><p>
That final step is to realise that "<em>except the first one</em>" can be rephrased as <em>except the first one in which case you prepend nothing</em>".
</p><p>
Applying this to the relevant section of Mark's code yields
</p><pre>
StringBuilder sb = new StringBuilder();
String separator = "";
for (String listenerClassName : data.TEST_LISTENERS) {
    if (listenerClassName != null && !"".equals(listenerClassName)) {
        sb.append(separator).append(listenerClassName);
        separator = ";";
    }
}
</pre>
<p>
There is a more OOish solution, which is to have a (tiny) class thus
</p><pre>
public Class Separator {
    private String next = "";
    private String separator;
    public Separator(String separator) {
        this.separator = separator;
    }

    public String get() {
        String result = next;
        next = separator;
        return result;
    }
}
</pre><p>
which returns an empty string the first time get() is called, then the configured value thereafter.
<p>
With this we can code the loop as
</p><pre>
StringBuilder sb = new StringBuilder();
Separator sep = new Separator(";");
for (String listenerClassName : data.TEST_LISTENERS) {
    if (listenerClassName != null && !"".equals(listenerClassName)) {
        sb.append(sep.get()).append(listenerClassName);
    }
}
</pre>
<p>
So how do you tackle this problem?
</p>
]]>

</content>
</entry>
<entry>
<title>Hot Threads</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/03/hot_threads.html" />
<modified>2008-03-26T09:22:54Z</modified>
<issued>2008-03-26T01:02:00Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.9412</id>
<created>2008-03-26T01:02:00Z</created>
<summary type="text/plain">New Desktop machine - netbeans really really really slow to install - other java apps running really really really slow - JMX to the rescue</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Tools</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>
I'm setting up my new desktop development machine, and netbeans installation is atrociously slow, like several minutes just to display the splash screen. The task manager shows the process consuming 50% CPU (on a dual core). After stuffing around barking up several wrong trees I drag out a JMX based tool I wrote a while back to find hot threads in a running application.
</p><p>
I had previously encountered slow startup with Netbeans 5.5 (itself - not the installer) and based on A. Sundararajan's blog <a href='http://blogs.sun.com/sundararajan/entry/using_mustang_s_attach_api'>Using Mustang's Attach API</a> I had written a tool to output the stack traces for the three busiest threads in a java process.
</p><p>

<a href="http://weblogs.java.net/blog/brucechapman/archive/hotthreads/Main.java/Main.java">Here's the source code.</a> And for those that just need to do the same thing without understanding internals, <a href="http://weblogs.java.net/blog/brucechapman/archive/hotthreads/hotthread.jar/HotThread.jar">Download the jar file</a>
</p><p>
The program attaches to the local java process (specified by the PID on the command line), it grabs information about the processing time of all threads, twice 500ms apart, and uses that to find the three busiest threads. It then takes 10 stacktrace snapshots of those three threads at 10ms intervals, and looks for the common parts on those stack traces for each thread. If a thread is busy, normally most of the stack stays the same, and just the top part changes. The program then outputs to common parts of the stack traces. From there you can see which thread is running hot, and where it is.
</p><p>
So I enabled PID display in the Window's task Manager and ran the program. Here's what I saw...</p>
<pre style='color:white;background-color:black;padding:3em'>
C:\>java -jar C:\projects\experimental\HotThread\dist\HotThread.jar 3544
java.lang.UnsatisfiedLinkError: no attach in java.library.path
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: no
        at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190)
        at hotthread.Main.main(Main.java:52)
</pre>
<p>That was due to java's installation running the JRE's copy of java.exe, but it doesn't have some of the attach API support files, so you need to run the JDK version of java.exe. Trying again...</p>
<pre style='color:white;background-color:black;padding:3em'>
C:\>"C:\Program Files\Java\jdk1.6.0_05\bin\java.exe"  -jar C:\projects\experimental\HotThread\dist\HotThread.jar 3544
106.3% CPU Usage by Thread 'Swing-Shell'
  10/10 snapshots sharing following 10 elements
    sun.awt.shell.Win32ShellFolder2.getAttributes0(Native Method)
    sun.awt.shell.Win32ShellFolder2.access$600(Unknown Source)
    sun.awt.shell.Win32ShellFolder2$6.call(Unknown Source)
    sun.awt.shell.Win32ShellFolder2$6.call(Unknown Source)
    java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    java.util.concurrent.FutureTask.run(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

 1.6% CPU Usage by Thread 'RMI TCP Connection(9)-172.30.41.210'
  10/10 snapshots sharing following 32 elements
    sun.management.ThreadImpl.getThreadInfo0(Native Method)
    sun.management.ThreadImpl.getThreadInfo(Unknown Source)
    sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.sun.jmx.mbeanserver.ConvertingMethod.invokeWithOpenReturn(Unknown Source)
    com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(Unknown Source)
    com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(Unknown Source)
    com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(Unknown Source)
    com.sun.jmx.mbeanserver.PerInterface.invoke(Unknown Source)
    com.sun.jmx.mbeanserver.MBeanSupport.invoke(Unknown Source)
    javax.management.StandardMBean.invoke(Unknown Source)
    com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
    com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
    javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
    javax.management.remote.rmi.RMIConnectionImpl.access$200(Unknown Source)
    javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
    javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
    javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
    sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    sun.rmi.transport.Transport$1.run(Unknown Source)
    java.security.AccessController.doPrivileged(Native Method)
    sun.rmi.transport.Transport.serviceCall(Unknown Source)
    sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

 0.0% CPU Usage by Thread 'Reference Handler'
  10/10 snapshots sharing following 3 elements
    java.lang.Object.wait(Native Method)
    java.lang.Object.wait(Object.java:485)
    java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
</pre>
<p>So armed with this information, a quick search of the JDK bug database looking for "<code>sun.awt.shell.Win32ShellFolder2</code>" yields <a href='http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5033747'>Bug ID: 5033747 JFileChooser is very slow on Windows XP</a> but that is about JFileChooser which doesn't seem related to my problem, however the stack trace matches. One of the related bugs is <a href='http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050516'>Bug ID: 5050516 JFileChooser very slow in XP if directory contains large zip files</a> and a light turns on. I have some big zip files on my desktop temporarily while I set things up. In that bug it shows how to disable XP's feature of treating zip files as directories which seems like it might be the root cause.
</p><p>
So I disabled XP's horrible ZIP file handling (which would be marvellous if it wasn't so pathetically slow), and ... <i>Drum roll</i> ... netbeans was installed in a couple of minutes.
</p><p>
Thank you JMX. Maybe a hot thread detector would be useful in jconsole and <a href="https://visualvm.dev.java.net/">visualVM</a>.
]]>

</content>
</entry>
<entry>
<title>Announcement - &quot;No Closures&quot; prototype</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/03/anouncement_no.html" />
<modified>2008-03-10T23:45:30Z</modified>
<issued>2008-03-08T09:39:28Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.9127</id>
<created>2008-03-08T09:39:28Z</created>
<summary type="text/plain">It is with pleasure that I announce the availability of a prototype for &quot;No Closures&quot;.
</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>All the major closures proposals now have prototype implementations available. But until we can play with the final option "No Closures" we're not in the best position to make a good decision. So it is with pleasure that I announce the availability of a prototype for "No Closures".
</p><p>
With <a href="http://weblogs.java.net/blog/brucechapman/archive/downloads/rapt.jar">

this jar file</a> and JDK 6, you can effectively cast a method to a SAM type. For those not following the various closures proposals too closely, a SAM type is a "Single Abstract Method" type. That is, a class or an interface with only one method that is abstract.
</p><p>
So to cast a method to a SAM type, the method should have the same argument types and return type as the SAM, but it can have any name. It may NOT be private. You then annotate that method with <code>@net.java.dev.rapt.anon.As</code>, and specify the SAM type. </p><p>Here is a method declared to be castable as a Runnable
<blockquote><pre>
import net.java.dev.rapt.anon.As;

class MyClass {
    @As(Runnable.class)
    void slowStuff() {
        ... // whatever
    }
}
</pre></blockquote>
In order to cast that method to a Runnable, you do this
<blockquote><pre>
new Thread(Runnables.slowStuff(this)).start();
</pre></blockquote>
Thats right, you get the Runnable by calling a static method on the Runnables class, and pass the object that owns the method.
</p><h3>So how does this work?</h3><p>
In the jar file containing the annotation there is also an <a href="http://java.sun.com/javase/6/docs/api/index.html?javax/annotation/processing/Processor.html">annotation processor</a>. For each SAM type with at least one corresponding <code>@As</code> annotation in a package, it creates a class in that package whose name is the SAM type name with an "s" appended, hence Runnable SAM type -> Runnables.java created. That class has static methods which make anonymous inner classes that delegate to each of the methods in that package annotated with <code>@As(Runnable.class)</code>
</p><p>
Those generated static methods look like this
</p><blockquote><pre>
class Runnables {
    private Runnables() {}

    static Runnable slowStuff(final MyClass owner) {
        return new Runnable() {
            public void run() {
                owner.slowStuff();
            }
        };
    }
}
</pre></blockquote><p>
If you want to pass additional arguments to the method which are not part of the SAM, just annotate those with @As.Additional, and when you call the generated class, pass those arguments.
</p><h3>Example</h3><p>
Here is a small swing app that demonstrates things.
</p>
<blockquote><pre>
package asdemo;

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import net.java.dev.rapt.anon.As;

public class Main extends JFrame {

    JButton goButton;
    JLabel  label;
    
    public Main() {
        super("@As");
    }

    public static void main(String[] args) throws Exception {
        Main instance = new Main();
        // run instance's startUp() method on the EDT
        EventQueue.invokeAndWait(Runnables.startUp(instance));
    }
    
    @As(Runnable.class)
    void startUp() {
        setLayout(new GridLayout(2,1));
        goButton = new JButton("Go");
        goButton.addActionListener(ActionListeners.onGo(this));
        label = new JLabel("Gone");
        add(label);
        add(goButton);
        pack();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }
    
    @As(ActionListener.class) // ActionListener for goButton
    void onGo(ActionEvent e) {
        goButton.setEnabled(false);
        // run goBackground() in a background thread
        new Thread(Runnables.goBackground(this)).start();
    }
    
    @As(Runnable.class)
    void goBackground() {
        for(int i = 10; i >= 0; i--) {
            try {
                // call showStatus(i) on EDT 
                EventQueue.invokeAndWait(Runnables.showStatus(this, i));
                Thread.sleep(500);
            } catch (InterruptedException ie) {
                return;
            } catch(InvocationTargetException ite) {
                 ite.printStackTrace();   
            }
        }
    }
    
    @As(Runnable.class)
    void showStatus(@As.Additional int value) {
        if(value != 0) {
            label.setText("Going " + value);
        } else {
            label.setText("Gone");
            goButton.setEnabled(true);
        }
    }
}

</pre></blockquote>
<p>
This should compile with JDK 6. You will find the generated Runnables and ActionListeners classes whereever it is you tell javac to place generated classes (the -s option if used, otherwise in the same place as the compiled .class files).
</p>
<h3>What's Hot and What's Not</h3><p>
This is designed to be work correctly even if you do incremental compiles. The processor remembers all the SAMs for the project and keeps them up to date, even if you only compile classes one by one.
</p><p>
Currently this doesn't work for generic SAM types. That means you can't use it to cast a method <code>int compareStringLengths(String s1, String s2)</code> to a <code>Comparator&lt;String></code>. I am working on a version that will infer the type parameters and the SAM type returned from the generated class will have the correct type parameters, but that isn't ready yet.
</p><p>
I don't think this is as good as any of the closures proposals, except in one respect, you don't have to wait for JDK 7 to use it.
</p>

]]>

</content>
</entry>
<entry>
<title>BGGA FUD Busting - Part 1</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/02/bgga_fud_bustin.html" />
<modified>2008-02-27T08:52:02Z</modified>
<issued>2008-02-27T08:46:35Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.9250</id>
<created>2008-02-27T08:46:35Z</created>
<summary type="text/plain">I want to refute the FUD that function types are nameless and have no javadoc.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>Josh Bloch makes some interesting points in his Javapolis presentation on the closures controversy. However having listened to   the <a href='http://parleys.libsyn.com/index.php?post_id=290944#'>audio</a>  several times and read the <a href='http://www.javac.info/bloch-closures-controversy.ppt'>slides</a>     at least three times, I am having trouble extracting the salient points from all the <a href='http://en.wikipedia.org/wiki/Fear%2C_uncertainty_and_doubt'>FUD</a>
</p><p>
(The <a href='http://www.parleys.com/display/PARLEYS/The+Closures+Controversy'>presentation video</a> of the talk is now also available)
</p><p>
What seems to be happening is that much of that FUD is starting to spread. 
</p><p>
In this post I want to expose one of these items of FUD to some light and see how it really looks. Also I am hoping that having neutralised the noise, I might more easily extract some signal from Josh's talk. I think its there but I can't hear it just yet. 
</p><p>
At 13:06 into the sound track, Josh starts comparing interfaces to function types by first refering to <a href='http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166ydocs/jsr166y/forkjoin/Ops.Reducer.html'>these javadocs</a> for an interface and talks about it having a name, all known implementations, and documentation including semantic constraints. He then says </p><blockquote>"with functional types all you get is 'it takes two T's and gives you a T'. There's a lot less information there."</blockquote> 
<p>This presumably is in reference to where the types are used. Compare this <a href='http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166ydocs/jsr166y/forkjoin/ParallelArray.html#reduce(jsr166y.forkjoin.Ops.Reducer,%20T)'>version</a> of a method in the fork join library with <a href='http://www.javac.info/jsr166z/jsr166z/forkjoin/ParallelArray.html#reduce(info.javac.function.OOO,%20T)'>this one</a> using closures.
</p><p>
An Ops.Reducer is of no value except where it is used. Now with the non closures version, all we see in the javadoc for the reduce() method is the names of the type and parameter, whereas with closures we see the essential method signature, because that is the closure type, and the parameter name. The closure version tells me more because all I get without the closure is a type name and a parameter name, and if I want to know more I have to click a link to go find it. With the closure I don't ned to first follow the link.
</p><p>
Recently Stephen Colbourne tried to give more  <a href='http://www.jroller.com/scolebourne/entry/closures_lightweight_interfaces_instead_of'>impetus </a> to this FUD when he said
</p><blockquote>"A second complaint about function types is that there is no home for documentation. One of Java's key strengths is its documentation capabilities in the form of Javadoc."</blockquote>
<p>
To date I haven't seen anyone describe how the javadoc tool would work for closures, so let me suggest that when a method return type is a function type, or a method parameter is a function type, then the return and parameters of that closure type will be able to have nested javadoc associated with them.
</p><p>I would expect you'd find the javadoc for ParallelArray.reduce  () being something like
</p><blockquote>
<HR>

<A NAME="reduce(info.javac.function.OOO,java.lang.Object)"><!-- --></A><A NAME="reduce(info.javac.function.OOO, T)"><!-- --></A><H3>
reduce</H3>
<PRE>
public <A HREF="../../jsr166z/forkjoin/ParallelArray.html" title="type parameter in ParallelArray">T</A> <B>reduce</B>({<A HREF="../../jsr166z/forkjoin/ParallelArray.html" title="type parameter in ParallelArray">T</A>,<A HREF="../../jsr166z/forkjoin/ParallelArray.html" title="type parameter in ParallelArray">T</A>=><A HREF="../../jsr166z/forkjoin/ParallelArray.html" title="type parameter in ParallelArray">T</A>}&nbsp;reducer,
                <A HREF="../../jsr166z/forkjoin/ParallelArray.html" title="type parameter in ParallelArray">T</A>&nbsp;base)</PRE>

<DL>
<DD>Returns reduction of elements
<P>
<DD><DL>
</DL>
</DD>
<DD><DL>
<DT><B>Parameters:</B>
<DD><CODE>reducer</CODE> - the reducer. This function must be associative.
<blockquote><dl><dt><code>reducer returns</code><dd>The result of combining the two arguments in some way
<dt><code>reducer parameter 1</code><dd>The first argument to be combined.
<dt><code>reducer parameter 2</code><dd>The second argument to be combined.
</dl></blockquote>
<DD><CODE>base</CODE> - the result for an empty array
<DT><B>Returns:</B><DD>reduction</DL>

</DD>
</DL>
<HR></blockquote><p>
You could do that now, but some new javadoc tags to do the nested documentation would make life simpler.
</p><p>
For sure those are pretty terrible javadocs, I just made them up, but this demonstrates that the function type's javadocs can be just as rich as the nominal type's. 
</p><p>
Before you say it would get tedious writing out the same complicated javadoc at every place where you used a particular function type, let me say that the point at which it gets painful is probably the point at which you should consider using an interface rather than a function type, and the javadoc pain is your friend by helping you to see that.
</p><p>
And one last thing, Josh says that with an interface, you can find all the known implementations from the javadoc. Not so, you won't find the implementations that are anonymous inner classes. And those are exactly the sorts of places where you would use nominal types and closures. So that's not really an advantage of nominal types over function types in the places where you'd actually use them, it's just more FUD.
</P>]]>

</content>
</entry>
<entry>
<title>Continuations JSR dead</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/01/continuations_j.html" />
<modified>2008-01-24T21:46:03Z</modified>
<issued>2008-01-24T21:45:58Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.9052</id>
<created>2008-01-24T21:45:58Z</created>
<summary type="text/plain">No continuations yet. JSR 323 never made the first hurdle.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>JSR</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>So JSR 323 has failed the <a href="http://jcp.org/en/jsr/results?id=4516">review ballot</a>, which means it's out before first base. It never quite looked viable.
</p><p>
What is interesting is the <a href="http://jcp.org/en/jsr/results?id=4516">voting comments</a> from the JCP Executive Committee. It seems that the later voters are referring to voting comments made by earlier voters. Which means that the later voters can see the voting comments (and presumably the votes) made by the earlier voters BEFORE THEY VOTE. Is that a fair way to conduct a ballot?
</p><p>
As usual the boring part is IBM's comment (less the first paragraph)
</P>
<blockquote>"IBM's vote is based on the technical merits of this JSR and is not a vote on the licensing terms.  IBM supports licensing models that create an open and level playing field by allowing third parties to create independent implementations of Java Specifications and that do not allow individuals or companies to exercise unnecessary control for proprietary advantage.  We support open source as a licensing model for contributions in the JCP, and would hope others will support this direction. This comment is not necessarily directed at the current business or license terms for this JSR, however, it is a statement of IBM's preferred licensing model."</blockquote> 
<p>They make this same comment on every ballot. Sometimes it is slightly relevant. In this case at least it is completely irrelevant. So IBM, if the intended audience of your message hasn't got it yet, I doubt they ever will, for the rest of us (and I presume the message is not targeted at me), you're starting to sound pathetic.
</p><p>
When I voted Hani onto the JCP I did so because I wanted someone who'd call a spade a spade. I look forward to the day when Hani's votes are postfixed with something like
</p><blockquote>This vote is based on the technical merits of the proposal and not on whether or not IBM makes statements about licensing terms in their vote comments which admit to not necessarily being directed at the particular JSR being voted on.
</blockquote>
<p>Maybe if a few other EC members started playing the same silly game as IBM, then the childishness of it might become apparent to them.
</p><p>
And one last observation, Oracle gets two votes, one as Oracle, and one as BEA, although they only exercised one of those votes this time.
</P>]]>

</content>
</entry>
<entry>
<title>A JSR for Continuations?</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2008/01/a_jsr_for_conti.html" />
<modified>2008-01-09T00:43:10Z</modified>
<issued>2008-01-09T00:43:05Z</issued>
<id>tag:weblogs.java.net,2008:/blog/brucechapman/424.8949</id>
<created>2008-01-09T00:43:05Z</created>
<summary type="text/plain">If (newly announced) JSR 323 is serious, it looks like it might give us continuations.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>JSR</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>If (newly announced) <a href="http://jcp.org/en/jsr/detail?id=323">JSR 323</a> is viable, it looks like it might give us continuations.
</P><P>
If you can move a thread to another JVM and have it run there, you can also presumably move it to storage, pull it back onto the original JVM some time later, and have it continue execution.
</P><P>
This might be worth watching.


]]>

</content>
</entry>
<entry>
<title>Luddites - Watch Your Back</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2007/12/luddites_watch.html" />
<modified>2007-12-17T22:11:21Z</modified>
<issued>2007-12-17T21:54:11Z</issued>
<id>tag:weblogs.java.net,2007:/blog/brucechapman/424.8852</id>
<created>2007-12-17T21:54:11Z</created>
<summary type="text/plain">The closures controversy is attracting a number of commenters who seem to be opposed to any new java language features that are not completely understandable in less than one minute. While all this conservative energy is being directed at the closures proposals, there is possibly a larger threat to the values these folk hold to.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Programming</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>
Neal Gafter's latest <a href="http://gafter.blogspot.com/2007/12/what-flavor-of-closures.html">blog</a> on closures has attracted two or three comments from people wanting to object to generics, and a number of other conservative commenters voicing an objection to closures. <a href="http://www.javac.info/bloch-closures-controversy.ppt">Josh's JavaPolis</a> presentation makes a valid point that these opinions cannot be ignored.
</p><p>
I have invested some time getting my head around some (but not all) of the closures proposals. I don't know whether I find that easier or harder than your average practitioner, but with a little effort I can now relatively easily read and comprehend most example code.
</p><p>
I have also invested some time getting my head around the early draft  of <a href="http://jcp.org/aboutJava/communityprocess/edr/jsr308/index.html">JSR-308</a> and there are parts (like method receivers) of that which I just can't get my head around. Maybe I'm thick, or maybe the spec does not do a good job of explaining what is fundamentally a good idea, or maybe the idea is fundamentally wrong. I don't yet know. 
</p><p>
What I do know is that closures is not the only language proposal out there that can make a java program look foreign to those who can't or won't put in the effort required to internalize them. JSR-308 makes closures look simple, and its a lot closer, in terms of the JSR lifecycle, to becoming a part of the java language specification.
</p><p>
To all those who are voicing opinions against language changes that make java more complex, have you read the JSR-308 early draft? And have you sent your comments to the expert group?
</p>
]]>

</content>
</entry>
<entry>
<title>Closures and Multiple Return Values</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2007/11/closures_and_mu.html" />
<modified>2007-11-29T04:09:52Z</modified>
<issued>2007-11-29T04:00:03Z</issued>
<id>tag:weblogs.java.net,2007:/blog/brucechapman/424.8729</id>
<created>2007-11-29T04:00:03Z</created>
<summary type="text/plain">In javaposse 150 the guys were talking about something and veered off on a tangent talking about multiple return values and tuples and such like. Next up they talked about the closures JSR. That sparked a thought that maybe we could transform the multiple return values problem in order to solve it using closures.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>JSR</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>In <a href="http://www.javaposse.com/index.php?post_id=279012">javaposse 150</a> the guys were talking about something and veered off on a tangent talking about multiple return values and tuples and such like. Next up they talked about the closures JSR. That sparked a thought that maybe we could transform the multiple return values problem in order to solve it using closures.
</p><p>
So <strong>what if</strong> instead of returning multiple values, a method returned void, but had another formal parameter which was a <a href='http://www.javac.info/closures-v05.html'>closure</a> to receive the results of the method?
</p><p>
I've <a href='http://www.javac.info/'>downloaded</a> the closures prototype compiler (2007-11-20 version) and had a play with that idea. Now if it had been a complete disaster you wouldn't be reading this, because I wouldn't have blogged about it, but you are reading it so lets get on with it.
</p><p>
Here is a method to convert rectangular to polar coordinates and pass the results (r,theta) to a receiver closure.
</p>
<pre>
    static void toPolar(double x, double y, {double, double => void } rThetaReceiver) {
        rThetaReceiver.invoke(Math.sqrt(x*x + y*y), Math.atan2(y, x));
    }
</pre>
<p>
And this is how you use it
</P>
<pre>
        // test toPolar
        toPolar(3,4,{double r, double theta =>
            System.out.format("3,4 = %f<%fRad%n",r,theta);
        });
</pre>
<p>
Here is the complete class with both converters, and a round trip test. Note how the round trip nests the closures.
</p>
<pre>
package closures.multireturn;

/**
 *
 * @author bchapman
 */
public class RectangularToPolar {
    
    static void toPolar(double x, double y, {double, double => void } rThetaReceiver) {
        rThetaReceiver.invoke(Math.sqrt(x*x + y*y), Math.atan2(y, x));
    }
    
    static void toRectangular(double r, double theta, { double, double => void} xYReceiver) {
        xYReceiver.invoke(r * Math.cos(theta), r * Math.sin(theta));
    }

    public static void main(String[] args) {
        
        // test toPolar
        toPolar(3,4,{double r, double theta =>
            System.out.format("3,4 = %f<%fRad%n",r,theta);
        });
        
        // test toRectangular
        toRectangular(5, Math.PI / 2, { double x, double y =>
                System.out.format("5<90deg = %f,%f%n",x,y);
        });

        // test Round trip - toPolar and back to rectangular
        toPolar(3,4,{double r, double theta =>
            System.out.format("3,4 = %f<%fRad%n",r,theta);
            toRectangular(r, theta, { double x, double y =>
                System.out.format("%f<%fRad = %f,%f%n",r,theta,x,y);
            });
        });
    }
}
</pre>
<p>
And here's the output
</p>
<pre style='color:white;background-color:black;padding:3em'>
C:\projects\quickhacks\src>javac closures\multireturn\RectangularToPolar.java

C:\projects\quickhacks\src>java closures.multireturn.RectangularToPolar
3,4 = 5.000000<0.927295Rad
5<90deg = 0.000000,5.000000
3,4 = 5.000000<0.927295Rad
5.000000<0.927295Rad = 3.000000,4.000000
</pre>
<p>
This looks promising. I'll keep exploring.
</p>]]>
<![CDATA[<p>
One of the interesting things which I think this demonstrates is how closures are such a fundamental building block that they offer the potential of solving quite a few other <i>problems</i> that we've traditionally thought of as requiring specialist language changes. Maybe such solutions are not quite as nice as a specialist language change, but good enough that the advantage of not having <i>yet another language feature</i> outweighs the now small disadvantage of not having the <i>perfect</i> solution. 
</p>]]>
</content>
</entry>
<entry>
<title>Dear Santa - Exceptional Stuff</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/brucechapman/archive/2007/08/dear_santa_exce_1.html" />
<modified>2007-08-15T02:22:45Z</modified>
<issued>2007-08-15T02:22:37Z</issued>
<id>tag:weblogs.java.net,2007:/blog/brucechapman/424.8021</id>
<created>2007-08-15T02:22:37Z</created>
<summary type="text/plain">The start of a series requesting some goodies for later next year. This  first looks at stack trace improvements.</summary>
<author>
<name>brucechapman</name>

<email>bruce.chapman@nec.co.nz</email>
</author>
<dc:subject>Community: OpenJDK</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/brucechapman/">
<![CDATA[<p>Dear Santa,</p>

<p>My stack traces seem to have been getting less and less useful recently. Just to make myself perfectly clear, I am not talking about wrapping the sleigh reins around a chimney, which is what <strong>you</strong> might think of when you hear the words "stack trace". </p>

<p>So here are a couple of things I'd like your <a href="https://jdk7.dev.java.net/">seven</a> elves to work on please.</p>

<h4>Better messages in JVM thrown Exceptions</h4>

<p>First, can the JVM elves please use the information that is available when the JVM throws an exception to create a useful message. For instance, in cases of throwing a NullPointerException, could we please be told the type of the reference that is null, and what it is that can't be done to null.</p>

<p>For example, say you call <t>List.get()</tt> on a null reference, wouldn't it be nice to see something like this in the message<br />
<pre>Exception in thread "main" java.lang.NullPointerException: ((java.util.List)null).get()<br />
</pre><br />
or when accessing an element from a null array<br />
<pre><br />
Exception in thread "main" java.lang.NullPointerException: ((String[])null)[]</pre>Those are just suggestions, but having some more information in the message of JVM generated exceptions would make life a little bit more pleasant for me. I am sure I am not the only one who has spent far too long analysing a line of code that throws a NullPointerException trying to work out which reference is null, all the time overlooking the possibility that it was an Integer being used as an array index which was being autounboxed. A meaningful exception message would save an awful lot of wasted time.</p>

<p>As best I can tell this can all be done without actually changing any specs. There are a few related bugs and RFEs in bug parade that address little parts of this, but what I'd really like is for someone to go through the whole JVM Spec, look at each exception that can be thrown by each opcode, and put all the useful information (types and names) available to the JVM into the messages in some consistent notation.</p>

<h4>Context Identifiers in StackTraceElements</h4>

<p>This suggestion might be a little more controversial. Often the code that is being debugged to find the cause of an Exception is not java code, but some other form that has been converted into a composite data structure and is being "executed" (in loose terms) by java code that someone else wrote for an external library or framework.</p>

<p>Some examples are JSP or JSF pages and scripting language code being run by an interpreter.</p>

<p>What would be really helpful in these cases would be for the stack trace to include a small amount of contextual information associated with key objects in the stack. Wouldn't it be nice if you could see the JSP / JSF EL expression that was being evaluated when an Exception was thrown. Wouldn't it be nice to see the name and source line number of the XML elements that enclosed the element containing that expression? Wouldn't it be nice if you could see the line numbers of the javascript code that was being executed? Wouldn't it be nice if your own classes could add the contents of a String instance field to a stack trace element for specified methods of key classes.</p>

<p><u>Here's how it might work.</u></p>

<p>Add a new property to StackTraceElement to hold the context identifier.</p>

<p>Define a marker annotation (say <tt>@StackContext</tt>).</p>

<p>Use <tt>@StackContext</tt> to annotate the methods for which you would like the context identifier shown in the stack trace.</p>

<p>For any class with any methods annotated with <tt>@StackContext</tt>, annotate a <strong>single String</strong> field with <tt>@StackContext</tt> to identify the context value.</p>

<p>When a stack trace is being filled in, the JVM would look at each method on the stack, and if it was annotated with <tt>@StackContext</tt> then the <tt>@StackContext</tt> field would be accessed, and if non null, then the value of that field would be used to set the context identifier in the corresponding stack trace element. </p>

<p>Printing the stack trace would print the instance identifiers where they were non null.</p>

<p>Other details might include taking a prefix substring if the annotated field's value was too long (say no more than 40 characters), and only filling in the context identifier once for consecutive stack trace elements with the same "this".</p>

<p>Imagine.</p>]]>

</content>
</entry>

</feed>