What does “Maybe be a local package” mean? (IDEA Inspection)

I used IntelliJ for the "Inspect Code", and one of its results:

Overview of the problem May be local (on line 18 (public class HeartBeat) )

What does this mean, how can I fix it?

this whole class is as follows:

 package com.xxxxxxxxxxx.app.xxxx; public class HeartBeat { private static final Logger LOG = LoggerFactory.getLogger( HeartBeat.class ); private final File heartBeatFile; public HeartBeat( File heartBeatFile ) { this.heartBeatFile = heartBeatFile; } public void beat() { try { FileUtils.writeStringToFile( heartBeatFile, String.valueOf( System.currentTimeMillis() ) ); } catch( IOException e ) { LOG.error( "Error while writing heart beat log", e ); } } } 
+45
java intellij-idea code-review
Jun 06 '15 at 2:55
source share
5 answers

IDEA refers to package-private visibility.

A class can be declared using the public modifier, in which case this class will be visible to all classes. If the class does not have a modifier (by default, also known as private-package), it is displayed only within its own package

For more information, see Managing Access to Class Members .

You can solve this problem by removing the public keyword from the class (if the class is not intended to be used outside the package) or by using the class from another package.

+74
Mar 26 '16 at 10:52 on
source share
— -

If you want to stop this warning:

  • Go to "Settings" → "Editor" → "Inspections"
  • Go to Java → Reservation Declaration
  • Select "Access to declaration may be weaker."
  • Uncheck the box "Offer local visibility package ..." to the right
+67
May 9 '16 at 10:03
source share

Sometimes lint is wrong. Each of these lints warnings can be suppressed one by one using the following code.

 @SuppressWarnings("WeakerAccess") 
+20
Dec 18 '16 at 0:31
source share

Your HeartBeat class is not used anywhere outside the com.xxxxxxxxxxx.app.xxxx package. In this case, you can declare the class "protected" or 'private' more accurate in your access.

If you are not going to use this class outside this package, you should change the class declaration. If you intend to use this class outside this package, leave it and the warning will disappear.

eg:.

 protected class HeartBeat { ... } 
+1
Jun 06 '15 at 3:56 on
source share

Based on the background of the Android application, you also need to consider that sometimes these warnings are redundant. Therefore, for debug build classes this can be package local , but for release build it can be used outside the package.

I turned it off at the end, and @ashario's answer was very helpful in finding out how to do this.

0
Dec 08 '16 at 17:13
source share



All Articles