Dieudonné
Dieudonné

Reputation: 561

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

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?

Upvotes: 12

Views: 11059

Answers (5)

holaktomas
holaktomas

Reputation: 21

I would extend https://stackoverflow.com/a/63693518/2252417...

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 :)

Upvotes: 0

mangala
mangala

Reputation: 31

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

Upvotes: 3

Manwej
Manwej

Reputation: 45

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.

Upvotes: 3

Jonathan
Jonathan

Reputation: 81

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"

Upvotes: 8

Ganesh Krishnan
Ganesh Krishnan

Reputation: 7395

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

Upvotes: 0

Related Questions