You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jay Liang (JIRA)" <ji...@apache.org> on 2008/01/24 18:00:37 UTC
[jira] Created: (LANG-403) HashcodeBuilder is broken for
Annotations
HashcodeBuilder is broken for Annotations
-----------------------------------------
Key: LANG-403
URL: https://issues.apache.org/jira/browse/LANG-403
Project: Commons Lang
Issue Type: Bug
Affects Versions: 2.3
Reporter: Jay Liang
HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
@Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
hashCode should be 895255138
The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
===============
public class Simple{
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
private @interface CustomAnnotation{
public String name();
public Class<?> type();
}
private static class CustomAnnotationImpl implements CustomAnnotation{
final String _name;
final Class<?> _type;
public CustomAnnotationImpl(String name, Class<?> type) {
_name = Objects.nonNull(name, "property name should not be null");
_type = Objects.nonNull(type, "property type should not be null");
}
public String name() {
return _name;
}
public Class<?> type() {
return _type;
}
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
* @return good annotation hashCode
*/
public int goodHashCode() {
return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private static class Test{
@CustomAnnotation(name="blah", type=String.class)
String _blah;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public static void main(String[] args) throws Exception{
for(Field f : Test.class.getDeclaredFields()){
for(Annotation a : f.getAnnotations()){
System.out.println(a + " hashCode= " + a.hashCode());
CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
System.out.println(c + " hashCode= " + c.hashCode());
System.out.println("hashCode should be "+ c.goodHashCode());
}
}
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Jay Liang (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jay Liang updated LANG-403:
---------------------------
Description:
HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
@Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
hashCode should be 895255138
The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
===============
public class Simple{
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
private @interface CustomAnnotation{
public String name();
public Class<?> type();
}
private static class CustomAnnotationImpl implements CustomAnnotation{
final String _name;
final Class<?> _type;
public CustomAnnotationImpl(String name, Class<?> type) {
_name = name;
_type = type;
}
public String name() {
return _name;
}
public Class<?> type() {
return _type;
}
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
* @return good annotation hashCode
*/
public int goodHashCode() {
return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private static class Test{
@CustomAnnotation(name="blah", type=String.class)
String _blah;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public static void main(String[] args) throws Exception{
for(Field f : Test.class.getDeclaredFields()){
for(Annotation a : f.getAnnotations()){
System.out.println(a + " hashCode= " + a.hashCode());
CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
System.out.println(c + " hashCode= " + c.hashCode());
System.out.println("hashCode should be "+ c.goodHashCode());
}
}
}
}
was:
HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
@Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
hashCode should be 895255138
The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
===============
public class Simple{
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
private @interface CustomAnnotation{
public String name();
public Class<?> type();
}
private static class CustomAnnotationImpl implements CustomAnnotation{
final String _name;
final Class<?> _type;
public CustomAnnotationImpl(String name, Class<?> type) {
_name = Objects.nonNull(name, "property name should not be null");
_type = Objects.nonNull(type, "property type should not be null");
}
public String name() {
return _name;
}
public Class<?> type() {
return _type;
}
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
* @return good annotation hashCode
*/
public int goodHashCode() {
return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private static class Test{
@CustomAnnotation(name="blah", type=String.class)
String _blah;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public static void main(String[] args) throws Exception{
for(Field f : Test.class.getDeclaredFields()){
for(Annotation a : f.getAnnotations()){
System.out.println(a + " hashCode= " + a.hashCode());
CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
System.out.println(c + " hashCode= " + c.hashCode());
System.out.println("hashCode should be "+ c.goodHashCode());
}
}
}
}
removed google guice codes
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> ===============
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12796555#action_12796555 ]
Henri Yandell commented on LANG-403:
------------------------------------
Looking into this - what I'm not getting here is why you would use HashCodeBuidler to build an annotation's hashcode; or rather, why you would make a class that implements an annotation like this. I'm thinking this is a theoretical issue only.
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.builder.*
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: 3.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated LANG-403:
-------------------------------
Issue Type: Improvement (was: Bug)
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.builder.*
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: 3.1
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12563393#action_12563393 ]
Henri Yandell commented on LANG-403:
------------------------------------
Sounds good. Patches welcome :)
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: LangTwo 1.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12742240#action_12742240 ]
Henri Yandell commented on LANG-403:
------------------------------------
We're 1.5 now, so this can be fixed directly. Patches welcome.
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: 3.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Benedict updated LANG-403:
-------------------------------
Fix Version/s: (was: 3.0)
3.x
Without a patch, moving this to post 3.0 release.
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.builder.*
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: 3.x
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Joerg Schaible updated LANG-403:
--------------------------------
Description:
HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
@Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
hashCode should be 895255138
The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
{code:java}
public class Simple{
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
private @interface CustomAnnotation{
public String name();
public Class<?> type();
}
private static class CustomAnnotationImpl implements CustomAnnotation{
final String _name;
final Class<?> _type;
public CustomAnnotationImpl(String name, Class<?> type) {
_name = name;
_type = type;
}
public String name() {
return _name;
}
public Class<?> type() {
return _type;
}
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
* @return good annotation hashCode
*/
public int goodHashCode() {
return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private static class Test{
@CustomAnnotation(name="blah", type=String.class)
String _blah;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public static void main(String[] args) throws Exception{
for(Field f : Test.class.getDeclaredFields()){
for(Annotation a : f.getAnnotations()){
System.out.println(a + " hashCode= " + a.hashCode());
CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
System.out.println(c + " hashCode= " + c.hashCode());
System.out.println("hashCode should be "+ c.goodHashCode());
}
}
}
}
{code}
was:
HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
@Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
hashCode should be 895255138
The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
===============
public class Simple{
@Retention(RetentionPolicy.RUNTIME)
@Target({FIELD, METHOD, PARAMETER})
private @interface CustomAnnotation{
public String name();
public Class<?> type();
}
private static class CustomAnnotationImpl implements CustomAnnotation{
final String _name;
final Class<?> _type;
public CustomAnnotationImpl(String name, Class<?> type) {
_name = name;
_type = type;
}
public String name() {
return _name;
}
public Class<?> type() {
return _type;
}
public Class<? extends Annotation> annotationType() {
return CustomAnnotation.class;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/**
* This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
* @return good annotation hashCode
*/
public int goodHashCode() {
return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
private static class Test{
@CustomAnnotation(name="blah", type=String.class)
String _blah;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
public static void main(String[] args) throws Exception{
for(Field f : Test.class.getDeclaredFields()){
for(Annotation a : f.getAnnotations()){
System.out.println(a + " hashCode= " + a.hashCode());
CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
System.out.println(c + " hashCode= " + c.hashCode());
System.out.println("hashCode should be "+ c.goodHashCode());
}
}
}
}
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: LangTwo 1.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> {code:java}
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated LANG-403:
-------------------------------
Fix Version/s: LangTwo 1.0
I suspect the answer is that Lang does not support JDK 1.5 features, and we need to save this issue for when such a Lang is worked on (the next one imo).
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: LangTwo 1.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> ===============
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-403) HashcodeBuilder is broken for
Annotations
Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12562380#action_12562380 ]
Joerg Schaible commented on LANG-403:
-------------------------------------
We could try to load Annotation.class dynamically and if it is available, the HashCode algorithm could test if the given instance is assignable and use the calculation required by the JDK docs for Annotations.
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: LangTwo 1.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> ===============
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (LANG-403) HashcodeBuilder is broken
for Annotations
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12562368#action_12562368 ]
bayard edited comment on LANG-403 at 1/24/08 9:37 PM:
-------------------------------------------------------------
I suspect the answer is that Lang does not support JDK 1.5 features, and we need to save this issue for when such a Lang is worked on (the next one after the upcoming 2.4 imo).
was (Author: bayard):
I suspect the answer is that Lang does not support JDK 1.5 features, and we need to save this issue for when such a Lang is worked on (the next one imo).
> HashcodeBuilder is broken for Annotations
> -----------------------------------------
>
> Key: LANG-403
> URL: https://issues.apache.org/jira/browse/LANG-403
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 2.3
> Reporter: Jay Liang
> Fix For: LangTwo 1.0
>
>
> HashCodeBuilder does not produce a correct hashCode that conforms to java language specs. Running the following code snippets, i get
> @Simple$CustomAnnotation(name=blah, type=class java.lang.String) hashCode= 895255138
> Simple$CustomAnnotationImpl@665753[_name=blah,_type=class java.lang.String] hashCode= 122852694
> hashCode should be 895255138
> The hashCode should computed according to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode() for annotations.
> ===============
> public class Simple{
> @Retention(RetentionPolicy.RUNTIME)
> @Target({FIELD, METHOD, PARAMETER})
> private @interface CustomAnnotation{
> public String name();
> public Class<?> type();
> }
> private static class CustomAnnotationImpl implements CustomAnnotation{
> final String _name;
> final Class<?> _type;
> public CustomAnnotationImpl(String name, Class<?> type) {
> _name = name;
> _type = type;
> }
> public String name() {
> return _name;
> }
> public Class<?> type() {
> return _type;
> }
> public Class<? extends Annotation> annotationType() {
> return CustomAnnotation.class;
> }
> @Override
> public int hashCode() {
> return HashCodeBuilder.reflectionHashCode(this);
> }
> /**
> * This conform to specs defined at http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Annotation.html#hashCode
> * @return good annotation hashCode
> */
> public int goodHashCode() {
> return (127 * "name".hashCode() ^ _name.hashCode()) + (127 *"type".hashCode() ^ _type.hashCode());
> }
>
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
> private static class Test{
> @CustomAnnotation(name="blah", type=String.class)
> String _blah;
> @Override
> public String toString() {
> return ToStringBuilder.reflectionToString(this);
> }
> }
>
> public static void main(String[] args) throws Exception{
> for(Field f : Test.class.getDeclaredFields()){
> for(Annotation a : f.getAnnotations()){
> System.out.println(a + " hashCode= " + a.hashCode());
> CustomAnnotationImpl c = new Simple.CustomAnnotationImpl("blah", String.class);
> System.out.println(c + " hashCode= " + c.hashCode());
> System.out.println("hashCode should be "+ c.goodHashCode());
> }
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.