Skip to content

Commit 6c4a32c

Browse files
committed
Suppress warnings about legitimate unchecked array creations, or change code to avoid it
1 parent f35b833 commit 6c4a32c

File tree

2 files changed

+112
-47
lines changed

2 files changed

+112
-47
lines changed

core/src/test/java/org/apache/spark/JavaAPISuite.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public int compare(Integer a, Integer b) {
7575
else if (a < b) return 1;
7676
else return 0;
7777
}
78-
};
78+
}
7979

80+
@SuppressWarnings("unchecked")
8081
@Test
8182
public void sparkContextUnion() {
8283
// Union of non-specialized JavaRDDs
@@ -148,6 +149,7 @@ public void call(String s) {
148149
Assert.assertEquals(2, foreachCalls);
149150
}
150151

152+
@SuppressWarnings("unchecked")
151153
@Test
152154
public void lookup() {
153155
JavaPairRDD<String, String> categories = sc.parallelizePairs(Arrays.asList(
@@ -179,6 +181,7 @@ public Boolean call(Integer x) {
179181
Assert.assertEquals(5, oddsAndEvens.lookup(false).get(0).size()); // Odds
180182
}
181183

184+
@SuppressWarnings("unchecked")
182185
@Test
183186
public void cogroup() {
184187
JavaPairRDD<String, String> categories = sc.parallelizePairs(Arrays.asList(
@@ -197,6 +200,7 @@ public void cogroup() {
197200
cogrouped.collect();
198201
}
199202

203+
@SuppressWarnings("unchecked")
200204
@Test
201205
public void leftOuterJoin() {
202206
JavaPairRDD<Integer, Integer> rdd1 = sc.parallelizePairs(Arrays.asList(
@@ -243,6 +247,7 @@ public Integer call(Integer a, Integer b) {
243247
Assert.assertEquals(33, sum);
244248
}
245249

250+
@SuppressWarnings("unchecked")
246251
@Test
247252
public void foldByKey() {
248253
List<Tuple2<Integer, Integer>> pairs = Arrays.asList(
@@ -265,6 +270,7 @@ public Integer call(Integer a, Integer b) {
265270
Assert.assertEquals(3, sums.lookup(3).get(0).intValue());
266271
}
267272

273+
@SuppressWarnings("unchecked")
268274
@Test
269275
public void reduceByKey() {
270276
List<Tuple2<Integer, Integer>> pairs = Arrays.asList(
@@ -320,8 +326,8 @@ public void approximateResults() {
320326
public void take() {
321327
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1, 1, 2, 3, 5, 8, 13));
322328
Assert.assertEquals(1, rdd.first().intValue());
323-
List<Integer> firstTwo = rdd.take(2);
324-
List<Integer> sample = rdd.takeSample(false, 2, 42);
329+
rdd.take(2);
330+
rdd.takeSample(false, 2, 42);
325331
}
326332

327333
@Test
@@ -359,8 +365,8 @@ public Boolean call(Double x) {
359365
Assert.assertEquals(2.49444, rdd.stdev(), 0.01);
360366
Assert.assertEquals(2.73252, rdd.sampleStdev(), 0.01);
361367

362-
Double first = rdd.first();
363-
List<Double> take = rdd.take(5);
368+
rdd.first();
369+
rdd.take(5);
364370
}
365371

366372
@Test
@@ -438,11 +444,11 @@ public Iterable<Double> call(String s) {
438444
return lengths;
439445
}
440446
});
441-
Double x = doubles.first();
442-
Assert.assertEquals(5.0, doubles.first().doubleValue(), 0.01);
447+
Assert.assertEquals(5.0, doubles.first(), 0.01);
443448
Assert.assertEquals(11, pairs.count());
444449
}
445450

451+
@SuppressWarnings("unchecked")
446452
@Test
447453
public void mapsFromPairsToPairs() {
448454
List<Tuple2<Integer, String>> pairs = Arrays.asList(
@@ -509,6 +515,7 @@ public void repartition() {
509515
}
510516
}
511517

518+
@SuppressWarnings("unchecked")
512519
@Test
513520
public void persist() {
514521
JavaDoubleRDD doubleRDD = sc.parallelizeDoubles(Arrays.asList(1.0, 1.0, 2.0, 3.0, 5.0, 8.0));
@@ -573,6 +580,7 @@ public void textFilesCompressed() throws IOException {
573580
Assert.assertEquals(expected, readRDD.collect());
574581
}
575582

583+
@SuppressWarnings("unchecked")
576584
@Test
577585
public void sequenceFile() {
578586
File tempDir = Files.createTempDir();
@@ -602,6 +610,7 @@ public Tuple2<Integer, String> call(Tuple2<IntWritable, Text> pair) {
602610
Assert.assertEquals(pairs, readRDD.collect());
603611
}
604612

613+
@SuppressWarnings("unchecked")
605614
@Test
606615
public void writeWithNewAPIHadoopFile() {
607616
File tempDir = Files.createTempDir();
@@ -632,6 +641,7 @@ public String call(Tuple2<IntWritable, Text> x) {
632641
}).collect().toString());
633642
}
634643

644+
@SuppressWarnings("unchecked")
635645
@Test
636646
public void readWithNewAPIHadoopFile() throws IOException {
637647
File tempDir = Files.createTempDir();
@@ -674,6 +684,7 @@ public void objectFilesOfInts() {
674684
Assert.assertEquals(expected, readRDD.collect());
675685
}
676686

687+
@SuppressWarnings("unchecked")
677688
@Test
678689
public void objectFilesOfComplexTypes() {
679690
File tempDir = Files.createTempDir();
@@ -690,6 +701,7 @@ public void objectFilesOfComplexTypes() {
690701
Assert.assertEquals(pairs, readRDD.collect());
691702
}
692703

704+
@SuppressWarnings("unchecked")
693705
@Test
694706
public void hadoopFile() {
695707
File tempDir = Files.createTempDir();
@@ -719,6 +731,7 @@ public String call(Tuple2<IntWritable, Text> x) {
719731
}).collect().toString());
720732
}
721733

734+
@SuppressWarnings("unchecked")
722735
@Test
723736
public void hadoopFileCompressed() {
724737
File tempDir = Files.createTempDir();
@@ -824,7 +837,7 @@ public Float zero(Float initialValue) {
824837
}
825838
};
826839

827-
final Accumulator<Float> floatAccum = sc.accumulator((Float) 10.0f, floatAccumulatorParam);
840+
final Accumulator<Float> floatAccum = sc.accumulator(10.0f, floatAccumulatorParam);
828841
rdd.foreach(new VoidFunction<Integer>() {
829842
public void call(Integer x) {
830843
floatAccum.add((float) x);
@@ -876,6 +889,7 @@ public void checkpointAndRestore() {
876889
Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), recovered.collect());
877890
}
878891

892+
@SuppressWarnings("unchecked")
879893
@Test
880894
public void mapOnPairRDD() {
881895
JavaRDD<Integer> rdd1 = sc.parallelize(Arrays.asList(1,2,3,4));
@@ -900,6 +914,7 @@ public Tuple2<Integer, Integer> call(Tuple2<Integer, Integer> in) throws Excepti
900914

901915
}
902916

917+
@SuppressWarnings("unchecked")
903918
@Test
904919
public void collectPartitions() {
905920
JavaRDD<Integer> rdd1 = sc.parallelize(Arrays.asList(1, 2, 3, 4, 5, 6, 7), 3);
@@ -968,14 +983,14 @@ public void countApproxDistinctByKey() {
968983
@Test
969984
public void collectAsMapWithIntArrayValues() {
970985
// Regression test for SPARK-1040
971-
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(new Integer[] { 1 }));
986+
JavaRDD<Integer> rdd = sc.parallelize(Arrays.asList(1));
972987
JavaPairRDD<Integer, int[]> pairRDD = rdd.map(new PairFunction<Integer, Integer, int[]>() {
973988
@Override
974989
public Tuple2<Integer, int[]> call(Integer x) throws Exception {
975990
return new Tuple2<Integer, int[]>(x, new int[] { x });
976991
}
977992
});
978993
pairRDD.collect(); // Works fine
979-
Map<Integer, int[]> map = pairRDD.collectAsMap(); // Used to crash with ClassCastException
994+
pairRDD.collectAsMap(); // Used to crash with ClassCastException
980995
}
981996
}

0 commit comments

Comments
 (0)