<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>GitHub API on AsherSu's Blog</title><link>https://ashersu.cn/en/tags/github-api/</link><description>Recent content in GitHub API on AsherSu's Blog</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Fri, 19 Jun 2026 21:12:00 +0800</lastBuildDate><atom:link href="https://ashersu.cn/en/tags/github-api/index.xml" rel="self" type="application/rss+xml"/><item><title>How I Diagnosed and Fixed a Bug in hub4j/github-api</title><link>https://ashersu.cn/en/posts/hub4j-notification-bug-fix/</link><pubDate>Fri, 19 Jun 2026 21:12:00 +0800</pubDate><guid>https://ashersu.cn/en/posts/hub4j-notification-bug-fix/</guid><description>&lt;p&gt;While using the notification stream in &lt;code&gt;hub4j/github-api&lt;/code&gt;, I encountered a GitHub API &lt;code&gt;422&lt;/code&gt; response:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;span class="lnt"&gt;2&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Unable to parse If-Modified-Since request header.&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Please make sure value is in an acceptable format.&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;The fix was merged in &lt;a class="link" href="https://github.com/hub4j/github-api/pull/1984" target="_blank" rel="noopener"&#13;&#10; &gt;PR #1984&lt;/a&gt; and linked to &lt;a class="link" href="https://github.com/hub4j/github-api/issues/1985" target="_blank" rel="noopener"&#13;&#10; &gt;Issue #1985&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="trace-the-error-to-the-request-header"&gt;&lt;a href="#trace-the-error-to-the-request-header" class="header-anchor"&gt;&lt;/a&gt;Trace the error to the request header&#13;&#10;&lt;/h2&gt;&lt;p&gt;The response explicitly named &lt;code&gt;If-Modified-Since&lt;/code&gt;, so the investigation focused on request construction rather than response parsing. In &lt;code&gt;GHNotificationStream.fetch()&lt;/code&gt;, the request reused the &lt;code&gt;Last-Modified&lt;/code&gt; value from the previous response:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;If-Modified-Since&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lastModified&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;The problem was that &lt;code&gt;lastModified&lt;/code&gt; is optional. When it was &lt;code&gt;null&lt;/code&gt;, the request layer could send the string &lt;code&gt;&amp;quot;null&amp;quot;&lt;/code&gt;. That is not a valid HTTP date, so the GitHub API returned 422.&lt;/p&gt;&#10;&lt;h2 id="apply-the-smallest-correct-fix"&gt;&lt;a href="#apply-the-smallest-correct-fix" class="header-anchor"&gt;&lt;/a&gt;Apply the smallest correct fix&#13;&#10;&lt;/h2&gt;&lt;p&gt;The notification stream did not need a broad refactor. The header should only be set when a value exists:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1&#10;&lt;/span&gt;&lt;span class="lnt"&gt;2&#10;&lt;/span&gt;&lt;span class="lnt"&gt;3&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastModified&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;If-Modified-Since&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lastModified&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;This preserves the valid path. When GitHub returns &lt;code&gt;Last-Modified&lt;/code&gt;, later polls still use a conditional request. When it is absent, the client sends a normal request.&lt;/p&gt;&#10;&lt;h2 id="add-a-regression-test"&gt;&lt;a href="#add-a-regression-test" class="header-anchor"&gt;&lt;/a&gt;Add a regression test&#13;&#10;&lt;/h2&gt;&lt;p&gt;A one-line code change is not enough evidence that the bug will stay fixed. I added WireMock data for the notification endpoint and extended the existing test with another iteration after a response without &lt;code&gt;Last-Modified&lt;/code&gt;.&lt;/p&gt;&#10;&lt;p&gt;The test verifies observable behavior rather than a private field: consecutive notification reads must not send an &lt;code&gt;If-Modified-Since&lt;/code&gt; header containing &lt;code&gt;&amp;quot;null&amp;quot;&lt;/code&gt; and must not receive a 422 response.&lt;/p&gt;&#10;&lt;h2 id="takeaway"&gt;&lt;a href="#takeaway" class="header-anchor"&gt;&lt;/a&gt;Takeaway&#13;&#10;&lt;/h2&gt;&lt;p&gt;An effective open-source fix combines a reproducible failure, a focused code change, and a regression test that matches the project&amp;rsquo;s existing style.&lt;/p&gt;&#10;&lt;p&gt;The same boundary condition applies to many integrations: optional response headers, cursors, continuation tokens, and pagination links must be checked before they are copied into a later request.&lt;/p&gt;&#10;</description></item></channel></rss>