Skip to content

Commit 5e6da6f

Browse files
committed
Deprecate toJavaArray: unsafe
1 parent 61708ee commit 5e6da6f

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

core/src/main/java/fj/data/Array.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ public Object[] array() {
128128
return copyOf(a, a.length);
129129
}
130130

131-
@SuppressWarnings("unchecked")
131+
/**
132+
* To be removed in future release:
133+
* affectation of the result of this method to a non generic array
134+
* will result in runtime error (ClassCastException).
135+
*
136+
* @deprecated use {@link #array(Class)}
137+
*/
138+
@Deprecated
132139
public A[] toJavaArray() {
133140
return (A[]) array();
134141
}

core/src/main/java/fj/data/List.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,14 @@ public final Object[] toArrayObject() {
211211
return a;
212212
}
213213

214-
@SuppressWarnings("unchecked")
214+
/**
215+
* To be removed in future release:
216+
* affectation of the result of this method to a non generic array
217+
* will result in runtime error (ClassCastException).
218+
*
219+
* @deprecated use {@link #array(Class)}
220+
*/
221+
@Deprecated
215222
public final A[] toJavaArray() {
216223
return (A[]) toArrayObject();
217224
}

core/src/main/java/fj/data/Stream.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,14 @@ public final Option<A> toOption() {
916916
return isEmpty() ? Option.<A>none() : some(head());
917917
}
918918

919-
@SuppressWarnings({"unchecked", "UnnecessaryFullyQualifiedName"})
919+
/**
920+
* To be removed in future release:
921+
* affectation of the result of this method to a non generic array
922+
* will result in runtime error (ClassCastException).
923+
*
924+
* @deprecated use {@link #array(Class)}
925+
*/
926+
@Deprecated
920927
public final A[] toJavaArray() {
921928
final A[] array = (A[]) new Object[length()];
922929
int i = 0;

core/src/test/java/fj/data/ArrayTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Test;
44

55
import static org.hamcrest.CoreMatchers.equalTo;
6+
import static org.hamcrest.CoreMatchers.instanceOf;
67
import static org.junit.Assert.assertThat;
78

89
/**
@@ -11,10 +12,10 @@
1112
public class ArrayTest {
1213

1314
@Test
14-
public void toJavaArray() {
15-
final int max = 3;
16-
List<Integer> list = List.range(1, max + 1);
17-
assertThat(list.toArray().toJavaArray(), equalTo(list.toJavaArray()));
15+
public void array_is_safe() {
16+
List<Integer> list = List.range(1, 2);
17+
18+
assertThat(list.toArray().array(Integer[].class), instanceOf(Integer[].class));
1819
}
1920

2021
}

0 commit comments

Comments
 (0)