Tuesday Aug 14, 2007

The sound of a bone file

It has been hard to work today. Yesterday I had oral surgery because my jaw bone grew out of the gum! It started out as a sore spot in my mouth, which grew to a bulge, and a week ago the gum ruptured and the jaw bone shone like a bright white spot...

It turned out that when I pulled a molar many years ago the Swedish dentist I went to didn't do a very good job, so yesterday they had to "fix" it. The fix was to cut open my gum and using a bone file to get rid of the outgrowth. When he was filing away on my jaw the sound resonated in my skull - not a very nice sound!

The Brazilian dentist who performed the surgery was excellent! He is a 4th generation dentist working with his father, which is very uncommon in Sweden. They are both exceptionally good and if you ever need to fix your teeth while in Rio drop me a line and I'll give you their name.

Eight stitches later we were sent home with a list of medications and procedures to follow, my wife had to pull a tooth - she have (had) 34 teeth. The one that got pulled was some strange pre-historical tooth appearing behind the molars. The only good thing about all this was that we were told to eat ice cream, lots of ice cream!

What amazed me the most with the dentist was that he gave me the number to his home and to his mobile and told me to call if there was any problem or if I had any questions! That never happens in Sweden. He even called in the evening to check up on us. Talk about good service!

So today I've had a throbbing pain in my jaw which no amount of ice cream could get rid of. It has been hard concentrating on the work at hand: writing a set of script to run bart on all our Solaris 10 systems and generating alerts when there is a discrepancy. Not something which is very hard, but today I can't focus very well...

Friday Aug 03, 2007

Bye, bye Java - welcome back Solaris!

As of this week I am no longer working in the Java SE Security Team. I got tired of fixing other peoples' mistakes - I have a hard enough time fixing my own! It was a great place to work at, lots of clever, nice and cool people, but my job wasn't all that I thought it would be...

So what do I do now? I'm the security geek for .Sun engineering (DSE - Dot Sun Engineering), the group who run and operate most of Sun's external systems - like this one (blogs.sun.com).

My main focus is Solaris security, but I will also help the development teams to review the application security. I'm responsible for the security of the Solaris servers which run all the external sites - so that'll keep me busy :)

This mean that I now have legitimate reasons to play with Solaris Auditing again, so I've already started to help Tomas to alfa test the Remote Audit Trail Storage project. DSE will be a good test bed to see how well the project scales.

[Technorati Tags: ]

Monday Mar 05, 2007

Stupid ways to check the condition of a boolean

I thought I had seen most things, but yesterday was given some code snippets (not produced at Sun) on how you can make things much harder than they really are.

Say that you want to check the condition of a Boolean. Most people would use

if (b) {
    // do stuff

But someone didn't think that was clear enough, so they used

if (b != false) {
    // do stuff

I though that was pretty bad, but then this masterpiece appeared

if (b.toString().length() < 5) {
    // do stuff

How on earth did they come up with that? The worst thing is that it is supposed to come from a real code base. I pity the ones who have to maintain it!

Sunday Feb 11, 2007

Finding a needle in a haystack

I've spent too much time today debugging a problem in a test application which uses the javax.persistence API. The problem is that I added about 15 new persistent classes, and got the following exception:

java.lang.IllegalStateException: During synchronization
a new object was found through a relationship that was
not marked cascade PERSIST

How useful is that? Why couldn't the exception contain the object which wasn't marked PERSIST? In which of the all the classes I added did I make an error?

Much, much later, I found the root cause. I had forgotten to add cascade=CascadeType.ALL on one of the @OneToMany annotations!

This is how it looked:

private Set<Foo> foo = new HashSet<Foo>();

And by adding cascade=CascadeType.ALL it works again:

@OneToMany(mappedBy="foo", cascade=CascadeType.ALL)
private Set<Foo> foo = new HashSet<Foo>();


[Technorati Tags: ]

Tuesday Jan 09, 2007

My first use of an Annotation

I made use of an Annotation for the first time today, and it was a very pleasant experience!

I have a number of classes which all extend the same abstract class. These classes have a number of public getter methods, and some of the getter methods are used to retrieve values which I want to display in a GUI. The problem was how I should distinguish between these and the other getter methods.

First I thought I'd use reflection, but then I'd have to name my printable getters in a similar way, which didn't feel right.

So I thought I would check out that new thing called annotations, and it fit the bill perfectly! I could even add a field to deal with the order they should be sorted.

I started by creating my annotation like this:

package example;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public @interface Printable {
    String displayName() default "";
    int sortOrder() default 0; // sort the items in ascending order

Now I can annotate all methods in my sub-class which I want print:

public class SubClass extends AbstractClass {
    @Printable(displayName = "Execute command", sortOrder = 1)
    public String getCmd() {
        return this.cmd;

And finally I can the the following code snippet to print subClass. Note that I've skipped the sorting.

public void classPrinter(AbstractClass c) {
    for (Method m:c.getClass().getMethods()) {
        if (m.isAnnotationPresent(Printable.class)) {
            Printable p = m.getAnnotation(Printable.class);
            String displayName = p.displayName();
            System.out.println("displayName = " + displayName);
            int i = p.sortOrder();
            System.out.println("sortOrder = " + i);
            String result = m.invoke(c, (Object[]) null); // get value
            System.err.println("result = " + result);

[Technorati Tags: ]

Tuesday Dec 05, 2006

An easier way of installing Nevada in Parallels on Mac OS X

As you might have seen from the Installing Nevada in Parallels on Mac OS X blog entry, it required a lot of tinkering to get Nevada installed in Parallels. I've found an easier way to do it!

When you boot Parallels using your Nevada DVD image, immediately hit the "e" key when the grub menu appears, then hit "e" again to edit the boot command. Add ",atapi-cd-dma-enabled=0" to the end of the line, so it reads

kernel /boot/multiboot kernel/unix -B install_media=cdrom,atapi-cd-dma-enabled=0

Then hit return to save it and the "b" key to boot using the new option.

[Technorati Tags: ]

Monday Nov 27, 2006

Sun Certified Java Programmer

Last Friday I passed the SCJP exam! I got 69% of the questions right, and you need 59% to pass.

I'm helping my boss to validate the quality of SCJP and SCJD, and unfortunately I had to rush things a bit with the first exam - I have to provide feedback for both exams by the middle of December, and the second certification takes a lot longer to do than the first, as it is a programming task. I am taking both exams just as if I were a regular customer. No hints on the answers and no help you could not get.

I bought the book Complete Java™ 2 Certification and read chapters 1 to 9, which covers everything you need to know to pass the SCJP exam. As far as I can tell, the book covers the exam topics very well - it should, as the authors wrote the exam questions. The exam covers seven sections:

  • Declarations, Initialization and Scoping
  • Flow Control
  • API Contents
  • Concurrency
  • OO Concepts
  • Collections/Generics
  • Findamentals

First I was stunned at all the things you have to know, I knew most of them - but far from all, and thought it was a bit excessive. I even got worried that I would not pass the exam! :-)

To get a feel for my Java background, I'll give you a short overview: I've been hacking Java on and off for over 11 years, even before it was publicly available as I did alpha testing of the Mac OS JVM for Java 1.0, but as it hasn't been my day job until I started at the Java SE security team, so I can't compare myself to my peers (like Andreas who is a brilliant Java hacker).

The only critique I have of the SCJP exam is that it required a bit too much of API knowledge. I use NetBeans when I write code, and it takes care of that for me, which was reflected on my score in the API section of the exam, where I only got 50% (my lowest score of all sections).

I'm not saying that you don't need to know what classes there are in the core libraries, but you don't need to know the exact class name and method name, you can look that up. Who writes code without access to the documentation? E.g. in the java.util.Scanner class, is the method which read the next available integer value called getInt() or getInteger()? I don't know - I look that up in NetBeans!

I think the API questions should be more around what types of classes there are, and what functionality they provide. Like that a Map takes a key/value pair, while a Set only takes an element - rather than knowing the verbatim class and method name. Depending on what you are focused on, you will have dealt with some parts of the API more than others.

But my final word to those of you who are SCJP - you really know the Java language, no doubt about it! Now I need to start working on my programming assignment for the SCJD...

[Technorati Tags: ]

I've been diagnosed

I chatted with Darren today, and pointed out my inability to get things done without a deadline. He diagnosed me with attention deficit disorder, and which he also correctly noted, is a priority inversion or scheduling problem to us software engineers :)

Tuesday Nov 14, 2006

Booth duty

I'm doing booth duty at Øredev and I'm stunned that many students don't know that Sun created Java!

I think someone at marketing should be spanked :)

Thursday Nov 02, 2006

Mercurial on Blastwave

I've just completed packaging Mercurial for Blastwave, and as soon as I've had some people try it out (let me know if you want to help), I'll let Phil know it is ready to be go on the downloadable list.

[Technorati Tags: ]

A new gadget

I've just ordered an Optimus mini three keyboard from Think Geek. A friend of mine is bringing it to Europe, so I can evade VAT and import taxes ;)

Monday Oct 02, 2006

Changing your uid on Mac OS X

Since I'm going to turn my brand new Ultra 40 into a NFS server, I have to match the uid on Mac OS X with Solaris.

Being an UNIX geek, I immediately created a temporary admin account and ran sudo vi /etc/passwd only to be baffeled by the fact that the user martin wasn't there! Then I glanced at the comment at the top of the file. It turns out that /etc/passwd is only used when you boot into single user mode, instead I should be looking using the NetInfo program.

Once my uid and gid had been changed, I ran two onliners to change the user and group of all files and directories I own:

# find / -user 501 -print0 | xargs -0 chown -h martin
find: /dev/fd/3: Bad file descriptor
# find / -group 501 -print0 | xargs -0 chgrp -h martin
find: /dev/fd/3: Bad file descriptor
And I could log out of my temporary admin account and start using my normal account again.

Where to find a 0.5 meter SFF-8484 to SFF-8484 cable in Sweden

I need to buy a 0.5 m SFF-8484 to SFF-8484 cable, but have been unable to find a company in Sweden which sell them. If you know of a place, please drop me a line at martin.englund@sun.com

Tuesday Sep 26, 2006

Migrating from TeamWare to a new SCM

I've just posted a blog entry at java.net about how we are investigating how to migrate from TeamWare to a new SCM.

[Technorati Tags: ]

Wednesday Sep 20, 2006

Filling my new U40 with over 2TB for only $680

When I get back to work in Sweden on Monday, I will have a brand new Ultra 40 waiting for me!

Earlier today I stood at Fry's pondering what disks to fill it with, and I was going for something with a good $/GB ratio. Then I spoted some 400 GB Seagate disks, for only $113.99 (due to a $76 discount), but they "opened items". This means that someone bought it before me, took the disk home opened the box and used it, but later returned it. However when it was returned it was tested, and it still comes with the full 5 year warranty.

My first thought was "I'm not gonna by that, I don't know how the disks have been handled", but then I realized that I'm going to use RAIDZ2 on them, and ZFS will take care of the data integrity, so I don't have anything to worry about.

I only bought two disks, but I just decided that I'll get up to 4 more if I can. That'll give me over 2 TB for only $680! :)

[Technorati Tags: ]




« July 2016