[Demonstration 1]

[Buggy Method]
@Test
public void test() {
    Session session = HttpExchangeHelper.getSession(httpExchange);
    assertNotNull(session);
    SessionHelper.invalidateSession(session);
    assertTrue(session.equals(HttpExchangeHelper.getSession(httpExchange)));
    assertFalse(HttpExchangeHelper.isAuthenticated(httpExchange));
    assertTrue(!SessionHelper.isSessionTimedOut(session));
    session.setLastUsed(timeout * 2);
    assertTrue(!SessionHelper.isSessionTimedOut(session));
}

[Buggy Hunk]
assertTrue(session.equals(HttpExchangeHelper.getSession(httpExchange)));

[Patch]
assertFalse(session.equals(HttpExchangeHelper.getSession(httpExchange)));

[Demonstration 2]

[Buggy Method]
public void waitForLayout(long timeout) throws Throwable {
    waitForLayout(timeout * (mDebug ? 10000 : 1), TimeUnit.SECONDS);
}

[Buggy Hunk]
waitForLayout(timeout * (mDebug ? 10000 : 1), TimeUnit.SECONDS);

[Patch]
waitForLayout(timeout * (mDebug ? 10000 : 1), TimeUnit.SECONDS, true);

[Demonstration 3]

[Buggy Method]
protected URLConnection createConnection() {
    String currentUrl = session.currUrl;
    if (TextUtils.isEmpty(currentUrl)) {
        return null;
    }
    URLConnection connection = null;
    try {
        URL url = new URL(currentUrl);
        String dnsPrefetchAddress = intent.getStringExtra(SonicSessionConnection.DNS_PREFETCH_ADDRESS);
        String originHost = null;
        /**
         * Use the ip value mapped by {@code SonicSessionConnection.DNS_PREFETCH_ADDRESS} to avoid the cost time of DNS resolution.
         * Meanwhile it can reduce the risk from hijacking http session.
         */
        if (!TextUtils.isEmpty(dnsPrefetchAddress)) {
            originHost = url.getHost();
            url = new URL(currentUrl.replace(originHost, dnsPrefetchAddress));
            SonicUtils.log(TAG, Log.INFO, "create UrlConnection with DNS-Prefetch(" + originHost + " -> " + dnsPrefetchAddress + ").");
        }
        connection = url.openConnection();
        if (connection != null) {
            if (connection instanceof HttpURLConnection) {
                ((HttpURLConnection) connection).setInstanceFollowRedirects(false);
            }
            if (!TextUtils.isEmpty(originHost)) {
                /**
                 * If originHost is not empty, that means connection uses the ip value instead of http host.
                 * So http header need to set the Host and {@link com.tencent.sonic.sdk.SonicSessionConnection.CUSTOM_HEAD_FILED_DNS_PREFETCH} request property.
                 */
                connection.setRequestProperty("Host", originHost);
                connection.setRequestProperty(SonicSessionConnection.CUSTOM_HEAD_FILED_DNS_PREFETCH, url.getHost());
                if (connection instanceof HttpsURLConnection) {
                    // 如果属于https，需要特殊处理，比如支持sni
                    /**
                     * If the scheme of url is https, then it needs extra processing, such as the sni support.
                     */
                    final String finalOriginHost = originHost;
                    final URL finalUrl = url;
                    HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
                    httpsConnection.setSSLSocketFactory(new SonicSniSSLSocketFactory(SonicEngine.getInstance().getRuntime().getContext(), originHost));
                    httpsConnection.setHostnameVerifier(new HostnameVerifier() {

                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            boolean verifySuccess = false;
                            long startTime = System.currentTimeMillis();
                            if (finalUrl.getHost().equals(hostname)) {
                                verifySuccess = HttpsURLConnection.getDefaultHostnameVerifier().verify(finalOriginHost, session);
                                SonicUtils.log(TAG, Log.DEBUG, "verify hostname cost " + (System.currentTimeMillis() - startTime) + " ms.");
                            }
                            return verifySuccess;
                        }
                    });
                }
            }
        }
    } catch (Throwable e) {
        if (connection != null) {
            connection = null;
        }
        SonicUtils.log(TAG, Log.ERROR, "create UrlConnection fail, error:" + e.getMessage() + ".");
    }
    return connection;
}

[Buggy Hunk]
String currentUrl = session.currUrl;

[Patch]
String currentUrl = session.srcUrl;