Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package visibility does not check inner classes #158

Open
philwebb opened this issue Dec 18, 2019 · 2 comments
Open

Package visibility does not check inner classes #158

philwebb opened this issue Dec 18, 2019 · 2 comments

Comments

@philwebb
Copy link
Contributor

See spring-projects/spring-boot#19395

@dreis2211
Copy link
Contributor

dreis2211 commented Dec 18, 2019

I have a first version for this, but that creates follow-up problems/questions with the method visibility checks.

E.g. take the following:
https://github.com/spring-projects/spring-boot/blob/a66c4d3096877b33119366ea9ea165c892b462c8/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java#L71-L86

	@MinimalWebConfiguration
	@ApplicationPath("/rest")
	@Path("/message")
	public static class Application extends ResourceConfig {

		Application() {
			register(Application.class);
		}

		@GET
		public Message message() {
			return new Message("Jersey", null);
		}

		static void main(String[] args) {
			SpringApplication.run(Application.class, args);
		}

	}

Making Application package private will cause the method visibility checks to kick in on message(). Yet, this method cannot be made package private as it is required to be public.

A similar issue appears in https://github.com/spring-projects/spring-boot/blob/a66c4d3096877b33119366ea9ea165c892b462c8/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanWithAopProxyTests.java#L87

	@Service
	public static class DateService {

		@Cacheable(cacheNames = "test")
		public Long getDate(boolean arg) {
			return System.nanoTime();
		}

	}

@Cacheable only works on public methods, so we can't change this here either.

I wonder if we should extend the MethodVisibilityChecks to check for some more annotations, but that might be cumbersome.

I've only checked a couple of modules so far, but I suspect more problems with some of the tests that do serialization and make use of inner classes and don't have any annotation, so the only option there would be to suppress the checks.

What do you think?

Cheers,
Christoph

@philwebb
Copy link
Contributor Author

philwebb commented Dec 4, 2020

I seem to remember we had a few of those in the past and the only option was to exclude them from checkstyle. Perhaps it's best if we leave things alone for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants