Torture.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Java torture fixture — exercises every Java extraction path the kernel
  3. * ports: package namespace, imports, javadoc, annotations, inheritance,
  4. * fields/constants, enums, anonymous classes, method references, static
  5. * member reads, fluent chains, Lombok synthesis, value refs + shadowing.
  6. */
  7. package com.example.torture;
  8. import java.util.List;
  9. import java.util.Map;
  10. import static java.util.Objects.requireNonNull;
  11. import com.example.other.OtherClass;
  12. import lombok.Data;
  13. /** Javadoc for the service. */
  14. @Service
  15. @Component("torture")
  16. public class TortureService extends BaseService implements Runnable, AutoCloseable {
  17. /** A shared constant table (value-ref target). */
  18. public static final Map<String, Integer> RETRY_LIMITS = Map.of("a", 1);
  19. private static final String API_BASE = "https://example.test";
  20. protected int count = 0;
  21. private final List<String> names;
  22. int packagePrivate, secondDeclarator;
  23. /** Field initializers — walked scoped to the field (#693). */
  24. private final Runnable fieldLambda = () -> helper(RETRY_LIMITS);
  25. private final Runnable fieldAnonClass = new Runnable() {
  26. @Override
  27. public void run() {
  28. helper(RETRY_LIMITS);
  29. }
  30. };
  31. private final Runnable fieldMethodRef = TortureService::compute;
  32. /** Ctor javadoc. */
  33. public TortureService(List<String> names) {
  34. this.names = requireNonNull(names);
  35. register(this::onEvent);
  36. queue(TortureService::compute);
  37. queue(OtherClass::handle);
  38. Runnable r = () -> helper(RETRY_LIMITS);
  39. executor.submit(new Runnable() {
  40. @Override
  41. public void run() {
  42. helper(RETRY_LIMITS);
  43. }
  44. });
  45. }
  46. @Override
  47. @Deprecated
  48. public void run() {
  49. Config cfg = ConfigLoader.getInstance().load();
  50. this.registry.lookup("x");
  51. helper(Direction.UP);
  52. String base = API_BASE;
  53. int max = Limits.MAX_VALUE;
  54. new StringBuilder(16).append(base);
  55. }
  56. private static Config helper(Object arg) {
  57. return new Config();
  58. }
  59. private void onEvent() {}
  60. private static void compute() {}
  61. public void shadowed() {
  62. String API_BASE = "local"; // shadows the class constant
  63. log(API_BASE);
  64. }
  65. enum Direction {
  66. UP,
  67. DOWN;
  68. Direction opposite() {
  69. return this == UP ? DOWN : UP;
  70. }
  71. }
  72. interface Listener {
  73. void onChange(TortureService svc);
  74. }
  75. }
  76. @Data
  77. class LombokBean {
  78. private String name;
  79. private boolean isActive;
  80. private final int id;
  81. private static int counter;
  82. private String toString; // taken: no synthetic toString field collision
  83. public String getName() { return name; } // explicit getter — never overridden
  84. }
  85. @lombok.Getter
  86. @lombok.extern.slf4j.Slf4j
  87. @Builder
  88. class LombokBuilderBean {
  89. private List<String> items;
  90. }
  91. interface Shape extends Comparable<Shape>, Cloneable {
  92. double area();
  93. }
  94. @interface Marker {
  95. String value() default "";
  96. }