Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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?

like image 677
Dieudonné Avatar asked Feb 12 '15 14:02

Dieudonné


2 Answers

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"
like image 50
Jonathan Avatar answered Nov 05 '22 00:11

Jonathan


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.

like image 22
Manwej Avatar answered Nov 05 '22 01:11

Manwej