Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8346751

Internal java compiler error with type annotations in constants expression in constant fields

XMLWordPrintable

    • b01
    • 11
    • b08
    • generic
    • generic

        A DESCRIPTION OF THE PROBLEM :
        javac throws an internal java compiler error when compiling code with annotations on constants in @interface

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Create a Java class containing an annotation (@interface) with a constant field that applies an annotation to the constant.
        Define a @Target(ElementType.TYPE_USE) annotation in the @interface.
        Attempt to compile the following code:


        package com.my.company;

        import java.lang.annotation.ElementType;
        import java.lang.annotation.Target;

        public class Client {
            public void packs3_new() {
                // Attempt to use the constant in the code
                float y = Client.ThreeFieldPack.EMPTY_PACK;
            }

            @Target(ElementType.TYPE_USE)
            public @interface ThreeFieldPack {
                // Invalid annotation usage on a constant field
                @Client.ThreeFieldPack float EMPTY_PACK = (@Client.ThreeFieldPack float) 0;
            }
        }

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The code should compile successfully, and the annotation @Client.ThreeFieldPack should be applied correctly in places where type annotations are supported, such as variable declarations or method parameters. Specifically:

        The annotation should not be applied to constants within the annotation itself.
        ACTUAL -
        When attempting to compile the code with javac, the following error is encountered:

        java: Compilation failed: internal java compiler error

        The error message does not provide specific details or a helpful stack trace to diagnose the cause of the failure.

              jlahoda Jan Lahoda
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: