Expected error is raised only after second (identical) attempt

オープン
#98 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
backend

調査の方向性

まず、HtmlDocumentBuilder、ThrowingErrorHandler、および issue にリンクされている Encoding ISO.html リソースを使って testHtmlIso を再現します。最初の parse(uri) とそのエラーハンドラーの設定を追跡します。壊れたドキュメント、または警告を生成するドキュメントが登録済みのハンドラーを発火させ、最初の同一の parse で例外をスローすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

The following code throws only after second call to parse, instead of throwing upon first call as expected.

private static final class ThrowingErrorHandler implements ErrorHandler {
  @Override
  public void warning(SAXParseException exception) throws SAXParseException {
    LOGGER.info("Warning while processing.", exception);
    throw exception;
  }

  @Override
  public void fatalError(SAXParseException exception) throws SAXParseException {
    LOGGER.info("Fatal while processing.", exception);
    throw exception;
  }

  @Override
  public void error(SAXParseException exception) throws SAXParseException {
    LOGGER.info("Error while processing.", exception);
    throw exception;
  }
}

@Test
public void testHtmlIso() throws Exception {
  String uri = "https://github.com/oliviercailloux/JARiS/raw/refs/heads/main/src/test/resources/io/github/oliviercailloux/jaris/xml/Html/Encoding%20ISO.html";
  HtmlDocumentBuilder builder = new HtmlDocumentBuilder();
  builder.setErrorHandler(new ThrowingErrorHandler());
  // logs no warning, does not throw
  builder.parse(uri);
  builder.setErrorHandler(new ThrowingErrorHandler());
  // logs a warning then throws
  builder.parse(uri);
}
Explanation

The document is supposed to raise a warning when parsed, and given the registered ThrowingErrorHandler, it is supposed to log then throw an exception when parsing. But the first parse completes without logging or throwing anything. Only the second one does.

主要言語
Java
スター
65
フォーク
29
平均マージ
11日 21時間
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

validator/htmlparser のほかの issue

validator/htmlparser の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。