Torture.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /** Ctor javadoc. */
  24. public TortureService(List<String> names) {
  25. this.names = requireNonNull(names);
  26. register(this::onEvent);
  27. queue(TortureService::compute);
  28. queue(OtherClass::handle);
  29. Runnable r = () -> helper(RETRY_LIMITS);
  30. executor.submit(new Runnable() {
  31. @Override
  32. public void run() {
  33. helper(RETRY_LIMITS);
  34. }
  35. });
  36. }
  37. @Override
  38. @Deprecated
  39. public void run() {
  40. Config cfg = ConfigLoader.getInstance().load();
  41. this.registry.lookup("x");
  42. helper(Direction.UP);
  43. String base = API_BASE;
  44. int max = Limits.MAX_VALUE;
  45. new StringBuilder(16).append(base);
  46. }
  47. private static Config helper(Object arg) {
  48. return new Config();
  49. }
  50. private void onEvent() {}
  51. private static void compute() {}
  52. public void shadowed() {
  53. String API_BASE = "local"; // shadows the class constant
  54. log(API_BASE);
  55. }
  56. enum Direction {
  57. UP,
  58. DOWN;
  59. Direction opposite() {
  60. return this == UP ? DOWN : UP;
  61. }
  62. }
  63. interface Listener {
  64. void onChange(TortureService svc);
  65. }
  66. }
  67. @Data
  68. class LombokBean {
  69. private String name;
  70. private boolean isActive;
  71. private final int id;
  72. private static int counter;
  73. private String toString; // taken: no synthetic toString field collision
  74. public String getName() { return name; } // explicit getter — never overridden
  75. }
  76. @lombok.Getter
  77. @lombok.extern.slf4j.Slf4j
  78. @Builder
  79. class LombokBuilderBean {
  80. private List<String> items;
  81. }
  82. interface Shape extends Comparable<Shape>, Cloneable {
  83. double area();
  84. }
  85. @interface Marker {
  86. String value() default "";
  87. }