2016-11-04 58 views
0

我有JSOUP v1.9.2,一切正常,在v1.10.1我得到「ConcurrentModificationException」(代碼結束)。我在HTML上有這個兩次。我首先從HTML設置中刪除並設置一個。我做錯了還是1.10.1中的錯誤?代碼:我做錯了還是錯誤1.10.1

final Element typeElementObjaveSuda = document.getElementById(Type.OBJAVE_SUDA.getName()); 
     if (typeElementObjaveSuda != null) { 
       typeElementObjaveSuda.removeAttr("checked"); 
     } 
     final Element typeElementObjaveJavnogBiljeznika = document.getElementById(Type.OBJAVE_JAVNOG_BILJEZNIKA.getName()); 
     if (typeElementObjaveJavnogBiljeznika != null) { 
       typeElementObjaveJavnogBiljeznika.removeAttr("checked"); 
     } 
     final Element typeElementCurrent = document.getElementById(tip.getName()); 
     if (typeElementCurrent != null) { 
      typeElementCurrent.attr("checked", "checked"); 
     } 

引起:java.util.ConcurrentModificationException:空 在java.util.LinkedHashMap中$ LinkedHashIterator.nextNode(LinkedHashMap.java:730)〜[NA:1.8.0內部] 在java的.util.LinkedHashMap $ LinkedKeyIterator.next(LinkedHashMap.java:753)〜[na:1.8.0-internal] at org.jsoup.nodes.Attributes.removeIgnoreCase(Attributes.java:122)〜[jsoup-1.10.1 .jar:na] at org.jsoup.nodes.Node.removeAttr(Node.java:128)〜[jsoup-1.10.1.jar:na] at hr.ibm.oglasna.statistics.OglasnaCollector.fetchResult(OglasnaCollector .java:167)〜[類/:na] ... 12個常用框架省略

+0

沒有添加:我對HTML有這個'兩次。 – Hrvoje

回答

0

這似乎是一個錯誤:

String htmlString = " <input type=\"radio\" id=\"edit-rid-1\" name=\"rid\" value=\"1\" checked=\"checked\" class=\"form-radio\" />"; 

Element element = Jsoup.parse(htmlString).getElementById("edit-rid-1"); 

System.out.println(element.toString()); 
System.out.println(element.hasAttr("checked")); 
element.removeAttr("checked"); 
System.out.println(element.toString()); 

輸出與jsoup 1.9.1

<input type="radio" id="edit-rid-1" name="rid" value="1" checked class="form-radio"> 
true 
<input type="radio" id="edit-rid-1" name="rid" value="1" class="form-radio"> 

輸出與jsoup 1.10.1

<input type="radio" id="edit-rid-1" name="rid" value="1" checked class="form-radio"> 
true 
Exception in thread "main" 
java.util.ConcurrentModificationException 
    at java.util.LinkedHashMap$LinkedHashIterator.nextNode(Unknown Source) 
    at java.util.LinkedHashMap$LinkedKeyIterator.next(Unknown Source) 
    at org.jsoup.nodes.Attributes.removeIgnoreCase(Attributes.java:122) 
    at org.jsoup.nodes.Node.removeAttr(Node.java:128) 
    at Webscraping.JsoupExamples.localByID(JsoupExamples.java:603) 
    at Tester.App.main(App.java:119) 

所以element.removeAttr("checked");導致異常。打開GitHub上的問題:從開發商

https://github.com/jhy/jsoup/issues/785

響應,感謝您的報告。這是固定在頭上的#759相同

相關問題