The following Maven project demonstrates the problem on Netbeans 8.0.2 running on Oracle Java 8u51 x86_64 on Windows 8.1 (Ubuntu 14.04 x86_64 is seemingly not affected with the same Netbeans/Java platform):
package com.mycompany.lombokutilityclassbug;
@lombok.experimental.UtilityClass
public class MyUtilityClass {
void foo() { System.out.println ("hi"); }
}
.
package com.mycompany.lombokutilityclassbug;
import static com.mycompany.lombokutilityclassbug.MyUtilityClass.foo;
public class Main { }
.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>LombokUtilityClassBug</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.4</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
static void foo()?
@kazuki-ma @UtilityClass adds the static modifier
I hit this issue a lot and seems to break compilation in a way that is very hard to diagnose since it creates many noisy downstream errors.
This is also the case for @FieldDefaults(level=PUBLIC) when trying to import a static field
i've just hit this issue with lombok 1.16.6 and java 1.8
any workarounds or import static simply doesn't work?
any workarounds or import static simply doesn't work?
I have an interesting find.
Only when you statically import a named member, the compilation fails.
Adding a static _wildcard_ import _does_ work.
So I think it's got something to do with member resolution in javac?
Although, Netbeans with nb-javac doesn't complain, so it must be a bug in javac I suppose.
Although, Netbeans with nb-javac doesn't complain, so it must be a bug in javac I suppose.
Statically imported named members also work fine within Eclipse IDE (Neon).
I stepped on this rake too :(. Idea doesn't show syntax error, but javac floods screen with unrelated errors.
I'm also having this issue. Importing with wildcard solves the problem.
java: 1.8.0_131
lombok 1.16.8
@Shredder121
Although, Netbeans with nb-javac doesn't complain, so it must be a bug in javac I suppose.
I am leaning towards the opposite conclusion: this must be a bug in Lombok. I've only ever seen this bug when using Lombok. If this was a bug in javac, someone would have produced a testcase without the use of Lombok. Thus far, this does not seem to be the case.
Although, Netbeans with nb-javac doesn't complain, so it must be a bug in javac I suppose.
nb-javac uses the JDK9 compiler so you're right that it's possible javac's behavior changed between JDK8 and JDK9. One way to find out is to download JDK9 and try to compile this testcase from the command-line.
This is a duplicate of many, many bug reports. However, lombok cannot fix this.
See:
https://github.com/rzwitserloot/lombok/wiki/LOMBOK-CONCEPT:-Resolution
https://stackoverflow.com/questions/47674264/static-import-not-working-in-lombok-builder-in-intellij
I just ran into this, and it took quite some time to debug. When I have a failure, the last thing I suspect is a bug in my toolchain. Instead, I spend a lot of cycles looking for anything _I_ may have done wrong (did I put an unprintable character in there? Did I do some wrong capitalization, maybe of a file name? Did I this, did I that??). Imo, the build tools should be as rock-solid as possible.
If Lombok cannot fix this, it should require the static modifier in the code, or at _least_ emit a warning from its IDE plugins. Adding static is an easy workaround, doesn't add much text, and removes the possibility of hitting this bug.
And this _is_ a bug. The docs say:
_All_ members of a utility class are automatically marked as
static. Even fields and inner classes.
That's not true, because they don't work exactly as static members, in that they can't be static-imported.
Just spent my own afternoon dealing with this. Frankly, figured it out mostly by luck (because the static method errors were first in the list).
I'm totally ok with the notion that Lombok can't handle this, but please put it into the documentation and/or Javadoc on the annotation, in big, bold letters. I understand this is an experimental feature, but if this annotation combined with a standard Java feature makes the compiler go haywaire, it should be officially mentioned.
Duplicate of #2044
Most helpful comment
I have an interesting find.
Only when you statically import a named member, the compilation fails.
Adding a static _wildcard_ import _does_ work.
So I think it's got something to do with member resolution in javac?
Although, Netbeans with nb-javac doesn't complain, so it must be a bug in javac I suppose.