spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Add @NotNull to BeforeRoutePredicateFactory.Config. datetime

Open apollyon4 opened this issue 1 year ago • 4 comments

Question & Enhancement

  1. I compared AfterRoutePredicateFactory and BeforeRoutePredicateFactory are quite similar but is diffrent about @NotNull. If there no reason I think should add @NotNull to BeforeRoutePredicateFactory.Config.datetime

  2. I don't realy know about @Validated anotation works in predicates. I try few test with or without @Validated but it have no given. Could you remove @Validated in every predicates If there are no reason to apply @Validated? Because it require me to understanding @Validated when I make custom predicate.

apollyon4 avatar Jul 29 '24 08:07 apollyon4

It happens when configuration is bound from properties, similar to how it works in spring boot @ConfigurationProperties, it uses the same mechanism, so supporting constraints and @Validated.

spencergibb avatar Sep 27 '24 02:09 spencergibb

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues avatar Oct 04 '24 02:10 spring-cloud-issues

@spencergibb @spencergibb I still don’t fully understand the use of @Validated in PredicateFactory.Config, but I believe it might not be crucial to this issue.

I looked three classes within the PredicateFactory.

public class HeaderRoutePredicateFactory extends AbstractRoutePredicateFactory<HeaderRoutePredicateFactory.Config> {
	@Validated
	public static class Config {
		@NotEmpty
		private String header;
	}

In HeaderRoutePredicateFactory, the header field is validated to ensure it is not empty.

public class AfterRoutePredicateFactory extends AbstractRoutePredicateFactory<AfterRoutePredicateFactory.Config> {
	public static class Config {
		@NotNull
		private ZonedDateTime datetime;
	}
}

Similarly, in AfterRoutePredicateFactory, the datetime field is checked for null values, but @Validated is not used here.

public class BeforeRoutePredicateFactory extends AbstractRoutePredicateFactory<BeforeRoutePredicateFactory.Config> {
	public static class Config {
		private ZonedDateTime datetime;
	}
}

BeforeRoutePredicateFactory is quite similar to AfterRoutePredicateFactory, but it’s missing the @NotNull annotation on the datetime field. It seems necessary to include this validation, as BeforeRoutePredicateFactory doesn’t currently check if the datetime field is null.

apollyon4 avatar Oct 09 '24 04:10 apollyon4

Yup, it's inconsistent. PRs welcome.

spencergibb avatar Oct 14 '24 15:10 spencergibb

Closed via #3583

spencergibb avatar Nov 20 '24 17:11 spencergibb