Fix some compiler warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808523 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-09-16 08:29:28 +00:00
parent 2600c60fb5
commit 1f4344a048
8 changed files with 142 additions and 161 deletions

View File

@ -77,16 +77,13 @@ public class BaseTestCellUtil {
@Test(expected=RuntimeException.class)
public void setCellStylePropertyWithInvalidValue() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
try {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Sheet s = wb.createSheet();
Row r = s.createRow(0);
Cell c = r.createCell(0);
// An invalid BorderStyle constant
CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, 42);
} finally {
wb.close();
}
}
@ -213,9 +210,6 @@ public class BaseTestCellUtil {
/**
* @deprecated by {@link #setAlignmentEnum()}
*
* @throws IOException
*
*/
@Deprecated
@SuppressWarnings("deprecated")

View File

@ -128,25 +128,19 @@ public class NumberComparingSpreadsheetGenerator {
return HexDump.longToHex(l)+'L';
}
public static void main(String[] args) {
HSSFWorkbook wb = new HSSFWorkbook();
public static void main(String[] args) throws IOException {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
SheetWriter sw = new SheetWriter(wb);
ComparisonExample[] ces = NumberComparisonExamples.getComparisonExamples();
for (ComparisonExample ce : ces) {
sw.addTestRow(ce.getA(), ce.getB(), ce.getExpectedResult());
}
File outputFile = new File("ExcelNumberCompare.xls");
try {
FileOutputStream os = new FileOutputStream(outputFile);
try (FileOutputStream os = new FileOutputStream(outputFile)) {
wb.write(os);
os.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("Finished writing '" + outputFile.getAbsolutePath() + "'");
}
}
}

View File

@ -18,6 +18,7 @@
package org.apache.poi.ss.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -115,7 +116,7 @@ final class NumberComparisonExamples {
addStepTransition(temp, 0x001000000000001BL);
addStepTransition(temp, 0x001000000000002FL);
for(ComparisonExample ce : new ComparisonExample[] {
Collections.addAll(temp, new ComparisonExample[]{
// negative, and exponents differ by more than 1
ce(0xBF30000000000000L, 0xBE60000000000000L, -1),
@ -137,9 +138,7 @@ final class NumberComparisonExamples {
ce(0x000FFFFFFFFFFFF9L, 0x0010000000000007L, -1),
ce(0x000FFFFFFFFFFFFAL, 0x0010000000000008L, -1),
ce(0x000FFFFFFFFFFFFBL, 0x0010000000000008L, -1),
}) {
temp.add(ce);
}
});
ComparisonExample[] result = new ComparisonExample[temp.size()];
temp.toArray(result);
@ -151,13 +150,11 @@ final class NumberComparisonExamples {
}
private static void addStepTransition(List<ComparisonExample> temp, long rawBits) {
for(ComparisonExample ce : new ComparisonExample[] {
Collections.addAll(temp, new ComparisonExample[]{
ce(rawBits - 1, rawBits + 0, 0),
ce(rawBits + 0, rawBits + 1, -1),
ce(rawBits + 1, rawBits + 2, 0),
}) {
temp.add(ce);
}
});
}

View File

@ -136,9 +136,7 @@ public class NumberRenderingSpreadsheetGenerator {
}
private static String formatLongAsHex(long l) {
StringBuilder sb = new StringBuilder(20);
sb.append(HexDump.longToHex(l)).append('L');
return sb.toString();
return HexDump.longToHex(l) + 'L';
}
public static void main(String[] args) {

View File

@ -27,8 +27,6 @@ import java.util.Arrays;
/**
* Tests that the common CellAddress works as we need it to.
* Note - some additional testing is also done in the HSSF class,
* {@link org.apache.poi.hssf.util.TestCellAddress}
*/
public final class TestCellAddress {
@Test
@ -60,6 +58,7 @@ public final class TestCellAddress {
assertNotEquals(new CellReference(4, 6), new CellReference(6, 4));
}
@SuppressWarnings("EqualsWithItself")
@Test
public void testCompareTo() {
final CellAddress A1 = new CellAddress(0, 0);
@ -89,7 +88,7 @@ public final class TestCellAddress {
CellAddress[] sorted = {A1, B1, A2, B2};
CellAddress[] unsorted = {B1, B2, A1, A2};
assumeTrue(!sorted.equals(unsorted));
assumeTrue(!Arrays.equals(sorted, unsorted));
Arrays.sort(unsorted);
assertArrayEquals(sorted, unsorted);
}

View File

@ -20,7 +20,6 @@ package org.apache.poi.ss.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -53,8 +52,9 @@ public final class TestCellRangeAddress {
@Test
public void testLoadInvalid() {
try {
assertNotNull(new CellRangeAddress(
TestcaseRecordInputStream.create(0x000, new byte[] { (byte)0x02 })));
new CellRangeAddress(
TestcaseRecordInputStream.create(0x000, new byte[] { (byte)0x02 }));
fail();
} catch (RuntimeException e) {
assertTrue("Had: " + e, e.getMessage().contains("Ran out of data"));
}
@ -66,8 +66,7 @@ public final class TestCellRangeAddress {
byte[] recordBytes;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
try {
try (LittleEndianOutputStream out = new LittleEndianOutputStream(baos)) {
// With nothing set
ref.serialize(out);
recordBytes = baos.toByteArray();
@ -91,8 +90,6 @@ public final class TestCellRangeAddress {
for (int i = 0; i < data.length; i++) {
assertEquals("At offset " + i, data[i], recordBytes[i]);
}
} finally {
out.close();
}
}
@ -100,13 +97,13 @@ public final class TestCellRangeAddress {
public void testCreateIllegal() throws IOException {
// for some combinations we expected exceptions
try {
assertNotNull(new CellRangeAddress(1, 0, 0, 0));
new CellRangeAddress(1, 0, 0, 0);
fail("Expect to catch an exception");
} catch (IllegalArgumentException e) {
// expected here
}
try {
assertNotNull(new CellRangeAddress(0, 0, 1, 0));
new CellRangeAddress(0, 0, 1, 0);
fail("Expect to catch an exception");
} catch (IllegalArgumentException e) {
// expected here

View File

@ -250,17 +250,23 @@ public final class TestCellReference {
try {
new CellReference("Sheet1!#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException expected) {}
} catch(IllegalArgumentException expected) {
// expected here
}
try {
new CellReference("'MySheetName'!#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException expected) {}
} catch(IllegalArgumentException expected) {
// expected here
}
try {
new CellReference("#REF!");
fail("Shouldn't be able to create a #REF! refence");
} catch(IllegalArgumentException expected) {}
} catch(IllegalArgumentException expected) {
// expected here
}
}
private static void confirmCrInRange(boolean expResult, String colStr, String rowStr,
@ -340,8 +346,10 @@ public final class TestCellReference {
assertEquals("equals", ref1, ref2);
assertEquals("hash code", ref1.hashCode(), ref2.hashCode());
//noinspection ObjectEqualsNull
assertFalse("null", ref1.equals(null));
assertFalse("3D vs 2D", ref1.equals(new CellReference("A5")));
//noinspection EqualsBetweenInconvertibleTypes
assertFalse("type", ref1.equals(new Integer(0)));
}

View File

@ -41,8 +41,7 @@ import org.apache.poi.util.TempFile;
public final class TestDateFormatConverter extends TestCase {
private void outputLocaleDataFormats( Date date, boolean dates, boolean times, int style, String styleName ) throws Exception {
Workbook workbook = new HSSFWorkbook();
try {
try (Workbook workbook = new HSSFWorkbook()) {
String sheetName;
if (dates) {
if (times) {
@ -107,16 +106,11 @@ public final class TestDateFormatConverter extends TestCase {
}
File outputFile = TempFile.createTempFile("Locale" + sheetName + styleName, ".xlsx");
FileOutputStream outputStream = new FileOutputStream(outputFile);
try {
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
workbook.write(outputStream);
} finally {
outputStream.close();
}
System.out.println("Open " + outputFile.getAbsolutePath() + " in Excel");
} finally {
workbook.close();
}
}