enum with array instead of copy, inner enums with error and no error

This commit is contained in:
artem.krosheninnikov
2019-06-14 01:47:17 +03:00
parent c5a77fbc35
commit 5f40ab11cf

View File

@ -308,6 +308,72 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface TopLevelAnnotation {
}
]]></code>
</test-code>
<test-code>
<description>Enum that returns array instead of copy</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public enum MethodReturnsInternalArrayCaseEnum {
ONE("One"),
TWO("Two", "Three");
private String[] titles;
MethodReturnsInternalArrayCaseEnum(String... titles) {
this.titles = titles;
}
public String[] getTitles() {
return titles;
}
}
]]></code>
</test-code>
<test-code>
<description>Inner enum that returns array instead of copy</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class OuterClass {
public enum InnerEnum {
INNER_ENUM("first", "second");
private String[] titles;
InnerEnum(String... titles) {
this.titles = titles;
}
public String[] getTitles() {
return titles;
}
}
}
]]></code>
</test-code>
<test-code>
<description>Inner enum that returns array instead of copy</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.Arrays;
public class OuterClass {
public enum InnerEnum {
INNER_ENUM("first", "second");
private String[] titles;
InnerEnum(String... titles) {
this.titles = titles;
}
public String[] getTitles() {
return Arrays.copyOf(titles, titles.length);
}
}
}
]]></code>
</test-code>