[FIXED Use filename as hash code on IO exceptions.
@@ -19,17 +19,15 @@ public class ContextHashCode {
* Creates a hash code from the source code of the warning line and the
* surrounding context.
*
- * @param fileName
- * the absolute path of the file to read
- * @param line
- * the line of the warning
- * @param encoding
- * the encoding of the file, if <code>null</code> or empty then
- * the default encoding of the platform is used
+ * @param fileName the absolute path of the file to read
+ * @param line the line of the warning
+ * @param encoding the encoding of the file, if <code>null</code> or empty then the default encoding of the platform
+ * is used
* @return a has code of the source code
- * @throws IOException
- * if the contents of the file could not be read
+ * @throws IOException if the contents of the file could not be read
+ * @deprecated use {@link #compute(String, int, String)}, so no exception will be thrown
*/
+ @Deprecated
public int create(final String fileName, final int line, final String encoding) throws IOException {
LineIterator lineIterator = EncodingValidator.readFile(fileName, encoding);
@@ -47,5 +45,25 @@ public class ContextHashCode {
return context.toString().hashCode();
}
+
+ /**
+ * Creates a hash code from the source code of the warning line and the
+ * surrounding context.
+ *
+ * @param fileName the absolute path of the file to read
+ * @param line the line of the warning
+ * @param encoding the encoding of the file, if <code>null</code> or empty then the default encoding of the platform
+ * is used
+ * @return a has code of the source code
+ */
+ @SuppressWarnings("deprecation")
+ public int compute(final String fileName, final int line, final String encoding) {
+ try {
+ return create(fileName, line, encoding);
+ }
+ catch (IOException e) {
+ return fileName.hashCode();
+ }
+ }
}
