java-topology/test/langtools/tools/javac/patterns/AnnotationErrors.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

42 lines
1.2 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8300543
* @summary Verify error related to annotations and patterns
* @compile/fail/ref=AnnotationErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW AnnotationErrors.java
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class AnnotationErrors {
private void test(Object o, G<String> g) {
boolean b1 = o instanceof @DA R(var s);
boolean b2 = o instanceof @DTA R(var s);
boolean b3 = o instanceof @TA R(var s);
boolean b5 = g instanceof G<@DTA String>(var s);
boolean b6 = g instanceof G<@TA String>(var s);
switch (o) {
case @DA R(var s) when b1 -> {}
case @DTA R(var s) when b1 -> {}
case @TA R(var s) when b1 -> {}
default -> {}
}
switch (g) {
case G<@DTA String>(var s) when b1 -> {}
case G<@TA String>(var s) when b1 -> {}
default -> {}
}
}
record R(String s) {}
record G<T>(T t) {}
@Target(ElementType.LOCAL_VARIABLE)
@interface DA {}
@Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})
@interface DTA {}
@Target(ElementType.TYPE_USE)
@interface TA {}
}