You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gets a default value for this primitive type, as assigned by the compiler for variables that are declared but not initialized explicitly.
This is misleading; unless the source actually contains literals with the default value, the predicate will have no result (except for some BooleanLiterals which are found in the JDK code as part of annotations). For example for this Java code:
Would it make sense to deprecate the predicate (for removal) and instead adjust the only query using it (DeadStoreOfLocal.ql)?
It appears that query actually wants to find out if an assigned literal has a default value; so maybe it should be rewritten to explicitly test that. (Note that adding a predicate Literal.hasDefaultValue() might not make much sense because technically for StringLiterals type String the default value is null; and NullLiteral has no type which could occur as field type.)
There are several issues with
PrimitiveType.getADefaultValue():The documentation says:
This is misleading; unless the source actually contains literals with the default value, the predicate will have no result (except for some
BooleanLiterals which are found in the JDK code as part of annotations). For example for this Java code:the following query only finds
BooleanLiterals:The way it matches literals by using
getLiteral()misses some cases wheregetValue()would actually represent the default value (relates to Java: Replace incorrect usage ofLiteral.getLiteral()#6612).Would it make sense to deprecate the predicate (for removal) and instead adjust the only query using it (
DeadStoreOfLocal.ql)?It appears that query actually wants to find out if an assigned literal has a default value; so maybe it should be rewritten to explicitly test that. (Note that adding a predicate
Literal.hasDefaultValue()might not make much sense because technically forStringLiterals typeStringthe default value isnull; andNullLiteralhas no type which could occur as field type.)