Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

RTC.CALL

The Redundant Type Cast (RTC) warning appears when one adds cast to some class while invoking a method which is defined in a more general class. An example is below:

public class Apple {
public String someAppleToString(Object o) {
return ((Apple) o).toString();
}

}

In this example, a type-cast to Apple is redundant, because Apple class does not redefine toString() method and Object's method is actually used. The RTC.CALL warning appears when one adds cast to some class while invoking a method which is defined in a more general class.

Example 1

9      public class Instruction {
10     }
11     public class JmpInstruction extends Instruction {
12         private final Number address;
13         protected JmpInstruction(Number address) {
14             this.address = address;
15         }
16         public Number getAddress() {
17             return address;
18         }
19     }
20     public class ShortJmpInstruction extends JmpInstruction {
21         public ShortJmpInstruction(Byte address) {
22             super(address);
23         }
24     }
25     // ...
26     public void visitInstruction(JmpInstruction i) {
27         if (i instanceof ShortJmpInstruction) {
28             // cast is not necessary here
29             Number address =
30                     ((ShortJmpInstruction) i).getAddress();
31             print(address);
32         }
33         // then visit other instrucrions..
34     }

RTC.CALL is reported for line 30: Type cast from 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$JmpInstruction' to 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$ShortJmpInstruction' is redundant because method 'getAddress' is defined in 'com.klocwork.jdefects.checkers.ast.samples.RTC_CALL_Sample_1$JmpInstruction'