|
25 | 25 | import java.io.ObjectOutputStream;
|
26 | 26 | import java.io.ObjectStreamClass;
|
27 | 27 | import java.io.Serializable;
|
| 28 | +import java.lang.reflect.Field; |
28 | 29 | import java.lang.reflect.Modifier;
|
29 | 30 | import java.nio.file.Files;
|
30 | 31 | import java.nio.file.Path;
|
|
36 | 37 | import java.util.List;
|
37 | 38 | import java.util.Map;
|
38 | 39 | import java.util.Set;
|
| 40 | +import java.util.stream.Collectors; |
39 | 41 | import java.util.stream.Stream;
|
40 | 42 |
|
41 | 43 | import org.apereo.cas.client.validation.AssertionImpl;
|
|
44 | 46 | import org.instancio.Select;
|
45 | 47 | import org.instancio.generator.Generator;
|
46 | 48 | import org.junit.jupiter.api.Disabled;
|
| 49 | +import org.junit.jupiter.api.Test; |
47 | 50 | import org.junit.jupiter.params.ParameterizedTest;
|
48 | 51 | import org.junit.jupiter.params.provider.MethodSource;
|
49 | 52 |
|
@@ -289,6 +292,39 @@ static Stream<Path> getFilesToDeserialize() throws IOException {
|
289 | 292 | return Files.list(previousVersionFolder);
|
290 | 293 | }
|
291 | 294 |
|
| 295 | + @Test |
| 296 | + void listClassesMissingSerialVersion() throws Exception { |
| 297 | + ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); |
| 298 | + provider.addIncludeFilter(new AssignableTypeFilter(Serializable.class)); |
| 299 | + List<Class<?>> classes = new ArrayList<>(); |
| 300 | + |
| 301 | + Set<BeanDefinition> components = provider.findCandidateComponents("org/springframework/security"); |
| 302 | + for (BeanDefinition component : components) { |
| 303 | + Class<?> clazz = Class.forName(component.getBeanClassName()); |
| 304 | + boolean isAbstract = Modifier.isAbstract(clazz.getModifiers()); |
| 305 | + if (isAbstract) { |
| 306 | + continue; |
| 307 | + } |
| 308 | + if (clazz.isEnum()) { |
| 309 | + continue; |
| 310 | + } |
| 311 | + if (clazz.getName().contains("Tests")) { |
| 312 | + continue; |
| 313 | + } |
| 314 | + boolean hasSerialVersion = Stream.of(clazz.getDeclaredFields()) |
| 315 | + .map(Field::getName) |
| 316 | + .anyMatch((n) -> n.equals("serialVersionUID")); |
| 317 | + if (!hasSerialVersion) { |
| 318 | + classes.add(clazz); |
| 319 | + } |
| 320 | + } |
| 321 | + if (!classes.isEmpty()) { |
| 322 | + System.out |
| 323 | + .println("Found " + classes.size() + " Serializable classes that don't declare a seriallVersionUID"); |
| 324 | + System.out.println(classes.stream().map(Class::getName).collect(Collectors.joining("\r\n"))); |
| 325 | + } |
| 326 | + } |
| 327 | + |
292 | 328 | static Stream<Class<?>> getClassesToSerialize() throws Exception {
|
293 | 329 | ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
294 | 330 | provider.addIncludeFilter(new AssignableTypeFilter(Serializable.class));
|
|
0 commit comments