You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/10/13 16:30:28 UTC

svn commit: r824783 - in /commons/proper/math/trunk: checkstyle.xml src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java

Author: luc
Date: Tue Oct 13 14:30:27 2009
New Revision: 824783

URL: http://svn.apache.org/viewvc?rev=824783&view=rev
Log:
tightened checkstyle rules
catching top level exceptions (Exception, Throwable and RuntimeException) is now forbidden

Modified:
    commons/proper/math/trunk/checkstyle.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java

Modified: commons/proper/math/trunk/checkstyle.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/checkstyle.xml?rev=824783&r1=824782&r2=824783&view=diff
==============================================================================
--- commons/proper/math/trunk/checkstyle.xml (original)
+++ commons/proper/math/trunk/checkstyle.xml Tue Oct 13 14:30:27 2009
@@ -122,8 +122,10 @@
     <!-- Don't add up parentheses when they are not required -->
     <module name="UnnecessaryParentheses" />
 
-    <!--
+   <!--  Don't use too widespread catch (Exception, Throwable, RuntimeException)  -->
     <module name="IllegalCatch" />
+
+    <!--
     <module name="StringLiteralEquality" />
     <module name="MultipleStringLiterals" />
     <module name="MultipleVariableDeclarations" />

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=824783&r1=824782&r2=824783&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java Tue Oct 13 14:30:27 2009
@@ -118,7 +118,7 @@
         try {
             da.computeStats();
             fillBinStats(in);
-        } catch (Exception e) {
+        } catch (IOException e) {
             throw new MathRuntimeException(e);
         }
         loaded = true;
@@ -136,17 +136,7 @@
             new BufferedReader(new InputStreamReader(url.openStream()));
         try {
             DataAdapter da = new StreamDataAdapter(in);
-            try {
-                da.computeStats();
-            } catch (IOException ioe) {
-                // don't wrap exceptions which are already IOException
-                throw ioe;
-            } catch (RuntimeException rte) {
-                // don't wrap RuntimeExceptions
-                throw rte;
-            } catch (Exception e) {
-                throw MathRuntimeException.createIOException(e);
-            }
+            da.computeStats();
             if (sampleStats.getN() == 0) {
                 throw MathRuntimeException.createEOFException("URL {0} contains no data",
                                                               url);
@@ -173,17 +163,7 @@
         BufferedReader in = new BufferedReader(new FileReader(file));
         try {
             DataAdapter da = new StreamDataAdapter(in);
-            try {
-                da.computeStats();
-            } catch (IOException ioe) {
-                // don't wrap exceptions which are already IOException
-                throw ioe;
-            } catch (RuntimeException rte) {
-                // don't wrap RuntimeExceptions
-                throw rte;
-            } catch (Exception e) {
-                throw MathRuntimeException.createIOException(e);
-            }
+            da.computeStats();
             in = new BufferedReader(new FileReader(file));
             fillBinStats(in);
             loaded = true;
@@ -201,20 +181,23 @@
      * <code>beanStats</code> abstracting the source of data.
      */
     private abstract class DataAdapter{
+
         /**
          * Compute bin stats.
          *
-         * @throws Exception  if an error occurs computing bin stats
+         * @throws IOException  if an error occurs computing bin stats
          */
-        public abstract void computeBinStats()
-                throws Exception;
+        public abstract void computeBinStats() throws IOException;
+
         /**
          * Compute sample statistics.
          *
-         * @throws Exception if an error occurs computing sample stats
+         * @throws IOException if an error occurs computing sample stats
          */
-        public abstract void computeStats() throws Exception;
+        public abstract void computeStats() throws IOException;
+
     }
+
     /**
      * Factory of <code>DataAdapter</code> objects. For every supported source
      * of data (array of doubles, file, etc.) an instance of the proper object
@@ -248,7 +231,7 @@
      */
     private class StreamDataAdapter extends DataAdapter{
 
-        /** Input stream providng access to the data */
+        /** Input stream providing access to the data */
         private BufferedReader inputStream;
 
         /**
@@ -260,14 +243,10 @@
             super();
             inputStream = in;
         }
-        /**
-         * Computes binStats
-         *
-         * @throws IOException if an IO error occurs
-         */
+
+        /** {@inheritDoc} */
         @Override
-        public void computeBinStats()
-                throws IOException {
+        public void computeBinStats() throws IOException {
             String str = null;
             double val = 0.0d;
             while ((str = inputStream.readLine()) != null) {
@@ -279,11 +258,8 @@
             inputStream.close();
             inputStream = null;
         }
-        /**
-         * Computes sampleStats
-         *
-         * @throws IOException if an IOError occurs
-         */
+
+        /** {@inheritDoc} */
         @Override
         public void computeStats() throws IOException {
             String str = null;
@@ -315,11 +291,8 @@
             super();
             inputArray = in;
         }
-        /**
-         * Computes sampleStats
-         *
-         * @throws IOException if an IO error occurs
-         */
+
+        /** {@inheritDoc} */
         @Override
         public void computeStats() throws IOException {
             sampleStats = new SummaryStatistics();
@@ -327,14 +300,10 @@
                 sampleStats.addValue(inputArray[i]);
             }
         }
-        /**
-         * Computes binStats
-         *
-         * @throws IOException  if an IO error occurs
-         */
+
+        /** {@inheritDoc} */
         @Override
-        public void computeBinStats()
-            throws IOException {
+        public void computeBinStats() throws IOException {
             for (int i = 0; i < inputArray.length; i++) {
                 SummaryStatistics stats =
                     binStats.get(findBin(inputArray[i]));
@@ -367,17 +336,7 @@
         // Filling data in binStats Array
         DataAdapterFactory aFactory = new DataAdapterFactory();
         DataAdapter da = aFactory.getAdapter(in);
-        try {
-            da.computeBinStats();
-        } catch (IOException ioe) {
-            // don't wrap exceptions which are already IOException
-            throw ioe;
-        } catch (RuntimeException rte) {
-            // don't wrap RuntimeExceptions
-            throw rte;
-        } catch (Exception e) {
-            throw MathRuntimeException.createIOException(e);
-        }
+        da.computeBinStats();
 
         // Assign upperBounds based on bin counts
         upperBounds = new double[binCount];

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java?rev=824783&r1=824782&r2=824783&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/EmpiricalDistributionTest.java Tue Oct 13 14:30:27 2009
@@ -26,7 +26,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.RetryTestCase;
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.stat.descriptive.SummaryStatistics;
@@ -195,8 +194,8 @@
         EmpiricalDistribution dist = new EmpiricalDistributionImpl();
         try {
             dist.load((double[]) null);
-            fail("load((double[]) null) expected RuntimeException");
-        } catch (MathRuntimeException e) {
+            fail("load((double[]) null) expected NullPointerException");
+        } catch (NullPointerException e) {
             // expected
         } catch (Exception e) {
             fail("wrong exception caught");