https://bz.apache.org/bugzilla/show_bug.cgi?id=69693

            Bug ID: 69693
           Summary: Improve readability and type safety by changing
                    parsingRequestLinePhase to an enum in
                    Http11InputBuffer
           Product: Tomcat 11
           Version: 11.0.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Connectors
          Assignee: dev@tomcat.apache.org
          Reporter: devjohnp...@gmail.com
  Target Milestone: -------

The Http11InputBuffer class in Apache Tomcat currently uses an int type for the
parsingRequestLinePhase field to track the state of request line parsing. While
this implementation is functionally sound, it has the following drawbacks:

* Readability: Integer values do not clearly convey the meaning of the state.
For example, it is not immediately obvious from the code alone that
parsingRequestLinePhase == 0 represents the "METHOD" state.
* Type Safety: The int type allows invalid values, such as negative numbers or
values outside the expected range, to be assigned, which could lead to runtime
errors.

To address these issues, we propose changing the type of
parsingRequestLinePhase from int to an enum called RequestLineParsePhase. This
enum defines explicit constants for each state (e.g., METHOD, URI, etc.),
improving code readability and leveraging Java's enum features to ensure only
valid states are assigned.

To maintain compatibility with existing code, the enum includes an int phase
field to preserve the integer representation of states. Additionally, the
public int getParsingRequestLinePhase() method has been modified to return this
integer value, ensuring no impact on external code.
This change enhances the maintainability and stability of the Http11InputBuffer
class without introducing functional changes. All existing tests have passed,
confirming the consistency of behavior.

* Future Intention: If this PR is merged, a potential follow-up task could be
to remove the getParsingRequestLinePhase() method and provide more specific,
intention-revealing methods for Http11Processor, further improving readability
and decoupling.

See
https://github.com/apache/tomcat/pull/855

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to