Inspection - Casting issue

Issue #1127 resolved
Jason Hardy created an issue

I'm just getting started with the tool. So far I'm impressed with it. I have found one annoying bit with the inspector though. I use a trigger factory context and it's not liking when I cast records inline.

2018-10-01_12-21-51.png

I've got the casting right because I use this method in all of my bulk actions in the trigger factory. It's not a huge deal since I can just disable that particular rule; however, I thought I would report it.

You can reproduce this through any trigger context when you're looping through the triggered records:

For the task object, here's how it would be:

for (Task tsk : Trigger.New == null ? (List<Task>) Trigger.Old : Trigger.New) {
    //Process tasks in the loop
}

Comments (3)

  1. Scott Wells repo owner

    Thanks for reporting, Jason. I'll take a look for one of the upcoming builds. I'm always trying to swat down inspection false negatives to ensure they're as reliable and informative as I can make them.

  2. Scott Wells repo owner

    Well, when I said "one of the upcoming builds" I promise that I meant something closer than two-and-a-half years later! But...I've just committed a fix for this. It's very much a corner case in Apex expression type inference, but it was resulting in code that compiles being flagged by IC2. The fix will be included in the next build, currently targeting tomorrow morning.

  3. Log in to comment