Polishing contribution · spring-projects/spring-framework@5f22648 (original) (raw)
File tree
- main/java/org/springframework
- test/java/org/springframework/http
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -38,11 +38,11 @@ | ||
| 38 | 38 | * additional properties. Subclasses can use the protected copy constructor to |
| 39 | 39 | * re-create an existing {@code ProblemDetail} instance as the subclass, e.g. |
| 40 | 40 | * from an {@code @ControllerAdvice} such as |
| 41 | - * {@link org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler}. | |
| 41 | + * {@link org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler} or | |
| 42 | + * {@link org.springframework.web.reactive.result.method.annotation.ResponseEntityExceptionHandler}. | |
| 42 | 43 | * |
| 43 | 44 | * @author Rossen Stoyanchev |
| 44 | 45 | * @author Juergen Hoeller |
| 45 | - * @author Yanming Zhou | |
| 46 | 46 | * @since 6.0 |
| 47 | 47 | * @see RFC 7807 |
| 48 | 48 | * @see org.springframework.web.ErrorResponse |
| @@ -239,8 +239,8 @@ public boolean equals(@Nullable Object other) { | ||
| 239 | 239 | if (!(other instanceof ProblemDetail otherDetail)) { |
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | -return (this.type.equals(otherDetail.type) && | |
| 243 | -ObjectUtils.nullSafeEquals(this.getTitle(), otherDetail.getTitle()) && | |
| 242 | +return (getType().equals(otherDetail.getType()) && | |
| 243 | +ObjectUtils.nullSafeEquals(getTitle(), otherDetail.getTitle()) && | |
| 244 | 244 | this.status == otherDetail.status && |
| 245 | 245 | ObjectUtils.nullSafeEquals(this.detail, otherDetail.detail) && |
| 246 | 246 | ObjectUtils.nullSafeEquals(this.instance, otherDetail.instance) && |
| @@ -250,7 +250,7 @@ public boolean equals(@Nullable Object other) { | ||
| 250 | 250 | @Override |
| 251 | 251 | public int hashCode() { |
| 252 | 252 | int result = this.type.hashCode(); |
| 253 | -result = 31 * result + ObjectUtils.nullSafeHashCode(this.getTitle()); | |
| 253 | +result = 31 * result + ObjectUtils.nullSafeHashCode(getTitle()); | |
| 254 | 254 | result = 31 * result + this.status; |
| 255 | 255 | result = 31 * result + ObjectUtils.nullSafeHashCode(this.detail); |
| 256 | 256 | result = 31 * result + ObjectUtils.nullSafeHashCode(this.instance); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -102,8 +102,7 @@ default Object[] getDetailMessageArguments(MessageSource messageSource, Locale l | ||
| 102 | 102 | /** |
| 103 | 103 | * Return a code to use to resolve the problem "title" for this exception |
| 104 | 104 | * through a {@link MessageSource}. |
| 105 | - * By default this is initialized via |
|
| 106 | - * {@link #getDefaultTitleMessageCode(Class, String)}. | |
| 105 | + * By default this is initialized via {@link #getDefaultTitleMessageCode(Class)}. |
|
| 107 | 106 | */ |
| 108 | 107 | default String getTitleMessageCode() { |
| 109 | 108 | return getDefaultTitleMessageCode(getClass()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | - * Copyright 2002-2022 the original author or authors. | |
| 2 | + * Copyright 2002-2023 the original author or authors. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | 5 | * you may not use this file except in compliance with the License. |
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | class ProblemDetailTests { |
| 31 | 31 | |
| 32 | 32 | @Test |
| 33 | -void equalsAndHashCode() throws Exception { | |
| 33 | +void equalsAndHashCode() { | |
| 34 | 34 | ProblemDetail pd1 = ProblemDetail.forStatus(500); |
| 35 | 35 | ProblemDetail pd2 = ProblemDetail.forStatus(HttpStatus.INTERNAL_SERVER_ERROR); |
| 36 | 36 | ProblemDetail pd3 = ProblemDetail.forStatus(HttpStatus.NOT_FOUND); |
| @@ -50,12 +50,19 @@ void equalsAndHashCode() throws Exception { | ||
| 50 | 50 | assertThat(pd2).isNotEqualTo(pd4); |
| 51 | 51 | assertThat(pd1.hashCode()).isNotEqualTo(pd3.hashCode()); |
| 52 | 52 | assertThat(pd1.hashCode()).isNotEqualTo(pd4.hashCode()); |
| 53 | + } | |
| 54 | + | |
| 55 | +@Test // gh-30294 | |
| 56 | +void equalsAndHashCodeWithDeserialization() throws Exception { | |
| 57 | +ProblemDetail originalDetail = ProblemDetail.forStatus(500); | |
| 58 | + | |
| 59 | +ObjectMapper mapper = new ObjectMapper(); | |
| 60 | +byte[] bytes = mapper.writeValueAsBytes(originalDetail); | |
| 61 | +ProblemDetail deserializedDetail = mapper.readValue(bytes, ProblemDetail.class); | |
| 53 | 62 | |
| 54 | -ObjectMapper om = new ObjectMapper(); | |
| 55 | -ProblemDetail pd5 = om.readValue(om.writeValueAsBytes(pd1), ProblemDetail.class); | |
| 56 | -assertThat(pd1).isEqualTo(pd5); | |
| 57 | -assertThat(pd5).isEqualTo(pd1); | |
| 58 | -assertThat(pd1.hashCode()).isEqualTo(pd5.hashCode()); | |
| 63 | +assertThat(originalDetail).isEqualTo(deserializedDetail); | |
| 64 | +assertThat(deserializedDetail).isEqualTo(originalDetail); | |
| 65 | +assertThat(originalDetail.hashCode()).isEqualTo(deserializedDetail.hashCode()); | |
| 59 | 66 | } |
| 60 | 67 | |
| 61 | 68 | } |