Skip to content

[core] EnumeratedProperty<T> does not return a T as its value #459

@oowekyala

Description

@oowekyala

Description: To use a rule property that can take its value in an enumeration, I think the preferred approach is an EnumeratedProperty. I create an EnumeratedProperty like this:

private static final String[] LABELS = { "foo", "bar" };
enum Foo { FOO, BAR }
private static final Foo[] CHOICES = { Foo.FOO, Foo.BAR };

public static final EnumeratedProperty<Foo> FOO_DESCRIPTOR = new EnumeratedProperty<>(
    "fooChoice", "Choose a instance of Foo", LABELS, CHOICES, 0, 3.0f);

where the parameter 0 indicates the default index. But the value returned by getProperty is really weird:

  • If the property was not explicitly given a value in the ruleset.xml, then getProperty returns "foo" (a String)
  • Otherwise, getProperty returns an instance of Foo, which corresponds to the label given in the XML.

I would think it's abnormal that getProperty may return something other than a Foo, especially since it's an EnumeratedProperty<Foo>. Is that a bug or am I doing this wrong ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions