Bird
0
0

Why does this code cause a runtime error?

medium📝 Debug Q7 of 15
Spring Boot - Spring Annotations
Why does this code cause a runtime error?
@Value("${app.timeout}")
private int timeout;

Given app.timeout=abc in properties.
AProperty name is invalid
BCannot convert 'abc' to int, causing type mismatch
CMissing default value causes error
DNo error, 'abc' is accepted as int
Step-by-Step Solution
Solution:
  1. Step 1: Analyze property value type

    The property 'app.timeout' has value 'abc' which is not a valid integer.
  2. Step 2: Understand type conversion failure

    Spring tries to convert 'abc' to int and fails, causing a runtime error.
  3. Final Answer:

    Cannot convert 'abc' to int, causing type mismatch -> Option B
  4. Quick Check:

    Invalid type conversion causes runtime error [OK]
Quick Trick: Property value must match field type to avoid errors [OK]
Common Mistakes:
  • Ignoring type mismatch errors
  • Assuming any string converts to int
  • Not validating property values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes