"log has private access" error when using Slf4j annotation and Lombok in IntelliJ
Asked Answered
E

5

12

I'm using Lombok to add logging to my Java applications. I've been using this for some time, but since I upgraded my IDE from IntelliJ 13 Community edition to 14 Ultimate, I get the following compile errors (using maven):

error: log has private access in SesameServer

This error originates in a subclass of SesameServer:

@Slf4j
public class AnnotatorServices extends SesameServer {

  @Override
  protected void initialiseRDFStoreManager(Series<Parameter> parameters) throws RepositoryConfigException, RepositoryException {
      log.info("<< ------ Annotator Services ------- >>");
  }
}

Of course SesameServer also uses the @Slf4j annotation to add logging. The @Slf4j annotation adds the line:

 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SesameServer.class);

to the class in which it is used (both SesameServer and AnnotatorServices where SesameServer.class is of course replaced by AnnotatorServices.class). Apparently the compiler thinks I want to use the log variable from SesameServer instead of AnnotatorServices (both classes have variables with the same name).

How can I prevent this problem, i.e. that the SesameServer.log is used instead of AnnotatorServices.log?

Esme answered 12/2, 2015 at 14:40 Comment(9)
AnnotatorServices.this.logStagger
rebuild, this should work as is.Nepali
@xTrollxDudex Unfortunately no.Stickybeak
@RC. Normally I'm using maven for compilation. If I do a rebuild in IntelliJ I still get the same errors, but with som extra information: Warning:(23, 8) java: Can't initialize javac processor due to (most likely) a class loader problem: java.lang.NoClassDefFoundError: com/sun/tools/javac/code/TypeTags at lombok.javac.Javac.<clinit>(Javac.java:104) at lombok.javac.handlers.HandleGetter.<clinit>(HandleGetter.java:294)... Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.code.TypeTags at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ...Stickybeak
My advise, check for update (intellij and lombok plugin), clear all intellij caches, restart intellij and let it rebuild, you might have something bad in your caches.Nepali
@RC did not work unfortunately. But it definitely is a IntelliJ problem. I can compile without errors or warning on the command line.Stickybeak
code.google.com/p/projectlombok/issues/detail?id=451 I bet :)Nepali
@RC Yes that was it! Many thanks ;D - we used an older version of lombok because of some other issues, but upgrading to the newest version did solve this problem.Stickybeak
Google Code link above is now at github.com/rzwitserloot/lombok/issues/524Giovanna
H
8

NOTE: This still comes up for anyone else googling this error message; so adding my fix hope this helps.

I had a similar issue after reopening a project from pom.xml.

Since my parent class SesameServer was already built in a different module and used a dependency; when I compiled my AnnotatorServices I also saw the error: log has private access in SesameServer


To fix it I just had to turn on Annotation Processing for the module containing AnnotatorServices.

In IntelliJ Community 2017.1.6 the check box was found under:

  1. File -> Settings
  2. "Build, Execution Deployment -> Compiler -> Annotation Processors"
  3. Tick the "Enable annotation processing"
Honan answered 29/1, 2019 at 2:24 Comment(0)
W
3

Following steps worked for me

  1. Install Lombok Plugin in Settings=>plugins under Marketplace search for Lombok and install.
  2. Then in IntelliJ Community 2017.1.6 go to File->Invalidate Caches/ Restart and click on both.

Did the trick for me. All the best.

Wilhelmstrasse answered 18/8, 2020 at 14:9 Comment(0)
A
3

Make sure your subclass is also annotated properly with @Slf4j.

Ardis answered 1/9, 2020 at 18:32 Comment(0)
B
0

Update your lombok plugin. Sometimes idea does not display the new updates so goto settings => plugins and search for "lombok" Click "update" and restart idea

Bleeder answered 27/5, 2016 at 5:40 Comment(1)
I tried it, but still problem persists. Any other ideas please? Thanks.Iorgos
H
0

I would extend https://mcmap.net/q/934929/-quot-log-has-private-access-quot-error-when-using-slf4j-annotation-and-lombok-in-intellij...

Make sure you have a proper import for the @Slf4j in the class where you experience the error.

It also happened to me when I used import groovy.util.logging.Slf4j;. It needed to be replaced by import lombok.extern.slf4j.Slf4j;

Issue was introduced by applying the 1st import suggestion by the Intellij :)

Hangeron answered 3/1 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.