Skip to content

[BUG] MazeRecursion crashes on small mazes #7671

Description

@NithinU2802

Description

In MazeRecursion.java

  • The maze solver can throw an ArrayIndexOutOfBoundsException when the maze is smaller than the hard-coded destination at row 6, column 5.
  • For example, calling solveMazeUsingFirstStrategy with a 2x2 maze causes an exception instead of handling the maze safely. The hard-coded start and destination also make it difficult to use the solver with mazes of other sizes.
  • It should handle maze boundaries safely and allow the start and destination to be specified for different maze sizes.
  • Also, would like to improve to avoid duplicated logic.

Steps to reproduce

  1. To update the MazeRecursion.java fix the issues
  2. Add test to MazeRecursionTest.java

Excepted behavior

  • To handle maze boundaries safely and must not throw an ArrayIndexOutOfBoundsException when the maze is smaller than the hard-coded destination.
  • It should validate the maze and handle invalid inputs, such as null, empty.
  • Preserve their specified traversal order and provide shared common solving logic to eliminate code duplication.
  • Add testcase to validate above things to check which are covered.

Screenshots

No response

Additional context

No response

Activity

  1. Meherab-hsn commented on Oct 31, 2026

    @Meherab-hsn

    Hi! I'd like to take this one. Looks like the crash comes from the hardcoded target map[6][5] — smaller mazes don't have that cell, so it throws ArrayIndexOutOfBounds. I'll derive the target position from the maze size instead and add tests with small mazes for both strategies. PR coming shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy