peichhorn/lombok-pg — Issue #45: Very serious javac bug
Author: nicholas22
Created: 2011-11-03 16:14:41+00:00
State: open

I've spent the last 3/4 hours trying to track what's going on with a very serious compile-time bug, I hope this can be resolved in the near future. The reason I spent so much time is that this somehow causes the javac compiler to report an error (Compile failed; see the compiler error output for details) but the 'great' thing about it, there is not freaking compiler output, it just crashes or something. ECJ is not affected by it thankfully. Anyhow, here's how to reproduce:

public static void addHandler(Function1 handler)
{
}

public static void main(String[] args) throws Exception
{
val handler = Object.class.getDeclaredMethods()[0];
addHandler(invokeMethod(new Main(), handler));
}

Ugly workaround which must be purged from this earth:

import lombok.ExtensionMethod;
import lombok.Functions.Function1;
import lombok.val;
import static propel.core.functional.projections.InvokeOneArg.invokeMethod;
import propel.core.functional.projections.InvokeOneArg;

public static void addHandler(Function1 handler)
{
}

public static void main(String[] args) throws Exception
{
val handler = Object.class.getDeclaredMethods()[0];
addHandler((Function1)InvokeOneArg.invokeMethod(new Main(), handler));
}

They both use this method:

@Validate
public static Function1 invokeMethod(@NotNull final Object obj, @NotNull final Method method)
{
return new Function1() {

@SneakyThrows
public Void apply(Object arg)
{
try
{
method.invoke(obj, arg);
return null;
}
catch(InvocationTargetException e)
{
// get rid of wrapper exception
throw e.getCause();
}
}
};
}