weixin_39603217
2020-12-09 09:40 阅读 0

GenericType is broken (at least for generic arrays)

new GenericType[]>() {}.getRawType() returns bogus

Affected Versions

[2.0]

该提问来源于开源项目:eclipse-ee4j/jaxrs-api

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • weixin_39603217 weixin_39603217 2020-12-09 09:40
    • Issue Imported From: https://github.com/jax-rs/api/issues/207
    • Original Issue Raised By:
    • Original Issue Assigned To:
    • Original Issue Closed By:
    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented Reported by mmatula

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented mmatula said: Turns out GenericType had more issues - accepting invalid types (even one of the tests was sending in non-sense and was happy to receive non-sense), questionable parameters to the static constructors (why allowing to specify both Type and rawType?) and wasn't consistent with the way GenericEntity treated things. Please consider the following patch that solves the issues I could spot:

    1. makes GenericType more consistent with GenericEntity
      • uses regular constructor instead of a static factory method like GenericEntity
      • GenericEntity uses the same logic to figure out the type parameter (which was more sophisticated in GenericType so copied it from there)
      • GenericEntity now defines equals(), hashCode() and toString() similar to GenericType
    2. GenericType correctly detects illegal arguments/type arguments and fixed the incorrect test
    3. GenericType returns correct raw type for generic arrays

    I also added a few more tests.

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented mmatula said: Uploaded v2 version of the patch. In addition to the issues the first version of the patch addressed, this one has the following additional improvements:

    • sharing the logic between GenericType and GenericEntity when it comes computing the right value of Type property (GenericType exposes a package private method that GenericEntity reuses - can also be pulled out into a package private utility class)
    • fixed the logic that searches for the value of the GenericType/Entity type variable
    • removed the use-less getParameterTypes() method from GenericType
    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented said: Patch applied.

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented File: generic-type-fix-v2.diff Attached By: mmatula

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented This issue was imported from java.net JIRA JAX_RS_SPEC-202

    点赞 评论 复制链接分享
  • weixin_39603217 weixin_39603217 2020-12-09 09:40

    Commented Marked as fixed on Monday, June 18th 2012, 2:27:52 am

    点赞 评论 复制链接分享

相关推荐