Today I found something looks like a bug in Ivy Script.
In Ivy Script, I want to have a List
of all the elements of an enum
, say WorkflowPriority
, I simply call WorkflowPriority.values()
. However, the instance of List
returned by the call doesn't work correctly, especially with operation contains
and remove
.
Here are the tests that I made to check:
(This is an Ivy Script snippet)
import org.junit.Assert;
import com.genzerhawherk.bugs.Lists;
import ch.ivyteam.ivy.workflow.WorkflowPriority;
// Below are all failed tests
Assert.assertTrue(WorkflowPriority.values().contains(WorkflowPriority.HIGH));
List<WorkflowPriority> withGenerics = WorkflowPriority.values();
Assert.assertTrue(withGenerics.contains(WorkflowPriority.HIGH));
List fromEnums = Lists.fromEnums(WorkflowPriority.class);
Assert.assertTrue(fromEnums.contains(WorkflowPriority.HIGH));
List fromEnumVarargs = Lists.enumVarArgs(WorkflowPriority.HIGH, WorkflowPriority.EXCEPTION);
Assert.assertTrue(fromEnumVarargs.contains(WorkflowPriority.HIGH));
// Below are all passed tests
List listComprehensive = [WorkflowPriority.HIGH];
Assert.assertTrue(listComprehensive.contains(WorkflowPriority.HIGH));
List newPriorities = new List().addAll(WorkflowPriority.values());
Assert.assertTrue(newPriorities.contains(WorkflowPriority.HIGH));
List fromList = Lists.toArray([WorkflowPriority.HIGH]);
Assert.assertTrue(fromList.contains(WorkflowPriority.HIGH));
List fromVarArgs = Lists.normalVarArgs(WorkflowPriority.HIGH);
Assert.assertTrue(fromVarArgs.contains(WorkflowPriority.HIGH));
List<WorkflowPriority> manuallyConstructed = new List<WorkflowPriority>();
manuallyConstructed.add(WorkflowPriority.HIGH);
Assert.assertTrue(manuallyConstructed.contains(WorkflowPriority.HIGH));
The bug particularly relates to converting <T extends Enum<T>> T[]
into a List<T>
Below is the class Lists
I use in the test
public class Lists {
public static Object[] toArray(Collection<?> collection) {
return collection.toArray();
}
@SafeVarargs
public static <T> T[] normalVarArgs(T...elements) {
return Arrays.copyOf(elements, elements.length);
}
public static <T extends Enum<T>> T[] fromEnums(Class<T> enums) {
return enums.getEnumConstants();
}
@SafeVarargs
public static <T extends Enum<T>> T[] enumVarArgs(T...enums) {
return enums;
}
}
asked
12.03.2015 at 08:27
Genzer Hawker
(suspended)
accept rate:
66%