diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java index 55b268133..1c8cac311 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Main.java @@ -270,9 +270,15 @@ public final class Main final Properties properties = new Properties(); try { FileInputStream fis = null; - fis = new FileInputStream(aFile); - properties.load(fis); - fis.close(); + try { + fis = new FileInputStream(aFile); + properties.load(fis); + } + finally { + if (fis != null) { + fis.close(); + } + } } catch (final IOException ex) { System.out.println("Unable to load properties from file: " diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java index 33140947c..d31850db0 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java @@ -24,10 +24,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.io.Serializable; import java.util.Properties; import java.security.MessageDigest; + import com.puppycrawl.tools.checkstyle.api.Configuration; import com.puppycrawl.tools.checkstyle.api.Utils; @@ -122,15 +124,32 @@ final class PropertyCacheFile .debug("Unable to save cache file.", e); } finally { - if (out != null) { - try { - out.flush(); - out.close(); - } - catch (final IOException ex) { - Utils.getExceptionLogger() - .debug("Unable to close cache file.", ex); - } + this.flushAndCloseOutStream(out); + } + } + } + + /** + * Flushes and closes output stream. + * @param aStream the output stream + */ + private void flushAndCloseOutStream(OutputStream aStream) + { + if (aStream != null) { + try { + aStream.flush(); + } + catch (final IOException ex) { + Utils.getExceptionLogger() + .debug("Unable to flush output stream.", ex); + } + finally { + try { + aStream.close(); + } + catch (final IOException ex) { + Utils.getExceptionLogger() + .debug("Unable to close output stream.", ex); } } } @@ -170,10 +189,14 @@ final class PropertyCacheFile // im-memory serialization of Configuration final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(aConfiguration); - oos.flush(); - oos.close(); + ObjectOutputStream oos = null; + try { + oos = new ObjectOutputStream(baos); + oos.writeObject(aConfiguration); + } + finally { + this.flushAndCloseOutStream(oos); + } // Instead of hexEncoding baos.toByteArray() directly we // use a message digest here to keep the length of the diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java index 5a2960362..f3cbd9000 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.api; +import java.io.Serializable; import java.text.MessageFormat; import java.util.Arrays; import java.util.Collections; @@ -38,7 +39,7 @@ import java.util.ResourceBundle; * @version 1.0 */ public final class LocalizedMessage - implements Comparable + implements Comparable, Serializable { /** hash function multiplicand */ private static final int HASH_MULT = 29; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java index 45fc9b85a..dd2b05834 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java @@ -217,7 +217,7 @@ public final class Utils ; // silently ignore } } - return lines.toArray(new String[0]); + return lines.toArray(new String[lines.size()]); } /** diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java index f31acc20d..d7e445461 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheck.java @@ -219,7 +219,8 @@ public final class IllegalTypeCheck extends AbstractFormatCheck */ public String[] getIllegalClassNames() { - return mIllegalClassNames.toArray(new String[0]); + return mIllegalClassNames.toArray( + new String[mIllegalClassNames.size()]); } /** @@ -240,7 +241,8 @@ public final class IllegalTypeCheck extends AbstractFormatCheck */ public String[] getIgnoredMethodNames() { - return mIgnoredMethodNames.toArray(new String[0]); + return mIgnoredMethodNames.toArray( + new String[mIgnoredMethodNames.size()]); } /** @@ -261,6 +263,7 @@ public final class IllegalTypeCheck extends AbstractFormatCheck */ public String[] getLegalAbstractClassNames() { - return mLegalAbstractClassNames.toArray(new String[0]); + return mLegalAbstractClassNames.toArray( + new String[mLegalAbstractClassNames.size()]); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/doclets/TokenTypesDoclet.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/doclets/TokenTypesDoclet.java index 5564d6e46..a51746d02 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/doclets/TokenTypesDoclet.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/doclets/TokenTypesDoclet.java @@ -49,29 +49,38 @@ public class TokenTypesDoclet { final String fileName = getDestFileName(aRoot.options()); final FileOutputStream fos = new FileOutputStream(fileName); - final PrintStream ps = new PrintStream(fos); - final ClassDoc[] classes = aRoot.classes(); - if ((classes.length != 1) || !"TokenTypes".equals(classes[0].name())) { - final String message = - "The doclet should be used for TokenTypes only"; - throw new IllegalArgumentException(message); - } - - final FieldDoc[] fields = classes[0].fields(); - for (final FieldDoc field : fields) { - if (field.isStatic() && field.isPublic() && field.isFinal() - && "int".equals((field.type().qualifiedTypeName()))) + PrintStream ps = null; + try { + ps = new PrintStream(fos); + final ClassDoc[] classes = aRoot.classes(); + if ((classes.length != 1) + || !"TokenTypes".equals(classes[0].name())) { - if (field.firstSentenceTags().length != 1) { - final String message = "Should be only one tag."; - throw new IllegalArgumentException(message); + final String message = + "The doclet should be used for TokenTypes only"; + throw new IllegalArgumentException(message); + } + + final FieldDoc[] fields = classes[0].fields(); + for (final FieldDoc field : fields) { + if (field.isStatic() && field.isPublic() && field.isFinal() + && "int".equals((field.type().qualifiedTypeName()))) + { + if (field.firstSentenceTags().length != 1) { + final String message = "Should be only one tag."; + throw new IllegalArgumentException(message); + } + ps.println(field.name() + "=" + + field.firstSentenceTags()[0].text()); } - ps.println(field.name() + "=" - + field.firstSentenceTags()[0].text()); + } + } + finally { + if (ps != null) { + ps.close(); } } - ps.close(); return true; } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/AbstractTreeTableModel.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/AbstractTreeTableModel.java index e8355cb5d..abb9e474c 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/AbstractTreeTableModel.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/gui/AbstractTreeTableModel.java @@ -33,8 +33,11 @@ package com.puppycrawl.tools.checkstyle.gui; -import javax.swing.tree.*; -import javax.swing.event.*; +import java.io.Serializable; +import javax.swing.event.EventListenerList; +import javax.swing.event.TreeModelEvent; +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreePath; /** * @version 1.2 10/27/98 @@ -42,15 +45,15 @@ import javax.swing.event.*; * of listeners. * @author Philip Milne */ - -public abstract class AbstractTreeTableModel implements TreeTableModel +public abstract class AbstractTreeTableModel implements TreeTableModel, + Serializable { private final Object mRoot; private final EventListenerList mListenerList = new EventListenerList(); public AbstractTreeTableModel(Object root) { - this.mRoot = root; + mRoot = root; } // diff --git a/suppressions.xml b/suppressions.xml index ae849da78..70218a230 100755 --- a/suppressions.xml +++ b/suppressions.xml @@ -22,7 +22,7 @@ lines="28"/> + lines="141"/>