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 16 public class InputJavadocMethodThrowsDetectionTwo { 17 /** 18 * Nesting inside 2 layers of if statements. 19 * 20 * @param x some input for control flow statements 21 */ 22 void doubleNestedIf(int x) { 23 if (x >= 0) { 24 if (x <= 0) { 25 // violation below 'Expected @throws tag for 'IllegalArgumentException'.' 26 throw new IllegalArgumentException("0"); 27 } 28 } 29 } 30 31 /** 32 * Nesting inside 3 layers of if statements. 33 * 34 * @param x some input for control flow statements 35 */ 36 void tripleNestedIf(int x) { 37 if (x >= 0) 38 if (x <= 0) 39 if (x == 0) 40 // violation below 'Expected @throws tag for 'IllegalArgumentException'.' 41 throw new IllegalArgumentException("0"); 42 } 43 44 /** 45 * Throw outside but after if statement. 46 * 47 * @param x some input for control flow statements 48 */ 49 void throwAfterIf(int x) { 50 if (x > 0) { 51 x = 0; 52 } 53 // violation below 'Expected @throws tag for 'UnsupportedOperationException'.' 54 throw new UnsupportedOperationException(""); 55 } 56 57 /** 58 * Throw in catch but after if statement. 59 * 60 * @param x some input for control flow statements 61 */ 62 void tryCatchAfterIf(int x) { 63 if (x == 0) { 64 return; 65 } 66 try { 67 System.out.println("foo"); 68 } catch (Exception e) { 69 // violation below 'Expected @throws tag for 'RuntimeException'.' 70 throw new RuntimeException(e); 71 } 72 } 73 74 /** 75 * Throw in try/catch inside if statement. 76 * @param x some input for control flow statements 77 */ 78 void tryCatchWithinIf(int x) { 79 if (x == 0) { 80 try { 81 System.out.println("foo"); 82 } catch (Exception e) { 83 // violation below 'Expected @throws tag for 'RuntimeException'.' 84 throw new RuntimeException(e); 85 } 86 } 87 } 88 }