Showing 774 of 774 total issues
The string literal " " appears 3 times in the file. Open
sanitizeURI(new File(path.replace(" ", SPACE_ENCODED)).toURI.toString)
- Exclude checks
Method name does not match the regular expression '^[a-z][A-Za-z0-9]*$' Open
def SHUTDOWN_TIMEOUT: Int = timeouts(SHUTDOWN)
- Exclude checks
Avoid using null Open
val changes = if (edit.getChanges != null) edit.getChanges.asScala else null
- Exclude checks
Method is longer than 50 lines Open
def applyEdit(edit: WorkspaceEdit, name: String = "LSP edits", toClose: Iterable[VirtualFile] = Seq()): Boolean = {
- Exclude checks
If block needs braces Open
if (w != wrapper && w.getRequestManager != null && w.getStatus == ServerStatus.STARTED)
- Exclude checks
File line length exceeds 160 characters Open
class LSPInplaceRenamer(elementToRename: PsiNamedElement, substituted: PsiElement, editor: Editor)(initialName: String = elementToRename.getName, oldName: String = elementToRename.getName) extends MemberInplaceRenamer(elementToRename, substituted, editor, initialName, oldName) {
- Exclude checks
Cyclomatic complexity of 20 exceeds max of 10 Open
override def getCompletionIcon(kind: CompletionItemKind): Icon = {
- Exclude checks
Cyclomatic complexity of 20 exceeds max of 10 Open
override def getSymbolIcon(kind: SymbolKind): Icon = {
- Exclude checks
Avoid using return Open
if ((newMap eq map) || changeUserMap(map, newMap)) return value
- Exclude checks
Avoid using null Open
override def getIcon(unused: Boolean): Icon = if (unused) null else null //iconProvider.getIcon(LSPPsiElement.this)
- Exclude checks
Imports should be grouped together Open
import PluginMain._
- Exclude checks
Imports should be grouped together Open
import scala.collection.JavaConverters._
- Exclude checks
Imports should be grouped together Open
import scala.collection.JavaConverters._
- Exclude checks
Imports should be grouped together Open
import scala.collection.JavaConverters._
- Exclude checks
Move the contents of this initializer to a standard constructor or to field initializers. Open
{
- Read upRead up
- Exclude checks
Non-static initializers are rarely used, and can be confusing for most developers because they only run when new class instances are created. When possible, non-static initializers should be refactored into standard constructors or field initializers.
Noncompliant Code Example
class MyClass { private static final Map<String, String> MY_MAP = new HashMap<String, String>() { // Noncompliant - HashMap should be extended only to add behavior, not for initialization { put("a", "b"); } }; }
Compliant Solution
class MyClass { private static final Map<String, String> MY_MAP = new HashMap<String, String>(); static { MY_MAP.put("a", "b"); } }
or using Java 9 Map.of
:
class MyClass { // Compliant private static final Map<String, String> MY_MAP = java.util.Map.of("a", "b"); }
or using Guava:
class MyClass { // Compliant private static final Map<String, String> MY_MAP = ImmutableMap.of("a", "b"); }
Remove this unused "LOG" private field. Open
private static final Logger LOG = Logger.getInstance(MiscSettings.class);
- Read upRead up
- Exclude checks
If a private
field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will
improve maintainability because developers will not wonder what the variable is used for.
Note that this rule does not take reflection into account, which means that issues will be raised on private
fields that are only
accessed using the reflection API.
Noncompliant Code Example
public class MyClass { private int foo = 42; public int compute(int a) { return a * 42; } }
Compliant Solution
public class MyClass { public int compute(int a) { return a * 42; } }
Exceptions
The Java serialization runtime associates with each serializable class a version number, called serialVersionUID
, which is used during
deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to
serialization.
A serializable class can declare its own serialVersionUID
explicitly by declaring a field named serialVersionUID
that
must be static, final, and of type long. By definition those serialVersionUID
fields should not be reported by this rule:
public class MyClass implements java.io.Serializable { private static final long serialVersionUID = 42L; }
Moreover, this rule doesn't raise any issue on annotated fields.
Make the enclosing method "static" or remove this set. Open
timeoutGUI = new TimeoutGUI();
- Read upRead up
- Exclude checks
Correctly updating a static
field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple
class instances and/or multiple threads in play. Ideally, static
fields are only updated from synchronized static
methods.
This rule raises an issue each time a static
field is updated from a non-static method.
Noncompliant Code Example
public class MyClass { private static int count = 0; public void doSomething() { //... count++; // Noncompliant } }
This block of commented-out lines of code should be removed. Open
//Messages.showInfoMessage("The changes will be applied after restarting the IDE.", "LSP Settings");
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
Make the enclosing method "static" or remove this set. Open
miscGUI = null;
- Read upRead up
- Exclude checks
Correctly updating a static
field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple
class instances and/or multiple threads in play. Ideally, static
fields are only updated from synchronized static
methods.
This rule raises an issue each time a static
field is updated from a non-static method.
Noncompliant Code Example
public class MyClass { private static int count = 0; public void doSomething() { //... count++; // Noncompliant } }
Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation. Open
public LSPState() {
- Read upRead up
- Exclude checks
There are several reasons for a method not to have a method body:
- It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
- It is not yet, or never will be, supported. In this case an
UnsupportedOperationException
should be thrown. - The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
Noncompliant Code Example
public void doSomething() { } public void doSomethingElse() { }
Compliant Solution
@Override public void doSomething() { // Do nothing because of X and Y. } @Override public void doSomethingElse() { throw new UnsupportedOperationException(); }
Exceptions
Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.
public abstract class Animal { void speak() { // default implementation ignored } }