# Com / Example / Bugca002

## Overview

The `com.example.bugca002` package is a **test fixture** used to validate JSP parser behavior around page directive attribute ordering. It demonstrates **BUG-CA-002**: when the `language=` attribute appears before the `import=` attribute inside a JSP `<%@ page %>` directive, the parser fails to recognize the import statement and therefore does not create the expected `jsp_view` node with `referenced_classes` populated. This module exists solely to exercise and verify a fix for that parsing edge case.

## Key Classes and Interfaces

### KnownClass

**Source:** [`KnownClass.java`](bug-ca-002-attr-order/src/java/com/example/bugca002/KnownClass.java)

`KnownClass` is a minimal, no-op Java class deliberately placed in this package so that the JSP import can be resolved. It has no fields, no constructors beyond the implicit default, and a single method.

#### `execute()`

```java
public void execute() {}
```

- **Purpose:** Provides a method target that the JSP can conceptually reference. The method body is empty — this class exists only as a resolution target, not as part of any business logic.
- **Parameters:** None.
- **Returns:** `void`.
- **Side effects:** None.

## How It Works

This module is a regression test, so the "flow" is about **parsing**, not runtime execution. Here is what happens when the test fixture is processed:

1. The JSP file [`BugCa002Language Before Import.jsp`](bug-ca-002-attr-order/src/BugCa002Language Before Import.jsp) declares a page directive with `language="java"` placed **before** `import="com.example.bugca002.KnownClass"`:

   ```jsp
   <%@ page language="java" import="com.example.bugca002.KnownClass" contentType="text/html; charset=UTF-8" %>
   ```

2. The JSP parser encounters this directive and should:
   - Resolve the import of `com.example.bugca002.KnownClass`.
   - Create a `jsp_view` node for the page.
   - Attach `referenced_classes = ["com.example.bugca002.KnownClass"]` to that node.

3. **The bug:** When `language=` precedes `import=`, the parser skips over the `import=` attribute entirely. The result is that no `jsp_view` node is created, and the class reference is lost.

4. **The expected fix:** The parser should handle page directive attributes regardless of their order within the directive, treating each attribute independently.

### Attribute Order Sensitivity

JSP spec does not guarantee attribute order within a directive — attributes are a set, not a sequence. Parsers should therefore parse each `key=value` pair independently rather than relying on a specific ordering. This test case verifies that behavior.

## Relationships

```mermaid
flowchart LR
    JSP["BugCa002Language Before Import.jsp"] -->|imports| CLASS["KnownClass"]
    JSP -->|triggers| BUG["BUG-CA-002: attribute order bug"]
```

## Dependencies and Integration

- **Inbound (consumers):** The JSP page `BugCa002Language Before Import.jsp` references `KnownClass` via the `import` attribute in its page directive.
- **No package-level dependencies:** `KnownClass` does not import or depend on any external classes or frameworks.
- **No outbound dependencies:** This package is a leaf — it is not imported by or referenced from any other module in this project.

## Notes for Developers

- **This is a test fixture, not production code.** Do not refactor or extend this package with business logic — its sole purpose is to exercise a specific parser edge case.
- **The JSP filename contains a space:** `BugCa002Language Before Import.jsp`. If you are processing files in this directory, ensure your file-handling logic does not break on whitespace in filenames.
- **The class is intentionally trivial.** If you need to add test cases, add new classes rather than modifying `KnownClass`.
- **Related test fixtures:** Look in sibling `bug-ca-002-attr-order` project directory for additional related cases (e.g., variations of attribute ordering within JSP page directives).
