"Variable xxx is never used" ?

I am a new user and I am using IntelliJ Idea 5.0.2. The code inspection always grey out some of variables and indicates "Variable xxx is never used". These variables do get used, however. I didn't have this problem in IntelliJ 4.5. Do anybody have any idea about this? Thanks.

6 comments

Can you provide an example?

Ping Ding wrote:

I am a new user and I am using IntelliJ Idea 5.0.2. The code inspection always grey out some of variables and indicates "Variable xxx is never used". These variables do get used, however. I didn't have this problem in IntelliJ 4.5. Do anybody have any idea about this? Thanks.

0

Maybe it's a known bug that causes inspections not to update. Do the warnings
go away if you edit the variable name (e.g. insert a character and delete it again)
or make global changes (e.g. reformat)?
Ping Ding wrote:

I am a new user and I am using IntelliJ Idea 5.0.2. The code inspection always grey out some of variables and indicates "Variable xxx is never used". These variables do get used, however. I didn't have this problem in IntelliJ 4.5. Do anybody have any idea about this? Thanks.

0

Hello Stephen,

Nope, this is a different case since Ping most probably says about local
variables, which do not encounter problems of analysis scope interdependencies.

-


Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Maybe it's a known bug that causes inspections not to update. Do the
warnings
go away if you edit the variable name (e.g. insert a character and
delete it again)
or make global changes (e.g. reformat)?
Ping Ding wrote:

>> I am a new user and I am using IntelliJ Idea 5.0.2. The code
>> inspection always grey out some of variables and indicates "Variable
>> xxx is never used". These variables do get used, however. I didn't
>> have this problem in IntelliJ 4.5. Do anybody have any idea about
>> this? Thanks.
>>


0

Thanks for replies!
Here is an example:

private void _processEnumeration(NdXmlSchemaSimpleType simpleType, _FactoryState state)
{
Enumeration enumValue = simpleType.getFacets(NdXmlSchemaFacet.ENUMERATION);

NdXmlEnumeration xmlClass = (NdXmlEnumeration) state.getXmlClass();
Vector enumV = new Vector();
int index = 0;

while (enumValue.hasMoreElements()) {
NdXmlSchemaFacet facet = (NdXmlSchemaFacet) enumValue.nextElement();
String value = facet.getValue();

// Create a property. There is no need to specify an XML Tag name since
// these are properties that correspond to values of an enumeration facet
// and not to attributes or sub-elements.
String propName = NdXmlEnumeration.EMPTY_ENUM_VALUE;
if (value.length() > 0) {
propName = NdXmlNameFactory.resolveAdvisorName(value);
}
NdXmlProperty prop = _createProperty(xmlClass,
propName, new NdXSType(NdXSType.INT_TYPE), null);
prop.setFixedValue(String.valueOf(index));

NdXmlSchemaSchema schema = simpleType.getSchema();
String schemaName = _schemaParser.getSchemaName(schema.getSchemaLocation());
String targetNamespace = _schemaParser.getTargetNamespace(schemaName);
String defaultPrefix = _schemaParser.getDefaultPrefix(schemaName);
if (targetNamespace != null) {
prop.setTargetNamespace(targetNamespace);
}
if (defaultPrefix != null) {
prop.setDefaultNamespacePrefix(defaultPrefix);
}

prop.setIsStatic(true);
prop.setReadWriteType(NdXmlProperty.TYPE_READ_ONLY);

xmlClass.addProperty(prop);
xmlClass.setInitialPropertyValue(propName, value);

NdXmlEnumValueDescriptor enumValueDescriptor = new NdXmlEnumValueDescriptor(xmlClass, propName, index);
enumValueDescriptor.setNativeName(value);
enumV.addElement(enumValueDescriptor);
index++;
}
NdXmlEnumValueDescriptor[] enumValues = new NdXmlEnumValueDescriptor[enumV.size()];
enumV.copyInto(enumValues);
xmlClass.setEnumValues(enumValues);
}

Inside this method scope, almost every variables are grey out (simpleType, state, enumValue, xmlClass, enumV, index, .....) and if moving the cursor on the variables, it says "Variable xxxx is never used". These variables are apparently used in the method.

One thing I should mention is this problem only occurs in this one class file and I got IDE fatal errors in my IntelliJ as

Assertion failed
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
at com.intellij.psi.impl.file.impl.FileManagerImpl.findFile(FileManagerImpl.java:421)
at com.intellij.psi.impl.RepositoryElementsManager.a(RepositoryElementsManager.java:47)
at com.intellij.psi.impl.RepositoryElementsManager.findOrCreatePsiElementById(RepositoryElementsManager.java:209)
at com.intellij.psi.impl.compiled.ClsClassImpl.getParent(ClsClassImpl.java:359)
at com.intellij.psi.impl.compiled.ClsElementImpl.isValid(ClsElementImpl.java:61)
at com.intellij.psi.impl.file.impl.FileManagerImpl.a(FileManagerImpl.java:51)
at com.intellij.psi.impl.file.impl.FileManagerImpl.findClass(FileManagerImpl.java:137)
at com.intellij.psi.impl.PsiManagerImpl$PsiElementFinderImpl.findClass(PsiManagerImpl.java:36)
at com.intellij.psi.impl.PsiManagerImpl.findClass(PsiManagerImpl.java:138)
at com.intellij.psi.impl.file.PsiPackageImpl.a(PsiPackageImpl.java:144)
at com.intellij.psi.impl.file.PsiPackageImpl.processDeclarations(PsiPackageImpl.java:19)
at com.intellij.psi.scope.util.PsiScopesUtil.processScope(PsiScopesUtil.java:44)
at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.a(PsiJavaFileBaseImpl.java:34)
at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.a(PsiJavaFileBaseImpl.java:41)
at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.processDeclarations(PsiJavaFileBaseImpl.java:51)
at com.intellij.psi.scope.util.PsiScopesUtil.processScope(PsiScopesUtil.java:44)
at com.intellij.psi.scope.util.PsiScopesUtil.treeWalkUp(PsiScopesUtil.java:173)
at com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil.java:21)
at com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil.java:19)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.b(PsiJavaCodeReferenceElementImpl.java:203)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.access$000(PsiJavaCodeReferenceElementImpl.java:302)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver._resolve(PsiJavaCodeReferenceElementImpl.java:5)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver.resolve(PsiJavaCodeReferenceElementImpl.java:10)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:67)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:73)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.multiResolve(PsiJavaCodeReferenceElementImpl.java:384)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.advancedResolve(PsiJavaCodeReferenceElementImpl.java:73)
at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visitReferenceElement(HighlightVisitorImpl.java:545)
at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.accept(PsiJavaCodeReferenceElementImpl.java:79)
at com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visit(HighlightVisitorImpl.java:4)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$1.run(GeneralHighlightingPass.java:3)
at com.intellij.psi.impl.PsiManagerImpl.performActionWithFormatterDisabled(PsiManagerImpl.java:220)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:148)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.doCollectInformation(GeneralHighlightingPass.java:103)
at com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:9)
at com.intellij.codeInsight.daemon.impl.UpdateThread$2.run(UpdateThread.java:11)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:153)
at com.intellij.codeInsight.daemon.impl.UpdateThread.a(UpdateThread.java:19)
at com.intellij.codeInsight.daemon.impl.UpdateThread.access$100(UpdateThread.java:49)
at com.intellij.codeInsight.daemon.impl.UpdateThread$1.run(UpdateThread.java:0)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:6)
at com.intellij.codeInsight.daemon.impl.UpdateThread.run(UpdateThread.java:23)

Thanks for any help!

0

Hello Ping,

The problem indeed seem to be caused by exception you've mentioned. The workaround
would be to wipe out caches directory (usualy at %USER_HOME%\.IntelliJIDEA50\system\caches)
and restart IDEA.

-


Maxim Shafirov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Thanks for replies!
Here is an example:
private void _processEnumeration(NdXmlSchemaSimpleType simpleType,
_FactoryState state)
{
Enumeration enumValue =
simpleType.getFacets(NdXmlSchemaFacet.ENUMERATION);
NdXmlEnumeration xmlClass = (NdXmlEnumeration) state.getXmlClass();
Vector enumV = new Vector();
int index = 0;
while (enumValue.hasMoreElements()) {
NdXmlSchemaFacet facet = (NdXmlSchemaFacet)
enumValue.nextElement();
String value = facet.getValue();
// Create a property. There is no need to specify an XML Tag name
since
// these are properties that correspond to values of an enumeration
facet
// and not to attributes or sub-elements.
String propName = NdXmlEnumeration.EMPTY_ENUM_VALUE;
if (value.length() > 0) {
propName = NdXmlNameFactory.resolveAdvisorName(value);
}
NdXmlProperty prop = _createProperty(xmlClass,
propName, new
NdXSType(NdXSType.INT_TYPE), null);
prop.setFixedValue(String.valueOf(index));
NdXmlSchemaSchema schema = simpleType.getSchema();
String schemaName =
_schemaParser.getSchemaName(schema.getSchemaLocation());
String targetNamespace =
_schemaParser.getTargetNamespace(schemaName);
String defaultPrefix = _schemaParser.getDefaultPrefix(schemaName);
if (targetNamespace != null) {
prop.setTargetNamespace(targetNamespace);
}
if (defaultPrefix != null) {
prop.setDefaultNamespacePrefix(defaultPrefix);
}
prop.setIsStatic(true);
prop.setReadWriteType(NdXmlProperty.TYPE_READ_ONLY);
xmlClass.addProperty(prop);
xmlClass.setInitialPropertyValue(propName, value);
NdXmlEnumValueDescriptor enumValueDescriptor = new
NdXmlEnumValueDescriptor(xmlClass, propName, index);
enumValueDescriptor.setNativeName(value);
enumV.addElement(enumValueDescriptor);
index++;
}
NdXmlEnumValueDescriptor[] enumValues = new
NdXmlEnumValueDescriptor[enumV.size()];
enumV.copyInto(enumValues);
xmlClass.setEnumValues(enumValues);
}
Inside this method scope, almost every variables are grey out
(simpleType, state, enumValue, xmlClass, enumV, index, .....) and if
moving the cursor on the variables, it says "Variable xxxx is never
used". These variables are apparently used in the method.

One thing I should mention is this problem only occurs in this one
class file and I got IDE fatal errors in my IntelliJ as

Assertion failed
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
at
com.intellij.psi.impl.file.impl.FileManagerImpl.findFile(FileManagerIm
pl.java:421)
at
com.intellij.psi.impl.RepositoryElementsManager.a(RepositoryElementsMa
nager.java:47)
at
com.intellij.psi.impl.RepositoryElementsManager.findOrCreatePsiElement
ById(RepositoryElementsManager.java:209)
at
com.intellij.psi.impl.compiled.ClsClassImpl.getParent(ClsClassImpl.jav
a:359)
at
com.intellij.psi.impl.compiled.ClsElementImpl.isValid(ClsElementImpl.j
ava:61)
at
com.intellij.psi.impl.file.impl.FileManagerImpl.a(FileManagerImpl.java
:51)
at
com.intellij.psi.impl.file.impl.FileManagerImpl.findClass(FileManagerI
mpl.java:137)
at
com.intellij.psi.impl.PsiManagerImpl$PsiElementFinderImpl.findClass(Ps
iManagerImpl.java:36)
at
com.intellij.psi.impl.PsiManagerImpl.findClass(PsiManagerImpl.java:138
)
at
com.intellij.psi.impl.file.PsiPackageImpl.a(PsiPackageImpl.java:144)
at
com.intellij.psi.impl.file.PsiPackageImpl.processDeclarations(PsiPacka
geImpl.java:19)
at
com.intellij.psi.scope.util.PsiScopesUtil.processScope(PsiScopesUtil.j
ava:44)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.a(PsiJavaFileBaseImpl
.java:34)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.a(PsiJavaFileBaseImpl
.java:41)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.processDeclarations(P
siJavaFileBaseImpl.java:51)
at
com.intellij.psi.scope.util.PsiScopesUtil.processScope(PsiScopesUtil.j
ava:44)
at
com.intellij.psi.scope.util.PsiScopesUtil.treeWalkUp(PsiScopesUtil.jav
a:173)
at
com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil
.java:21)
at
com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil
.java:19)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.b(PsiJava
CodeReferenceElementImpl.java:203)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.access$00
0(PsiJavaCodeReferenceElementImpl.java:302)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGeneri
csResolver._resolve(PsiJavaCodeReferenceElementImpl.java:5)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGeneri
csResolver.resolve(PsiJavaCodeReferenceElementImpl.java:10)
at
com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(R
esolveCache.java:67)
at
com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(R
esolveCache.java:73)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.multiReso
lve(PsiJavaCodeReferenceElementImpl.java:384)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.advancedR
esolve(PsiJavaCodeReferenceElementImpl.java:73)
at
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.vis
itReferenceElement(HighlightVisitorImpl.java:545)
at
com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.accept(Ps
iJavaCodeReferenceElementImpl.java:79)
at
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.vis
it(HighlightVisitorImpl.java:4)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$1.run(Gen
eralHighlightingPass.java:3)
at
com.intellij.psi.impl.PsiManagerImpl.performActionWithFormatterDisable
d(PsiManagerImpl.java:220)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(General
HighlightingPass.java:148)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.doCollect
Information(GeneralHighlightingPass.java:103)
at
com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPass.collec
tInformation(TextEditorHighlightingPass.java:9)
at
com.intellij.codeInsight.daemon.impl.UpdateThread$2.run(UpdateThread.j
ava:11)
at
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(Ap
plicationImpl.java:153)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.a(UpdateThread.java:
19)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.access$100(UpdateThr
ead.java:49)
at
com.intellij.codeInsight.daemon.impl.UpdateThread$1.run(UpdateThread.j
ava:0)
at
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(Prog
ressManagerImpl.java:6)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.run(UpdateThread.jav
a:23)
Thanks for any help!



0

Thanks Maxim. The problem disappears after I clean up the cache.

ping

0

Please sign in to leave a comment.