Cannot Resolve Symbol - Field class

Issue #1613 resolved
August Detlefsen created an issue

I have an Apex class called 'Field' defined in my 'classes' directory, but IlluminatedCloud is saying that it cannot resolve the symbol.

Per Scott Wells:

That's almost certainly because ‘Field’ is also an Apex reserved word.

Comments (10)

  1. Scott Wells repo owner

    August, I'm actually unable to reproduce this:

    Issue_1613.png

    Can you do me a favor and regenerate your OST to see if that resolves the issue?

  2. Jonny Power (he/him)

    August - are you developing in a scratch org with a namespace by any chance? If so, does your offline table have a Field.cls in a namespaced subdirectory?

    I've found the symbol tree to get tricked in multi-module projects against namespaced DX orgs, where IC2 expects the class to be referenced by namespace if it has a symbol in the namespace subfolder. This is typically only a problem for classes defined in a module outside of the default module referencing other classes defined outside the default module.

    It's hacky but we've added a build process hook into intellij that clears these symbols from the offline symbol table to get around this.

  3. Scott Wells repo owner

    Jonny, do you mind reaching out to me directly to help me understand this workaround you've had to implement a bit more. I want to make sure that I fix it and you don't have to implement such a workaround. If you've already reported it somewhere, my apologies for letting it slip off my radar; just send me the issue number.

  4. Scott Wells repo owner

    Eric, that still doesn't show as an error for me:

    Issue_1613_20220412.png

    I tried it in both Anonymous Apex and in a dedicated class file, and in both cases there were no errors and all references resolved appropriately. Are you able to do this in 100% isolation of other files in a given project? I'm wondering if something else in the project is being picked up during reference resolution or something.

  5. Eric Kintzer

    so, perhaps this is the clue --

    In the org, there is a managed package Selector, namespace = Select that has a class called Field. If you look at the readme for that package, you’ll note that the usage is: Select.Field.xxx(). Not Select__Field.xxx()

  6. Eric Kintzer

    OK, I’m not convinced by the above; today in my project I started seeing inner class code inspection errors where the inner class type was not recognized within the same outer class file. So, I attempted to reproduce in anonymous apex:

    public class MyOuter {
        MyInner myInner;
        public class MyInner{}
    }
    

    I updated to 2.2.1.6, refreshed OST/rebuilt caches and indexes and the code inspection worked in my real class files but had no effect in the anon apex as shown above.

    How I got to this point … For example, in my real class file SlackService I had an inner class. All fine with respect to code inspector

    public class SlackService {
    
     public class SomeOtherClass {}
    
     public class Text {
      String text;
      }
    
     public class AnotherClass{}
    } 
    

    then , I edited the file and added a fluent item:

    public class SlackService {
    
     public class SomeOtherClass {}
    
     public class Text {
      String text;
      public Text withText(String val) {this.text = val; return this;}
      }
    
     public class AnotherClass{}
    }
    

    and line 7 suddenly popped up in red with Text being an unresolved symbol. Of course it compiles fine. There are no managed package classes named Text. Rebuilding OST/cache/indices after upgrading to 2.2.1.6 resolved the inspector (but not the anon apex one ^). I wish I could localize this more for you Let me know what else I can provide.

    UPDATE: So, I’m continuing to edit my SlackService outer class which happens to have 30 inner classes.

    As I add fluent methods within each inner class as in:

    public class Inner6 {
      Inner28 someField;
    
      public Inner6 withSomeField(Inner28 val) {this.somefield = val; return this;}
      }
    }
    ...
    public class Inner28 {
      ..
    }  
    

    the references to Inner28 suddenly go red - unable to resolve symbol. It seems to be a density of inner class issue??? And, not every further down the class file references to Inner classes go red

    These inner class refs go red:

    Confirm, Text, OptionGroup

    These inner class refs do not go red:

    Option, Filter, Message

    To test out the reserved word hypothesis, I renamed the inner class Confirm to ConfirmX - this resolved the red symbol not found

    Then, I renamed ConfirmX back to Confirm - went back to Red . Hmm - perhaps alleged reserved words are the issue?

    No … it appears Illuminated Cloud knows about an Apex Slack namespace. There seems to be a (undocumented in V54) Slack.Text class, a Slack.Confirm class, a Slack.OptionGroup class. Perhaps your code inspector is confusing my inner class Text with the Slack.Text class - but only on some weird delayed basis. Doesn’t explain the anon apex example ^ though.

  7. Scott Wells repo owner

    I'm still unable to reproduce this behavior. Definitely the best way for me to get to the bottom of it would be a simple standalone project where you can reproduce it (semi-?)consistently shared so I could open the same project.

  8. Scott Wells repo owner

    Issue tracker grooming. If this is still an issue, please feel free to reopen, ideally with a concrete reproduction scenario.

  9. Log in to comment