History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-21779
Type: Bug Bug
Status: Open Open
Priority: Normal Normal
Assignee: Maxim Shafirov
Reporter: Gibson
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

"Redundant type cast" inspection not triggered

Created: 29 May 07 13:00   Updated: 06 Nov 08 23:08
Component/s: Code Analysis. Inspection
Fix Version/s: Undefined

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 6,180
Severity: Medium


 Description  « Hide
public class CastTest
{
	public static void main (String[] args) throws CloneNotSupportedException
	{
		CastTest ct1 = new CastTest ();
		// The cast of ct1 is obviously redundant (although the cast of the result is necessary)
		CastTest ct2 = (CastTest) ((CastTest)ct1).clone (); 
	}
}


 All   Comments   Work Log   Change History      Sort Order:
AlexL - 29 Sep 07 12:35
I found the same problem. Here is my example.
BTW you should edit the title from "Reundant" to "Redundant" because I didn't find this Jira when I searched initially.
TestRedundantCast.java
package org.intellij;

import java.util.*;

/**
 * User: Alex
 */
public class TestRedundantCast
{
    void test() {
        Iterator it = ((List) Arrays.asList("1", "2","3")).iterator();
    }
}

If I Introduce variable for the List expression, then the redundant type cast will be flagged.

TestRedundantCast.java-After Introduce Variable
package org.intellij;

import java.util.*;

/**
 * User: Alex
 */
public class TestRedundantCast
{
    void test() {
        List list = (List) Arrays.asList("1", "2", "3");
        Iterator it = list.iterator();
    }
}

Similarly for Gibson's example, if you Introduce variable for the expression ((CastTest)ctl) first, then the reduandant type cast will be flagged.


Gibson - 01 Oct 07 14:16
I can't edit this bug to change the title, unfortunately, as I don't have the correct permissions.