Skip to content

Commit 86da4be

Browse files
xzel23svanteschubert
authored andcommitted
collapse identical catch-clauses
1 parent 602ac10 commit 86da4be

File tree

14 files changed

+21
-104
lines changed

14 files changed

+21
-104
lines changed

odfdom/src/main/java/org/odftoolkit/odfdom/changes/ChangesFileSaxHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,7 @@ public void startElement(String uri, String localName, String qName, Attributes
914914
if (anchorHorOffset != 0) {
915915
drawingProps.put("anchorHorOffset", anchorHorOffset);
916916
}
917-
} catch (IndexOutOfBoundsException ex) {
918-
LOG.log(Level.SEVERE, null, ex);
919-
} catch (JSONException ex) {
917+
} catch (IndexOutOfBoundsException | JSONException ex) {
920918
LOG.log(Level.SEVERE, null, ex);
921919
}
922920
}

odfdom/src/main/java/org/odftoolkit/odfdom/changes/JsonOperationConsumer.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,9 +1343,7 @@ public static void addStyles(
13431343
OdfOfficeStyles styles = null;
13441344
try {
13451345
styles = doc.getStylesDom().getOrCreateOfficeStyles();
1346-
} catch (SAXException ex) {
1347-
LOG.log(Level.SEVERE, null, ex);
1348-
} catch (IOException ex) {
1346+
} catch (SAXException | IOException ex) {
13491347
LOG.log(Level.SEVERE, null, ex);
13501348
}
13511349
if (attrs != null) {
@@ -3340,19 +3338,7 @@ public static void addField(
33403338
Constructor<OdfElement> constructor = fieldClass.getConstructor(types);
33413339
newFieldElement = constructor.newInstance(xmlDoc);
33423340
}
3343-
} catch (InstantiationException e) {
3344-
LOG.log(Level.SEVERE, null, e);
3345-
} catch (IllegalAccessException e) {
3346-
LOG.log(Level.SEVERE, null, e);
3347-
} catch (IllegalArgumentException e) {
3348-
LOG.log(Level.SEVERE, null, e);
3349-
} catch (InvocationTargetException e) {
3350-
LOG.log(Level.SEVERE, null, e);
3351-
} catch (NoSuchMethodException e) {
3352-
LOG.log(Level.SEVERE, null, e);
3353-
} catch (SecurityException e) {
3354-
LOG.log(Level.SEVERE, null, e);
3355-
} catch (ClassNotFoundException e) {
3341+
} catch (InstantiationException | ClassNotFoundException | SecurityException | NoSuchMethodException | InvocationTargetException | IllegalArgumentException | IllegalAccessException e) {
33563342
LOG.log(Level.SEVERE, null, e);
33573343
}
33583344
setFieldAttributes(newFieldElement, attrs, currentMap, contentDom);

odfdom/src/main/java/org/odftoolkit/odfdom/changes/JsonOperationProducer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,7 @@ static Map<String, Object> getAutomaticStyleHierarchyProps(OdfStylableElement st
10741074
jsonCellProps.put("formatCode", formatCode);
10751075
allHardFormatting.put("cell", jsonCellProps);
10761076
}
1077-
} catch (SAXException ex) {
1078-
LOG.log(Level.SEVERE, null, ex);
1079-
} catch (IOException ex) {
1077+
} catch (SAXException | IOException ex) {
10801078
LOG.log(Level.SEVERE, null, ex);
10811079
}
10821080
}

odfdom/src/main/java/org/odftoolkit/odfdom/changes/MapHelper.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,10 +2147,8 @@ public static String findOrCreateDataStyle(String code, long id, OdfFileDom file
21472147
ret = newDataStyleName;
21482148
}
21492149
}
2150-
} catch (SAXException e) {
2150+
} catch (SAXException | IOException e) {
21512151
LOG.log(Level.SEVERE, null, e);
2152-
} catch (IOException ex) {
2153-
LOG.log(Level.SEVERE, null, ex);
21542152
}
21552153
return ret;
21562154
}

odfdom/src/main/java/org/odftoolkit/odfdom/doc/OdfPresentationDocument.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,6 @@ private boolean deleteLinkRef(DrawPageElement slideEle) {
518518
}
519519
}
520520
}
521-
} catch (XPathExpressionException e) {
522-
LOG.log(Level.SEVERE, null, e);
523-
success = false;
524521
} catch (Exception e) {
525522
LOG.log(Level.SEVERE, null, e);
526523
success = false;
@@ -1410,9 +1407,7 @@ private void setSlideLayout(DrawPageElement page, OdfSlide.SlideLayout slideLayo
14101407
OdfOfficeStyles styles = null;
14111408
try {
14121409
styles = this.getStylesDom().getOrCreateOfficeStyles();
1413-
} catch (SAXException ex) {
1414-
LOG.log(Level.SEVERE, null, ex);
1415-
} catch (IOException ex) {
1410+
} catch (SAXException | IOException ex) {
14161411
LOG.log(Level.SEVERE, null, ex);
14171412
}
14181413
String layoutName;

odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTable.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ public static OdfTable newTable(OdfElement tableParent) {
554554
tableParent.appendChild(newTEle);
555555
return OdfTable.getInstance(newTEle);
556556

557-
} catch (DOMException e) {
558-
LOG.log(Level.SEVERE, e.getMessage(), e);
559557
} catch (Exception e) {
560558
LOG.log(Level.SEVERE, e.getMessage(), e);
561559
}
@@ -687,8 +685,6 @@ public static OdfTable newTable(
687685

688686
return OdfTable.getInstance(newTEle);
689687

690-
} catch (DOMException e) {
691-
LOG.log(Level.SEVERE, e.getMessage(), e);
692688
} catch (Exception e) {
693689
LOG.log(Level.SEVERE, e.getMessage(), e);
694690
}
@@ -798,8 +794,6 @@ public static OdfTable newTable(
798794
}
799795
}
800796
return table;
801-
} catch (DOMException e) {
802-
LOG.log(Level.SEVERE, e.getMessage(), e);
803797
} catch (Exception e) {
804798
LOG.log(Level.SEVERE, e.getMessage(), e);
805799
}
@@ -907,8 +901,6 @@ public static OdfTable newTable(
907901

908902
return table;
909903

910-
} catch (DOMException e) {
911-
LOG.log(Level.SEVERE, e.getMessage(), e);
912904
} catch (Exception e) {
913905
LOG.log(Level.SEVERE, e.getMessage(), e);
914906
}

odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,7 @@ public void loadDocument() {
134134
// Exception is expected!
135135
OdfDocument.loadDocument(ResourceUtilities.getAbsoluteInputPath(IMAGE_TEST_FILE));
136136
Assert.fail();
137-
} catch (IllegalArgumentException e) {
138-
if (!e.getMessage().contains("shall be a ZIP file")) {
139-
LOG.log(Level.SEVERE, e.getMessage(), e);
140-
Assert.fail();
141-
}
142-
} catch (OdfValidationException e) {
137+
} catch (IllegalArgumentException | OdfValidationException e) {
143138
if (!e.getMessage().contains("shall be a ZIP file")) {
144139
LOG.log(Level.SEVERE, e.getMessage(), e);
145140
Assert.fail();

odfdom/src/test/java/org/odftoolkit/odfdom/doc/table/TableTest.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,6 @@ public void testAppendColumn() {
381381
Assert.assertEquals(column.getCellCount(), columnOld.getCellCount());
382382
}
383383
saveodt(mOdtTestFileName + "Output.odt");
384-
} catch (FileNotFoundException ex) {
385-
LOG.log(Level.SEVERE, null, ex);
386-
Assert.fail();
387384
} catch (Exception ex) {
388385
LOG.log(Level.SEVERE, null, ex);
389386
Assert.fail();
@@ -465,9 +462,6 @@ public void testInsertColumnBefore() {
465462
Assert.assertEquals(newClm2, oldClm0);
466463

467464
saveodt(mOdtTestFileName + "Out.odt");
468-
} catch (FileNotFoundException ex) {
469-
LOG.log(Level.SEVERE, null, ex);
470-
Assert.fail();
471465
} catch (Exception ex) {
472466
LOG.log(Level.SEVERE, null, ex);
473467
Assert.fail();
@@ -503,9 +497,6 @@ public void testRemoveColumnByIndex() {
503497
Assert.assertEquals(oldClm1, clm0);
504498
Assert.assertEquals(clmnum - 4, table2.getColumnCount());
505499
saveodt(mOdtTestFileName + "Out.odt");
506-
} catch (FileNotFoundException ex) {
507-
LOG.log(Level.SEVERE, null, ex);
508-
Assert.fail();
509500
} catch (Exception ex) {
510501
LOG.log(Level.SEVERE, null, ex);
511502
Assert.fail();
@@ -538,9 +529,6 @@ public void testInsertRowBefore() {
538529
OdfTable newTable = mOdtDoc.getTableByName("Table2");
539530

540531
Assert.assertEquals(originalRowCount + 2, newTable.getRowCount());
541-
} catch (FileNotFoundException ex) {
542-
LOG.log(Level.SEVERE, null, ex);
543-
Assert.fail();
544532
} catch (Exception ex) {
545533
LOG.log(Level.SEVERE, null, ex);
546534
Assert.fail();
@@ -695,9 +683,6 @@ public void testGetColumnByIndex() {
695683
Assert.assertNotNull(cell);
696684
cell.setStringValue("string86");
697685
Assert.assertEquals("string86", cell.getStringValue());
698-
} catch (FileNotFoundException ex) {
699-
LOG.log(Level.SEVERE, null, ex);
700-
Assert.fail();
701686
} catch (Exception ex) {
702687
LOG.log(Level.SEVERE, null, ex);
703688
Assert.fail();
@@ -736,9 +721,6 @@ public void testGetRowByIndex() throws Exception {
736721
Assert.assertNotNull(cell);
737722
cell.setStringValue("string86");
738723
Assert.assertEquals("string86", cell.getStringValue());
739-
} catch (FileNotFoundException ex) {
740-
LOG.log(Level.SEVERE, null, ex);
741-
Assert.fail();
742724
} catch (Exception ex) {
743725
LOG.log(Level.SEVERE, null, ex);
744726
Assert.fail();
@@ -769,9 +751,6 @@ public void testRemoveRowByIndex() {
769751
OdfTable newTable = mOdtDoc.getTableByName("Table2");
770752

771753
Assert.assertEquals(originalRowCount - 2, newTable.getRowCount());
772-
} catch (FileNotFoundException ex) {
773-
LOG.log(Level.SEVERE, null, ex);
774-
Assert.fail();
775754
} catch (Exception ex) {
776755
LOG.log(Level.SEVERE, null, ex);
777756
Assert.fail();
@@ -788,9 +767,6 @@ public void testGetHeaderRowCount() {
788767
OdfTable table = mOdtDoc.getTableByName("Table3");
789768
int headerRowCount = table.getHeaderRowCount();
790769
Assert.assertEquals(1, headerRowCount);
791-
} catch (FileNotFoundException ex) {
792-
LOG.log(Level.SEVERE, null, ex);
793-
Assert.fail();
794770
} catch (Exception ex) {
795771
LOG.log(Level.SEVERE, null, ex);
796772
Assert.fail();
@@ -807,9 +783,6 @@ public void testGetHeaderColumnCount() {
807783
OdfTable table = mOdtDoc.getTableByName("Table3");
808784
int headerColumnCount = table.getHeaderColumnCount();
809785
Assert.assertEquals(1, headerColumnCount);
810-
} catch (FileNotFoundException ex) {
811-
LOG.log(Level.SEVERE, null, ex);
812-
Assert.fail();
813786
} catch (Exception ex) {
814787
LOG.log(Level.SEVERE, null, ex);
815788
Assert.fail();

odfdom/src/test/java/org/odftoolkit/odfdom/utils/ResourceUtilities.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ public static String loadFileAsString(File file) {
357357
input.read(fileData);
358358
input.close();
359359
result = new String(fileData, "UTF-8");
360-
} catch (FileNotFoundException ex) {
361-
LOG.log(Level.SEVERE, null, ex);
362360
} catch (IOException ex) {
363361
LOG.log(Level.SEVERE, null, ex);
364362
} finally {

validator/src/main/java/org/odftoolkit/odfvalidator/Main.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ public static void main(String[] aArgs) {
232232
aOut, aFileNames, aExcludeRegExp, eMode, bRecursive, aFilterFileName);
233233
}
234234
System.exit(bHasErrors ? 2 : 0);
235-
} catch (ODFValidatorException e) {
236-
System.err.println(e.getMessage());
237-
System.err.println("Validation aborted.");
238-
System.exit(1);
239-
} catch (FileNotFoundException e) {
235+
} catch (ODFValidatorException | FileNotFoundException e) {
240236
System.err.println(e.getMessage());
241237
System.err.println("Validation aborted.");
242238
System.exit(1);

0 commit comments

Comments
 (0)