1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 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.
@@ -1953,7 +1953,7 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
1953
1953
this .aliasedAttributeName = getAliasedAttributeName (aliasFor , sourceAttribute );
1954
1954
if (this .aliasedAnnotationType == this .sourceAnnotationType &&
1955
1955
this .aliasedAttributeName .equals (this .sourceAttributeName )) {
1956
- String msg = String .format ("@AliasFor declaration on attribute [%s] in annotation [%s] points to " +
1956
+ String msg = String .format ("@AliasFor declaration on attribute '%s' in annotation [%s] points to " +
1957
1957
"itself. Specify 'annotation' to point to a same-named attribute on a meta-annotation." ,
1958
1958
sourceAttribute .getName (), declaringClass .getName ());
1959
1959
throw new AnnotationConfigurationException (msg );
@@ -1963,7 +1963,7 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
1963
1963
}
1964
1964
catch (NoSuchMethodException ex ) {
1965
1965
String msg = String .format (
1966
- "Attribute [%s] in annotation [%s] is declared as an @AliasFor nonexistent attribute [%s] in annotation [%s]." ,
1966
+ "Attribute '%s' in annotation [%s] is declared as an @AliasFor nonexistent attribute '%s' in annotation [%s]." ,
1967
1967
this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1968
1968
this .aliasedAnnotationType .getName ());
1969
1969
throw new AnnotationConfigurationException (msg , ex );
@@ -1975,8 +1975,8 @@ private AliasDescriptor(Method sourceAttribute, AliasFor aliasFor) {
1975
1975
private void validate () {
1976
1976
// Target annotation is not meta-present?
1977
1977
if (!this .isAliasPair && !isAnnotationMetaPresent (this .sourceAnnotationType , this .aliasedAnnotationType )) {
1978
- String msg = String .format ("@AliasFor declaration on attribute [%s] in annotation [%s] declares " +
1979
- "an alias for attribute [%s] in meta-annotation [%s] which is not meta-present." ,
1978
+ String msg = String .format ("@AliasFor declaration on attribute '%s' in annotation [%s] declares " +
1979
+ "an alias for attribute '%s' in meta-annotation [%s] which is not meta-present." ,
1980
1980
this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
1981
1981
this .aliasedAnnotationType .getName ());
1982
1982
throw new AnnotationConfigurationException (msg );
@@ -1985,14 +1985,14 @@ private void validate() {
1985
1985
if (this .isAliasPair ) {
1986
1986
AliasFor mirrorAliasFor = this .aliasedAttribute .getAnnotation (AliasFor .class );
1987
1987
if (mirrorAliasFor == null ) {
1988
- String msg = String .format ("Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s]." ,
1988
+ String msg = String .format ("Attribute '%s' in annotation [%s] must be declared as an @AliasFor [%s]." ,
1989
1989
this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName );
1990
1990
throw new AnnotationConfigurationException (msg );
1991
1991
}
1992
1992
1993
1993
String mirrorAliasedAttributeName = getAliasedAttributeName (mirrorAliasFor , this .aliasedAttribute );
1994
1994
if (!this .sourceAttributeName .equals (mirrorAliasedAttributeName )) {
1995
- String msg = String .format ("Attribute [%s] in annotation [%s] must be declared as an @AliasFor [%s], not [%s]." ,
1995
+ String msg = String .format ("Attribute '%s' in annotation [%s] must be declared as an @AliasFor [%s], not [%s]." ,
1996
1996
this .aliasedAttributeName , this .sourceAnnotationType .getName (), this .sourceAttributeName ,
1997
1997
mirrorAliasedAttributeName );
1998
1998
throw new AnnotationConfigurationException (msg );
@@ -2001,9 +2001,10 @@ private void validate() {
2001
2001
2002
2002
Class <?> returnType = this .sourceAttribute .getReturnType ();
2003
2003
Class <?> aliasedReturnType = this .aliasedAttribute .getReturnType ();
2004
- if (returnType != aliasedReturnType ) {
2005
- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
2006
- "and attribute [%s] in annotation [%s] must declare the same return type." ,
2004
+ if (returnType != aliasedReturnType &&
2005
+ (!aliasedReturnType .isArray () || returnType != aliasedReturnType .getComponentType ())) {
2006
+ String msg = String .format ("Misconfigured aliases: attribute '%s' in annotation [%s] " +
2007
+ "and attribute '%s' in annotation [%s] must declare the same return type." ,
2007
2008
this .sourceAttributeName , this .sourceAnnotationType .getName (), this .aliasedAttributeName ,
2008
2009
this .aliasedAnnotationType .getName ());
2009
2010
throw new AnnotationConfigurationException (msg );
@@ -2020,16 +2021,16 @@ private void validateDefaultValueConfiguration(Method aliasedAttribute) {
2020
2021
Object aliasedDefaultValue = aliasedAttribute .getDefaultValue ();
2021
2022
2022
2023
if (defaultValue == null || aliasedDefaultValue == null ) {
2023
- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
2024
- "and attribute [%s] in annotation [%s] must declare default values." ,
2024
+ String msg = String .format ("Misconfigured aliases: attribute '%s' in annotation [%s] " +
2025
+ "and attribute '%s' in annotation [%s] must declare default values." ,
2025
2026
this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2026
2027
aliasedAttribute .getDeclaringClass ().getName ());
2027
2028
throw new AnnotationConfigurationException (msg );
2028
2029
}
2029
2030
2030
2031
if (!ObjectUtils .nullSafeEquals (defaultValue , aliasedDefaultValue )) {
2031
- String msg = String .format ("Misconfigured aliases: attribute [%s] in annotation [%s] " +
2032
- "and attribute [%s] in annotation [%s] must declare the same default value." ,
2032
+ String msg = String .format ("Misconfigured aliases: attribute '%s' in annotation [%s] " +
2033
+ "and attribute '%s' in annotation [%s] must declare the same default value." ,
2033
2034
this .sourceAttributeName , this .sourceAnnotationType .getName (), aliasedAttribute .getName (),
2034
2035
aliasedAttribute .getDeclaringClass ().getName ());
2035
2036
throw new AnnotationConfigurationException (msg );
@@ -2154,7 +2155,7 @@ private String getAliasedAttributeName(AliasFor aliasFor, Method attribute) {
2154
2155
2155
2156
// Ensure user did not declare both 'value' and 'attribute' in @AliasFor
2156
2157
if (attributeDeclared && valueDeclared ) {
2157
- String msg = String .format ("In @AliasFor declared on attribute [%s] in annotation [%s], attribute 'attribute' " +
2158
+ String msg = String .format ("In @AliasFor declared on attribute '%s' in annotation [%s], attribute 'attribute' " +
2158
2159
"and its alias 'value' are present with values of [%s] and [%s], but only one is permitted." ,
2159
2160
attribute .getName (), attribute .getDeclaringClass ().getName (), attributeName , value );
2160
2161
throw new AnnotationConfigurationException (msg );
0 commit comments