robototes / Crescendo2024

Other
8 stars 13 forks source link

Null pointer exceptions are thrown when any of drivebase, intake, or launcher subsystems are disabled #90

Open TAKBS2412 opened 3 months ago

TAKBS2412 commented 3 months ago

Probably low priority, since (hopefully) we won't have to run in competition with subsystems disabled.

Sample intake disabled stacktrace:

Error at java.base/java.util.Objects.requireNonNull(Objects.java:233): Unhandled exception: java.lang.NullPointerException: Parameter requirement in method addRequirements was null when it should not have been!  Check the stacktrace to find the responsible line of code - usually, it is the first line of user-written code indicated in the stacktrace.  Make sure all objects passed to the method in question were properly initialized - note that this may not be obvious if it is being called under dynamically-changing conditions!  Please do not seek additional technical assistance without doing this first!
        at java.base/java.util.Objects.requireNonNull(Objects.java:233)
        at edu.wpi.first.util.ErrorMessages.requireNonNullParam(ErrorMessages.java:27)
        at edu.wpi.first.wpilibj2.command.Command.addRequirements(Command.java:92)
        at frc.team2412.robot.commands.intake.IntakeStopCommand.<init>(IntakeStopCommand.java:11)
        at frc.team2412.robot.util.AutoLogic.registerCommands(AutoLogic.java:54)
        at frc.team2412.robot.util.AutoLogic.<init>(AutoLogic.java:46)
        at frc.team2412.robot.Robot.robotInit(Robot.java:86)
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:433)
        at java.base/java.lang.Thread.run(Thread.java:833)

Sample launcher disabled stacktrace:

Error at java.base/java.util.Objects.requireNonNull(Objects.java:233): Unhandled exception: java.lang.NullPointerException: Parameter requirement in method addRequirements was null when it should not have been!  Check the stacktrace to find the responsible line of code - usually, it is the first line of user-written code indicated in the stacktrace.  Make sure all objects passed to the method in question were properly initialized - note that this may not be obvious if it is being called under dynamically-changing conditions!  Please do not seek additional technical assistance without doing this first!
        at java.base/java.util.Objects.requireNonNull(Objects.java:233)
        at edu.wpi.first.util.ErrorMessages.requireNonNullParam(ErrorMessages.java:27)
        at edu.wpi.first.wpilibj2.command.Command.addRequirements(Command.java:92)
        at frc.team2412.robot.commands.launcher.FullTargetCommand.<init>(FullTargetCommand.java:43)
        at frc.team2412.robot.util.AutoLogic.registerCommands(AutoLogic.java:59)
        at frc.team2412.robot.util.AutoLogic.<init>(AutoLogic.java:46)
        at frc.team2412.robot.Robot.robotInit(Robot.java:86)
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:433)
        at java.base/java.lang.Thread.run(Thread.java:833)

Sample drivebase disabled stacktrace:

Error at frc.team2412.robot.commands.launcher.FullTargetCommand.<init>(FullTargetCommand.java:41): Unhandled exception: java.lang.NullPointerException: Cannot invoke "frc.team2412.robot.subsystems.DrivebaseSubsystem.rotateToAngle(java.util.function.Supplier, boolean)" because "drivebaseSubsystem" is null
        at frc.team2412.robot.commands.launcher.FullTargetCommand.<init>(FullTargetCommand.java:41)
        at frc.team2412.robot.util.AutoLogic.registerCommands(AutoLogic.java:59)
        at frc.team2412.robot.util.AutoLogic.<init>(AutoLogic.java:46)
        at frc.team2412.robot.Robot.robotInit(Robot.java:86)
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:433)
        at java.base/java.lang.Thread.run(Thread.java:833)
TAKBS2412 commented 3 months ago

One interesting thing for the future would be adding separate tests with different subsystems enabled/disabled (based off our existing simulation test) to catch errors like this in CI.

jamesdooley4 commented 3 months ago

One big cause of this is the call to AutoLogic.initShuffleBoard that instantiates the static commandsMap variable, which instances a bunch of static List variables and the AutoPath items in those lists. Those all assume there's a drivebase subsystem that's already configured PathPlanner, and crash if that's not the case.