javac produces a compile error for valid java 7 codes: Cast vs Boolean Expression

Vicente-Arturo Romero-Zaldivar vicente.romero at oracle.com
Tue Nov 26 06:48:18 PST 2013


Hi bitter_fox,

Thanks for your bug report, I have filed bug entry [1] to track it,

Vicente

[1] https://bugs.openjdk.java.net/browse/JDK-8029179

On 26/11/13 05:32, bitter_fox wrote:
> Hi,
> I found a javac bug.
>
> Javac reject valid java 7 codes:
>
> public class Test
> {
>      static int a, b, c, d;
>
>      public static void main(String[] args)
>      {
>          boolean cond = (a < b & c > d);
>
>          /*
>        JavacParser#analyzeParens
>            LPAREN
>            IDENT(a) : skip
>            LT : depth = 1
>            IDENT(b) : skip
>            AMP : skip
>            IDENT(c) : skip
>            GT : depth = 0 -> type = true
>            IDENT(d) : skip
>            RPAREN : type == true -> return ParensResult.CAST
>          */
>      }
> }
>
> This is a simple parened boolean expression.
> But javac(JavacParser#analyzeParens) analyzes it into CAST expression from
> above.
>
> Today's JavacParser#analyzeParens take no thought that intersection type
> for type parameter isn't accepted.
>
> You should change JavacParser#analyzeParens like following.
>
> --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java     Mon
> Nov 11 23:16:35 2013 -0800
> +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java     Tue
> Nov 26 14:27:43 2013 +0900
> @@ -1536,7 +1536,14 @@
>               switch (tk) {
>                   case COMMA:
>                       type = true;
> -                case EXTENDS: case SUPER: case DOT: case AMP:
> +                    break;
> +                case AMP:
> +                    if (depth > 0) {
> +                        // < ... & -> parens
> +                        // (for type parameter, intersection type isn't
> accepted)
> +                        return ParensResult.PARENS;
> +                    }
> +                case EXTENDS: case SUPER: case DOT:
>                       //skip
>                       break;
>                   case QUES:
>
> Regards,
> bitter_fox
>



More information about the lambda-dev mailing list