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 — Unused format argument — CodeQL query help documentation

Unused format argument¶

ID: java/unused-format-argument
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - maintainability
   - useless-code
   - external/cwe/cwe-685
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

When formatting strings using printf-style format strings, one must ensure that the number of supplied arguments matches the number of arguments referenced by the format string. Additional arguments will be thrown away silently, which may not be the intended behavior, and too few arguments will cause an IllegalFormatException.

Format strings are used by the format method on the classes String, Formatter, Console, PrintWriter, and PrintStream. Several of these classes also supply the method alias printf. The class Console has two additional methods, readLine and readPassword, that also use format strings.

Recommendation¶

Change the format string to use all the arguments, or remove the unnecessary arguments.

Example¶

The following example supplies three arguments to be formatted, but the format string only refers to two arguments, so this will silently ignore the third argument.

System.out.format("First string: %s Second string: %s", "Hello", "world", "!");

References¶

  • Java API Specification: Format string syntax, Class String, Class Formatter, Class Console, Class PrintWriter, Class PrintStream.

  • SLF4J library: org.slf4j.Logger.

  • Common Weakness Enumeration: CWE-685.

  • © 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.