Inspection Gadget plugin small issue

Hi.

I have the following class:

package com.freshwater.event;

public class StatusCategory implements Comparable {
private final String name;

// Ordinal of next status to be created
private static int nextOrdinal = 0;

// Assign an ordinal to this status
private final int ordinal = nextOrdinal++;

private StatusCategory(String name) {
this.name = name;
}

public String toString() {
return this.name;
}

public int toInt() {
return ordinal;
}

public int compareTo(Object o) {
assert o instanceof StatusCategory;
return ordinal - ((StatusCategory) o).ordinal;
}

public static final StatusCategory DISABLED = new
StatusCategory("DISABLED");
public static final StatusCategory RUNNING = new StatusCategory("RUNNING");
public static final StatusCategory UNKNOWN = new StatusCategory("UNKNOWN");
public static final StatusCategory GOOD = new StatusCategory("GOOD");
public static final StatusCategory WARNING = new StatusCategory("WARNING");
public static final StatusCategory ERROR = new StatusCategory("ERROR");

// Maximum status
public static final StatusCategory STATUS_COUNT = new
StatusCategory("STATUS_COUNT");
}

I get a warning on "ordinal" that says that it can be static.
This warning is wrong, as this pattern purpose is to have an ordinal for
each created StatusCategory instance (DISABLED, RUNNING, etc.). If ordinal
were static, that pattern would be broken.

Amnon


2 comments
Comment actions Permalink


Wild, and you are quite correct that it's a bug. I'll modify the "Field Can Be Static" inspection to ignore the case where the initializer of the field has side effects.

0
Comment actions Permalink

Cool. Your plugin rocks!

"Dave Griffith" <dave.griffith@cnn.com> wrote in message
news:32768886.1063644276292.JavaMail.itn@is.intellij.net...
>

Wild, and you are quite correct that it's a bug. I'll modify the "Field

Can Be Static" inspection to ignore the case where the initializer of the
field has side effects.
>


0

Please sign in to leave a comment.