I am having a strange bug in IntelliJ where I have a base class that has a protected member which I am accessing in the constructor of a derived class several inheritance levels deeper, i.e. something like this (except that there are more layers in between but the structure is the same):
public class Base {
...
protected boolean fieldX;
public Base() {
fieldX = false;
}
... <code that uses fieldX here> ...
}
public class Derived1 extends Base {
...
}
public class Derived2 extends Derived1 {
public Derived2() {
super();
this.fieldX = true;
}
...
}
The bug manifests in that IntelliJ colors the member (here fieldX
) in red and the error message when hovering over it reads:
cannot resolve symbol
fieldX
However, I can build and run the project just fine.
I also tried declaring the fieldX
as public in order to get rid of the error highlighting but that didn’t change anything. Of course, trying to create a minimal reproducer didn’t work either. Here the fieldX was always resolvable – as it should be and as one would expect!
Any idea why IntelliJ (or actually AndroidStudio Koala) stumbles over this??? Anything cached that one could erase?
Android Studio Koala Feature Drop | 2024.1.2
Build #AI-241.18034.62.2412.12266719, built on August 22, 2024
Runtime version: 17.0.11+0--11852314 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 4076M
Cores: 8
Registry:
documentation.show.toolbar=true
Non-Bundled Plugins:
PlantUML integration (7.10.1-IJ2023.2)
Batch Scripts Support (1.0.13)
CMD Support (1.0.5)
For the benefit of anyone stumbling over this question: Clearing AndroidStudio’s caches made these errors go away:
File –> Invalidate Caches… –> tick “Clear File system cache and Local History” and then click the “Invalidate and Restart”-button.
After the following restart IntelliJ/Android Studio obviously re-read all library files and that made these errors wrongly flagging members as “non resolvable” henceforth to be happily accepted.