jcabi-github icon indicating copy to clipboard operation
jcabi-github copied to clipboard

Incorrect hasName implementation

Open g4s8 opened this issue 6 years ago • 4 comments

Github API returns null as name JSON field if user doesn't have a name, but User.Smart#hasName implementation doesn't check it:

public boolean hasName() throws IOException {
    return this.json().containsKey("name");
}

So when I check that user has a name and then read this name I'm getting an error:

java.lang.ClassCastException: javax.json.JsonValueImpl cannot be cast to javax.json.JsonString
    at org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl.getJsonString(JsonObjectBuilderImpl.java:252)
    at org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl.getString(JsonObjectBuilderImpl.java:257)
    at com.jcabi.github.User$Smart.name_aroundBody8(User.java:191)
    at com.jcabi.github.User$Smart$AjcClosure9.run(User.java:1)
    at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
    at com.jcabi.aspects.aj.MethodLogger.wrap(MethodLogger.java:213)
    at com.jcabi.aspects.aj.MethodLogger.ajc$inlineAccessMethod$com_jcabi_aspects_aj_MethodLogger$com_jcabi_aspects_aj_MethodLogger$wrap(MethodLogger.java:1)
    at com.jcabi.aspects.aj.MethodLogger.wrapClass(MethodLogger.java:140)
    at com.jcabi.github.User$Smart.name(User.java:181)

(https://github.com/zerocracy/farm/issues/1753).

g4s8 avatar Mar 03 '19 16:03 g4s8

@amihaiemil/z please, pay attention to this issue

0crat avatar Mar 03 '19 16:03 0crat

@g4s8/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

0crat avatar Mar 03 '19 16:03 0crat

@g4s8 please provide a PR, there are no DEVs on the project and I don't really have time for it now.

I'll release it afterwards. Thanks!

amihaiemil avatar Mar 03 '19 20:03 amihaiemil

@g4s8 do you still have this issue, care to provide a PR? :D

amihaiemil avatar Jun 04 '19 14:06 amihaiemil