SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Bug 047

Format string placeholder incompatible with passed argument (VA_FORMAT_STRING_BAD_ARGUMENT)

Inspired by

Original Description

“The format string placeholder is incompatible with the corresponding argument. For example, System.out.printf(”%d\n“, “hello”); The %d placeholder requires a numeric argument, but a string value is passed instead. A runtime exception will occur when this statement is executed.” – 2013-12-02

Detailed Description

If the format string passed to the printf() method is not compatible with the argument in printf() method, it should detect the error at compilation time instead of throwing run-time exception (which is currently done by IDE).

Sample Problem Scenario

class Sample {
              public static void main(String[] args){     
              System.out.printf("%d\n","hello");
      
            }       
      }

Sample Fix

It is possible to correct the code by replacing the format string with correct one as shown in following example

    class Sample {
              public static void main(String[] args){     
              System.out.printf("%s\n","hello");
      
            }       
      }

Evaluation Results

Benchmark project Precision Recall
FB JT Delta FB JT Delta
Project … …% …% …% …% …% …%
Project … …% …% …% …% …% …%

FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs

teaching/labs/mdse/2013/bug_descriptions/jt-bug-cor047.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2023