Language Design – things not to do 2

Don’t make the behaviour of your strings depend on the system time! (Java String hashCodes I’m looking at you).

It seems like this is new in Java7, and is for security reasons (mostly to stop DOS attacks on hashmaps). So perhaps it could have been abstracted? Instead of putting the code into String.class, call a native method for the string hash seed, and let the JVM control the String hashCode policy? It is yet another source of non-detrminism in the core language.

Using Jmock annotations with Junit 4

Recent versions of JMock have support for configuration by annotation using JUnit 4 MethodRule

package mypackage;
 
import org.jmock.auto.Mock;
import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;
import org.junit.Test;
 
public class TestMyClass {
   @Rule public final JUnitRuleMockery context = new JUnitRuleMockery();
   @Mock private MyCollaborator collaborator;
 
   @Test public void somethingHappensWhenSomethingElse() {
 
   }
}

Using proguard 4.8 with maven

The proguard/maven ecosystem seems to be in a bit of a mess. Luckily wvengen and github have stepped up, and released a fork of the com.pyx4me proguard maven plugin.

Anyone that wants to put stuff in maven central should check out this guide to putting stuff in maven central using sonatype.

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.6</version>
    <executions>
       <execution>
           <phase>package</phase>
           <goals><goal>proguard</goal></goals>
       </execution>
    </executions>
    <configuration>
        <libs>
            <lib>${java.home}/lib/rt.jar</lib>
        </libs>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.proguard</groupId>
            <artifactId>proguard-base</artifactId>
            <version>4.8</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>