Skip to content

Commit

Permalink
Merge branch '6.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jzheaux committed Feb 18, 2025
2 parents b6c0bde + cc2cfc6 commit 51ce91f
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.nio.file.Paths;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -42,7 +43,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.servlet.http.Cookie;
Expand Down Expand Up @@ -762,18 +762,14 @@ static Stream<Path> getFilesToDeserialize() throws IOException {
}

@Test
void listClassesMissingSerialVersion() throws Exception {
void allSerializableClassesShouldHaveSerialVersionOrSuppressWarnings() throws Exception {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(Serializable.class));
List<Class<?>> classes = new ArrayList<>();

Set<BeanDefinition> components = provider.findCandidateComponents("org/springframework/security");
for (BeanDefinition component : components) {
Class<?> clazz = Class.forName(component.getBeanClassName());
boolean isAbstract = Modifier.isAbstract(clazz.getModifiers());
if (isAbstract) {
continue;
}
if (clazz.isEnum()) {
continue;
}
Expand All @@ -783,15 +779,16 @@ void listClassesMissingSerialVersion() throws Exception {
boolean hasSerialVersion = Stream.of(clazz.getDeclaredFields())
.map(Field::getName)
.anyMatch((n) -> n.equals("serialVersionUID"));
if (!hasSerialVersion) {
SuppressWarnings suppressWarnings = clazz.getAnnotation(SuppressWarnings.class);
boolean hasSerialIgnore = suppressWarnings == null
|| Arrays.asList(suppressWarnings.value()).contains("Serial");
if (!hasSerialVersion && !hasSerialIgnore) {
classes.add(clazz);
}
}
if (!classes.isEmpty()) {
System.out
.println("Found " + classes.size() + " Serializable classes that don't declare a seriallVersionUID");
System.out.println(classes.stream().map(Class::getName).collect(Collectors.joining("\r\n")));
}
assertThat(classes)
.describedAs("Found Serializable classes that are either missing a serialVersionUID or a @SuppressWarnings")
.isEmpty();
}

static Stream<Class<?>> getClassesToSerialize() throws Exception {
Expand Down

0 comments on commit 51ce91f

Please sign in to comment.