AdvantageKit icon indicating copy to clipboard operation
AdvantageKit copied to clipboard

Attempts at log replay cause ClassCastExceptions for all MutableMeasure types

Open godmar opened this issue 1 month ago • 0 comments

Describe the bug When replaying a log that contains logged data of types that are a subtype of MutableMeasure, a ClassCastException occurs. This means AdvantageKit cannot replay logs containing mutable measure types at this point.

To Reproduce Steps to reproduce the behavior: Described here.

Expected behavior The logged value should be restored with the proper type.

Version (required):

  • OS: any
  • Project Information: akit 4.0.0.

Additional context This is already discussed in #222 but I am adding this bug report to ensure it's flagged as a bug rather than a feature request. PR #224 provides a fix and unit tests. This bug was introduced by @jwbonner in commit 252cbe193994a109aa9bdf236389dba39193a566. It is my belief that this code never worked and was never tested.

For background, Java's generics use type erasure. This means that the cast (M) doesn't actually transform the GenericMutableMeasureImpl into the required type; rather, an object of type GenericMutableMeasureImpl is returned.

The following Java statement, which was created by akit's annotation processor:

    largeEncoderPos = table.get("LargeEncoderPos", largeEncoderPos);

compiles because this overload of table.get could return a MutAngle object, but the compiler inserts a checkcast bytecode instruction to ensure that it actually did:

      36: invokevirtual #115                // Method org/littletonrobotics/junction/LogTable.get:(Ljava/lang/String;Ledu/wpi/first/units/MutableMeasure;)Ledu/wpi/first/units/MutableMeasure;
      39: checkcast     #118                // class edu/wpi/first/units/measure/MutAngle
      42: putfield      #28                 // Field largeEncoderPos:Ledu/wpi/first/units/measure/MutAngle;

It is this checkcast instruction that fails because the object return is of type GenericMutableMeasureImpl instead of the required MutAngle type. It would be great if this could make it upstream before kickoff. Thank you.

godmar avatar Nov 27 '25 16:11 godmar