@Test @SuppressWarnings({ "unused", "resource" }) public void testDebugContextDisabled() { final CloseTrackedRegistry<SomethingClosable> debugContextDisabledRegistry = new CloseTrackedRegistry<>(this, "testDebugContextDisabled", false); SomethingClosable forgotToCloseOnce = new SomethingClosable(debugContextDisabledRegistry); Set<CloseTrackedRegistryReportEntry<SomethingClosable>> closeRegistryReport = debugContextDisabledRegistry.getAllUnique(); assertThat(closeRegistryReport).hasSize(1); CloseTrackedRegistryReportEntry<SomethingClosable> closeRegistryReportEntry1 = closeRegistryReport.iterator().next(); assertThat(closeRegistryReportEntry1.getNumberAddedNotRemoved()).isEqualTo(1); assertThat(closeRegistryReportEntry1.getStackTraceElements()).isEmpty(); }
@SuppressFBWarnings("UC_USELESS_OBJECT") public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() { Map<List<StackTraceElement>, Long> map = new HashMap<>(); Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked); for (CloseTracked<T> closeTracked : copyOfTracked) { final StackTraceElement[] stackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> stackTraceElements = stackTraceArray != null ? Arrays.asList(stackTraceArray) : Collections.emptyList(); map.merge(stackTraceElements, 1L, (oldValue, value) -> oldValue + 1); } Set<CloseTrackedRegistryReportEntry<T>> report = new HashSet<>(); map.forEach((stackTraceElements, number) -> copyOfTracked.stream().filter(closeTracked -> { StackTraceElement[] closeTrackedStackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> closeTrackedStackTraceElements = closeTrackedStackTraceArray != null ? asList(closeTrackedStackTraceArray) : emptyList(); return closeTrackedStackTraceElements.equals(stackTraceElements); }).findAny().ifPresent(exampleCloseTracked -> report.add( new CloseTrackedRegistryReportEntry<>(exampleCloseTracked, number, stackTraceElements)))); return report; }
CloseTrackedRegistry { @SuppressFBWarnings("UC_USELESS_OBJECT") public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() { Map<List<StackTraceElement>, Long> map = new HashMap<>(); Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked); for (CloseTracked<T> closeTracked : copyOfTracked) { final StackTraceElement[] stackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> stackTraceElements = stackTraceArray != null ? Arrays.asList(stackTraceArray) : Collections.emptyList(); map.merge(stackTraceElements, 1L, (oldValue, value) -> oldValue + 1); } Set<CloseTrackedRegistryReportEntry<T>> report = new HashSet<>(); map.forEach((stackTraceElements, number) -> copyOfTracked.stream().filter(closeTracked -> { StackTraceElement[] closeTrackedStackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> closeTrackedStackTraceElements = closeTrackedStackTraceArray != null ? asList(closeTrackedStackTraceArray) : emptyList(); return closeTrackedStackTraceElements.equals(stackTraceElements); }).findAny().ifPresent(exampleCloseTracked -> report.add( new CloseTrackedRegistryReportEntry<>(exampleCloseTracked, number, stackTraceElements)))); return report; } }
CloseTrackedRegistry { @SuppressFBWarnings("UC_USELESS_OBJECT") public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() { Map<List<StackTraceElement>, Long> map = new HashMap<>(); Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked); for (CloseTracked<T> closeTracked : copyOfTracked) { final StackTraceElement[] stackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> stackTraceElements = stackTraceArray != null ? Arrays.asList(stackTraceArray) : Collections.emptyList(); map.merge(stackTraceElements, 1L, (oldValue, value) -> oldValue + 1); } Set<CloseTrackedRegistryReportEntry<T>> report = new HashSet<>(); map.forEach((stackTraceElements, number) -> copyOfTracked.stream().filter(closeTracked -> { StackTraceElement[] closeTrackedStackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> closeTrackedStackTraceElements = closeTrackedStackTraceArray != null ? asList(closeTrackedStackTraceArray) : emptyList(); return closeTrackedStackTraceElements.equals(stackTraceElements); }).findAny().ifPresent(exampleCloseTracked -> report.add( new CloseTrackedRegistryReportEntry<>(exampleCloseTracked, number, stackTraceElements)))); return report; } CloseTrackedRegistry(final Object anchor, final String createDescription, final boolean isDebugContextEnabled); }
CloseTrackedRegistry { @SuppressFBWarnings("UC_USELESS_OBJECT") public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() { Map<List<StackTraceElement>, Long> map = new HashMap<>(); Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked); for (CloseTracked<T> closeTracked : copyOfTracked) { final StackTraceElement[] stackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> stackTraceElements = stackTraceArray != null ? Arrays.asList(stackTraceArray) : Collections.emptyList(); map.merge(stackTraceElements, 1L, (oldValue, value) -> oldValue + 1); } Set<CloseTrackedRegistryReportEntry<T>> report = new HashSet<>(); map.forEach((stackTraceElements, number) -> copyOfTracked.stream().filter(closeTracked -> { StackTraceElement[] closeTrackedStackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> closeTrackedStackTraceElements = closeTrackedStackTraceArray != null ? asList(closeTrackedStackTraceArray) : emptyList(); return closeTrackedStackTraceElements.equals(stackTraceElements); }).findAny().ifPresent(exampleCloseTracked -> report.add( new CloseTrackedRegistryReportEntry<>(exampleCloseTracked, number, stackTraceElements)))); return report; } CloseTrackedRegistry(final Object anchor, final String createDescription, final boolean isDebugContextEnabled); boolean isDebugContextEnabled(); Object getAnchor(); String getCreateDescription(); @SuppressFBWarnings("UC_USELESS_OBJECT") Set<CloseTrackedRegistryReportEntry<T>> getAllUnique(); }
CloseTrackedRegistry { @SuppressFBWarnings("UC_USELESS_OBJECT") public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() { Map<List<StackTraceElement>, Long> map = new HashMap<>(); Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked); for (CloseTracked<T> closeTracked : copyOfTracked) { final StackTraceElement[] stackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> stackTraceElements = stackTraceArray != null ? Arrays.asList(stackTraceArray) : Collections.emptyList(); map.merge(stackTraceElements, 1L, (oldValue, value) -> oldValue + 1); } Set<CloseTrackedRegistryReportEntry<T>> report = new HashSet<>(); map.forEach((stackTraceElements, number) -> copyOfTracked.stream().filter(closeTracked -> { StackTraceElement[] closeTrackedStackTraceArray = closeTracked.getAllocationContextStackTrace(); List<StackTraceElement> closeTrackedStackTraceElements = closeTrackedStackTraceArray != null ? asList(closeTrackedStackTraceArray) : emptyList(); return closeTrackedStackTraceElements.equals(stackTraceElements); }).findAny().ifPresent(exampleCloseTracked -> report.add( new CloseTrackedRegistryReportEntry<>(exampleCloseTracked, number, stackTraceElements)))); return report; } CloseTrackedRegistry(final Object anchor, final String createDescription, final boolean isDebugContextEnabled); boolean isDebugContextEnabled(); Object getAnchor(); String getCreateDescription(); @SuppressFBWarnings("UC_USELESS_OBJECT") Set<CloseTrackedRegistryReportEntry<T>> getAllUnique();  }