Skip to content

Binary Compatibility: Analyze type compatibility in assignments #181

@smarkwal

Description

@smarkwal

If an expression is used to calculate a value which is then assigned to a local variable, a field, a method call argument, the expected return type of the expression should be assignment compatible with the type of the variable, field, or method parameter.

Unfortunately, getting the type of an expression is not simple. Most likely, this requires byte code and data flow analysis.

Example:

  • Class A has a static method "write" with a parameter of interface type java.io.Serializable.
  • Class B calls A.write(new DataObject()).
  • The expression new DataObject() returns a value of type DataObject.
  • In order for this code to work, the class type DataObject must implement the interface Serializable.

The byte code for the above logic would first create an instance of class DataObject, put a reference to this object onto the stack, call its constructor (<init>()), and then call the method A.write(Serializable) which will take the reference for the argument from the stack. This means that stack analysis is required to find the actual type of the argument value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or idea

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions