Blog

Lambda analysis hack no longer working in Java 12

Geschrieben 2018. Versionen und Details können veraltet sein.

To get errors at compile time I'm using java function references to refer object based queries. Since it is not possible to lookup the referenced function name (in fact a stupid behaviour) I was forced to use a hack to get the referenced name.

Now it looks like neither the hack nor any other way exists to get the function name in java 12 (and maybe in earlier versions). I tested the current openjdk12 against my tool and it looks like it's not working.

Therefore I switched the way to save my code consistency. The alternative way is to generate classes which are containing information about the existing function names.

A maven plugin analyses existing classes and generates new ones. The generated classes will only be updated if the content has changed. In this way it is possible to commit the classes to the software repository.

To switch your project you need to add the plugin configuration to your pom:

<plugin>
<groupId>de.mhus.lib</groupId>
<artifactId>constgenerator-maven-plugin</artifactId>
<version>${mhulib.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>const-generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>de.mhus.lib</groupId>
<artifactId>mhu-lib-annotations</artifactId>
<version>${mhulib.version}</version>
</dependency>
</dependencies>
</plugin>
And mark the concerning classes with the annotation @GenerateConst and rebuild the project to generate the new classes. They will be generated next to the corresponding root class, with an underscore added to the class name.
Use the static fields to refer the function names.