Skip to content

fix: allow reserved keywords in package names for class references (#103)#486

Merged
lukaszlenart merged 1 commit intomainfrom
claude/analyze-issue-proposal-011CUu8SKqVevG29u3vRC1DV
Nov 29, 2025
Merged

fix: allow reserved keywords in package names for class references (#103)#486
lukaszlenart merged 1 commit intomainfrom
claude/analyze-issue-proposal-011CUu8SKqVevG29u3vRC1DV

Conversation

@lukaszlenart
Copy link
Copy Markdown
Collaborator

Summary

Fixes parsing error when OGNL class references contain reserved keywords like or, and, not in package names.

Before: @jp.or.example.Utils@method() → ExpressionSyntaxException
After: @jp.or.example.Utils@method() → ✅ Parses successfully

Problem

The parser treated or, and, not, etc. as operator keywords everywhere, preventing their use in package names. This broke support for Japanese domain packages like jp.or.*.

Solution

Added classNamePart() helper that accepts both identifiers and reserved keywords when parsing class names. Updated className() and instanceof productions to use it.

Fixes #103

@lukaszlenart lukaszlenart force-pushed the claude/analyze-issue-proposal-011CUu8SKqVevG29u3vRC1DV branch 3 times, most recently from 440beab to fbebd26 Compare November 7, 2025 20:33
)

This commit resolves Issue #103 where the OGNL parser would fail to parse
class references containing reserved keywords (like "or", "and", "not", etc.)
in package names.

Problem:
--------
Expressions like `@jp.or.example.IdUtils@generateId()` would fail at parse
time with ExpressionSyntaxException because "or" was tokenized as a keyword
rather than as part of the package name.

Root Cause:
-----------
In JavaCC, string literals used as operators in grammar productions (e.g.,
"or" for logical OR) become implicit keyword tokens that take precedence
over generic IDENT tokens during lexical analysis.

Solution:
---------
- Added new `classNamePart()` production that accepts either IDENT tokens
  or any reserved keywords, treating them as identifiers in the context
  of class/package names
- Updated `className()` production to use `classNamePart()` instead of
  direct IDENT references
- Updated `instanceof` production similarly to handle keywords in type names

Changes:
--------
- Modified: ognl/src/main/javacc/ognl.jj
  - Added classNamePart() helper production (lines 1389-1418)
  - Updated className() to use classNamePart() (lines 1374-1382)
  - Updated instanceof production to use classNamePart() (lines 948-969)

- Added: ognl/src/test/java/ognl/test/PackageKeywordTest.java
  - Comprehensive test coverage for keywords in package names
  - Tests for: or, and, not, in, and multiple keywords
  - Validates that parsing succeeds (no ExpressionSyntaxException)

- Added: ISSUE_103_ANALYSIS.md
  - Detailed analysis of the problem and solution
  - Impact analysis and backward compatibility notes
  - Build and verification instructions

Impact:
-------
- Fully backward compatible (only expands valid expressions)
- No ambiguity introduced (context is unambiguous)
- Keywords remain functional as operators in expression contexts
- Aligns with real-world Java package naming (e.g., jp.or.* domains)

Testing:
--------
The fix requires regenerating the parser via `mvn compile` which runs the
javacc-maven-plugin. All existing tests should continue to pass.

Fixes #103
@lukaszlenart lukaszlenart force-pushed the claude/analyze-issue-proposal-011CUu8SKqVevG29u3vRC1DV branch from fbebd26 to 08748f0 Compare November 7, 2025 20:35
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Nov 7, 2025

@lukaszlenart lukaszlenart marked this pull request as ready for review November 9, 2025 17:49
@lukaszlenart lukaszlenart added this to the 3.5.0 milestone Nov 9, 2025
lukaszlenart pushed a commit that referenced this pull request Nov 11, 2025
…3-4-x)

Port the fix from PR #486 to resolve issue #103 where OGNL parser
fails to parse class references containing reserved keywords in
package names (e.g., @jp.or.example.Utils@method()).

Changes:
- Modified ognl.jj grammar to add classNamePart() production that
  accepts both identifiers and reserved keywords (or, and, not, in, etc.)
- Updated instanceof and className() productions to use classNamePart()
- Added PackageKeywordTest.java with comprehensive test coverage

This allows package names commonly used in Japanese domains (.jp.or.)
and other scenarios where reserved keywords appear in package names.

Fixes #103
lukaszlenart pushed a commit that referenced this pull request Nov 11, 2025
…3-4-x)

Port the fix from PR #486 to resolve issue #103 where OGNL parser
fails to parse class references containing reserved keywords in
package names (e.g., @jp.or.example.Utils@method()).

Changes:
- Modified ognl.jj grammar to add classNamePart() production that
  accepts both identifiers and reserved keywords (or, and, not, in, etc.)
- Updated instanceof and className() productions to use classNamePart()
- Added PackageKeywordTest.java with comprehensive test coverage

This allows package names commonly used in Japanese domains (.jp.or.)
and other scenarios where reserved keywords appear in package names.

Fixes #103
lukaszlenart added a commit that referenced this pull request Nov 29, 2025
…3-4-x) (#491)

Port the fix from PR #486 to resolve issue #103 where OGNL parser
fails to parse class references containing reserved keywords in
package names (e.g., @jp.or.example.Utils@method()).

Changes:
- Modified ognl.jj grammar to add classNamePart() production that
  accepts both identifiers and reserved keywords (or, and, not, in, etc.)
- Updated instanceof and className() productions to use classNamePart()
- Added PackageKeywordTest.java with comprehensive test coverage

This allows package names commonly used in Japanese domains (.jp.or.)
and other scenarios where reserved keywords appear in package names.

Fixes #103

Co-authored-by: Claude <[email protected]>
@lukaszlenart lukaszlenart merged commit 706a549 into main Nov 29, 2025
5 checks passed
@lukaszlenart lukaszlenart deleted the claude/analyze-issue-proposal-011CUu8SKqVevG29u3vRC1DV branch November 29, 2025 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class reference is failed when include 'or' at a package name

2 participants