Skip to content

[java] AST inconsistency between primitive and reference type arrays #910

Closed
@oowekyala

Description

Array types are represented by a ReferenceType with attributes IsArray and ArrayDepth set accordingly. ReferenceType nodes then either have a PrimitiveType or a ClassOrInterfaceType child, depending on whether the component type of the array is primitive or not. Both these node types have the attributes IsArray and ArrayDepth too.

The problem is that, with arrays of primitive types, these attributes are set only on the parent ReferenceType, and not on the PrimitiveType node. For arrays of reference type, the attributes are correctly set.

This causes ClassTypeResolver to resolve the type of the formal parameter keys as int and not int[] in the following snippet, since the type of the ReferenceType node is rolled up from its child. (try with the designer)

public abstract class AbstractClass {
    public void arrayParams(int[] keys, String[] labels) {
	int[] foo = new int[5];
   }
}

I think the root problem is that only the parent ReferenceType should know about array dimensions, if the child node is to represent the component type. If removing those attributes is too inconvenient, we could also just patch the parser so that the attributes are correctly set on PrimitiveType. Either way, there's an inconsistency to rule out.

Metadata

Assignees

Labels

a:bugPMD crashes or fails to analyse a file.in:astAbout the AST structure or API, the parsing stepin:type-resolutionAffects the type resolution code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions