Description
I just encountered a bit of a tricky bug. Consider this :
Request request = new Request(url)
request.setExtras(Map.of("key", "value"))
When you get a cycle retry on this request, it'll blow up with UnsupportedException. That is because putExtra on the linked line above will call put on your immutable hashmap. It would be safer if setExtras would only allow a mutable hashmap as parameter somehow, or rewrap the parameter in new HashMap<>(immHashmap) or something.
Affected Version and code The latest version 0.10.0 and below.
https://github.com/code4craft/webmagic/blob/7ededbea1a3b040c4429293e10a30996ccf9caf0/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java#L482
Description I just encountered a bit of a tricky bug. Consider this :
When you get a cycle retry on this request, it'll blow up with
UnsupportedException
. That is becauseputExtra
on the linked line above will callput
on your immutable hashmap. It would be safer ifsetExtras
would only allow a mutable hashmap as parameter somehow, or rewrap the parameter innew HashMap<>(immHashmap)
or something.