GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Javadoc has impossible ‘throws’ tag — CodeQL query help documentation

Javadoc has impossible ‘throws’ tag¶

ID: java/inconsistent-javadoc-throws
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - quality
   - maintainability
   - readability
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

A Javadoc @throws or @exception tag that references an exception that cannot be thrown is misleading.

Recommendation¶

Ensure that you only include the @throws or @exception tags in Javadoc when an exception can be thrown.

Example¶

The following example shows a method with Javadoc that claims it can throw Exception. Since Exception is a checked exception and the method does not declare that it may throw an exception, the Javadoc is wrong and should be updated.

/**
 * Javadoc for method.
 *
 * @throws Exception if a problem occurs.
 */
public void noThrow() {
	System.out.println("This method does not throw.");
}

In the following example the Javadoc has been corrected by removing the @throws tag.

/**
 * Javadoc for method.
 */
public void noThrow() {
	System.out.println("This method does not throw.");
}

References¶

  • Java SE Documentation: How to Write Doc Comments for the Javadoc Tool,

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.