View Javadoc
1   /*
2   JavadocMethod
3   allowedAnnotations = (default)Override
4   validateThrows = true
5   accessModifiers = (default)public, protected, package, private
6   allowMissingParamTags = (default)false
7   allowMissingReturnTag = (default)false
8   tokens = (default)METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF
9   
10  
11  */
12  
13  package com.puppycrawl.tools.checkstyle.checks.javadoc.javadocmethod;
14  
15  import java.io.File;
16  import java.io.FileNotFoundException;
17  import java.io.IOException;
18  
19  public class InputJavadocMethodExtraThrowsTwo {
20  
21       /**
22       * expicitly throwed  but throwed as variable, we do not catch this for now
23       * @param properties some value
24       */
25      public void doSomething7(String properties) {
26          // here is NPE possible
27          if (properties.charAt(0) == 0) {
28              IllegalArgumentException exception =
29                      new IllegalArgumentException("cannot have char with code 0");
30              throw exception;
31          }
32      }
33  
34      /**
35       * Actual exception thrown is child class of class that is declared in throws.
36       * It is limitation of checkstyle (as checkstyle does not know type hierarchy).
37       * Javadoc is valid not declaring {@link FileNotFoundException}
38       * BUT checkstyle can not distinguish relationship between exceptions.
39       * @param file some file
40       * @throws IOException if some problem
41       */
42      public void doSomething8(File file) throws IOException {
43          if (file == null) {
44              // violation below 'Expected @throws tag for 'FileNotFoundException'.'
45              throw new FileNotFoundException();
46          }
47      }
48  
49     /**
50      * Exact throw type referencing in javadoc even first is parent of second type.
51      * It is a limitation of checkstyle (as checkstyle does not know type hierarchy).
52      * This javadoc is valid for checkstyle and for javadoc tool.
53      * @param file some file
54      * @throws IOException if some problem
55      * @throws FileNotFoundException if file is not found
56      */
57      public void doSomething9(File file) throws IOException {
58          if (file == null) {
59              throw new FileNotFoundException();
60          }
61      }
62  }