JDK-8177316 : Compiler generates wrong code if Annotation TYPE_USE on anonymous class
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u121
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2017-03-17
  • Updated: 2017-03-21
  • Resolved: 2017-03-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If I use an Annotation with ElementType.TYPE_USE on an anonymous class,
this class becomes unusable.
For example, initialization of fields results in a NoSuchFieldError at runtime.

Basically, this bug is described in an OpenJDK-bug:
https://bugs.openjdk.java.net/browse/JDK-8059531



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Declare an Annotation type "A" with ElementType.TYPE_USE
2. Write an expression that instantiates an anonymous class with at least one field, and annotates it with "A"
3. Run the program

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The anonymous class is instantiated and is fully usable.
ACTUAL -
The initializer of the class fails with a NoSuchFieldError

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.neppert;

import org.junit.Test;

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

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface Alias {
	String value();
}

public class TestAnnotationTypeUse {

	
	public static void main(String[] argc) {
		Object annotatedObject = new @Alias("Test") Object() {
			public final Object member = "Hello"; 
		};
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workaround possible


Comments
Closing as duplicate.
21-03-2017

This issue is duplicate of JDK-8059531 which is still in Open state. Moving to core-libs
20-03-2017