Skip to content

Commit 451e80f

Browse files
AXIS2-6095 Fix IDL parser fault on comments ending with **/
The ML_COMMENT lexer rule failed on Javadoc-style comments ending with **/ (double asterisk before slash). The original rule's ('*')+ alternative consumed both asterisks, then the next char '/' didn't match any inner alternative (which excluded both '*' and '/'), causing a NoViableAltForCharException. Fix: use a semantic predicate — consume '*' only when the next character is not '/'. This ensures '*/' always terminates the comment, regardless of how many asterisks precede it. Both the ANTLR grammar (idl.g) and the generated lexer (IDLLexer.java) are updated. The generated code is hand-edited to match since the project uses ANTLR 2.7.6 which is no longer actively maintained. Reported by Brănaci Șerban-Mihai.
1 parent c833164 commit 451e80f

2 files changed

Lines changed: 12 additions & 41 deletions

File tree

modules/corba/src/org/apache/axis2/corba/idl/parser/IDLLexer.java

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -829,61 +829,35 @@ public final void mSL_COMMENT(boolean _createToken) throws RecognitionException,
829829
_returnToken = _token;
830830
}
831831

832+
// AXIS2-6095: Fixed to handle comments ending with **/ (double asterisk).
833+
// The original grammar's ('*')+ alternative failed on **/ because after
834+
// consuming both asterisks, the next char '/' didn't match any inner
835+
// alternative. The fix uses a semantic predicate: consume '*' only when
836+
// the next char is not '/', so '*/' always terminates the comment.
832837
public final void mML_COMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
833838
int _ttype; Token _token=null; int _begin=text.length();
834839
_ttype = ML_COMMENT;
835840
int _saveIndex;
836-
841+
837842
_saveIndex=text.length();
838843
match("/*");
839844
text.setLength(_saveIndex);
840845
{
841846
_loop333:
842847
do {
843-
if ((LA(1)=='*') && (_tokenSet_2.member(LA(2)))) {
844-
{
845-
int _cnt329=0;
846-
_loop329:
847-
do {
848-
if ((LA(1)=='*')) {
849-
match('*');
850-
}
851-
else {
852-
if ( _cnt329>=1 ) { break _loop329; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
853-
}
854-
855-
_cnt329++;
856-
} while (true);
857-
}
858-
{
859-
if ((LA(1)=='\n')) {
860-
match('\n');
861-
newline();
862-
}
863-
else if ((_tokenSet_3.member(LA(1)))) {
864-
{
865-
match(_tokenSet_3);
866-
}
867-
}
868-
else {
869-
throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
870-
}
871-
872-
}
848+
if ((LA(1)=='*') && (LA(2) != '/')) {
849+
match('*');
873850
}
874851
else if ((LA(1)=='\n')) {
875852
match('\n');
876853
newline();
877854
}
878-
else if ((_tokenSet_4.member(LA(1)))) {
879-
{
880-
match(_tokenSet_4);
881-
}
855+
else if (LA(1) != '*' && LA(1) != '\n' && LA(1) != EOF_CHAR) {
856+
matchNot(EOF_CHAR);
882857
}
883858
else {
884859
break _loop333;
885860
}
886-
887861
} while (true);
888862
}
889863
_saveIndex=text.length();

modules/corba/src/org/apache/axis2/corba/idl/parser/idl.g

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,11 +1225,8 @@ options {
12251225
:
12261226
"/*"!
12271227
(
1228-
'\n' { newline(); }
1229-
| ('*')+
1230-
( '\n' { newline(); }
1231-
| ~('*' | '/' | '\n')
1232-
)
1228+
{ LA(2) != '/' }? '*'
1229+
| '\n' { newline(); }
12331230
| ~('*' | '\n')
12341231
)*
12351232
"*/"!

0 commit comments

Comments
 (0)