qos-ch / slf4j

Simple Logging Facade for Java
http://www.slf4j.org
MIT License
2.32k stars 980 forks source link

Apparently dead code in LoggerFactory #371

Closed TWiStErRob closed 9 months ago

TWiStErRob commented 9 months ago

While reading slf4j2 code to figure out how ~bindings~providers work, I came across a line that confused me: catch(NoSuchFieldError) in LoggerFactory

https://github.com/qos-ch/slf4j/blob/216459e5d81c3b066748c51a4eabcda32395fe05/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java#L364-L388

I was wondering why the comment references REQUESTED_API_VERSION, while there's no such thing in the try.

I found the change that invalidated that catch, and ~I'm still baffled as to why Java does not complain about a checked exception being not used~ I see why javac didn't alert: it's an Error, not checked!.

ceki commented 9 months ago

Hi @TWiStErRob

I think the NoSuchFieldError can no longer occur and it makes no sense to check for it. As for the compiler not complaining, it is a good question but beyond the scope of SLF4J. :relaxed:

TWiStErRob commented 9 months ago

See edit: Error is not a checked exception.

ceki commented 9 months ago

Unreachable code removed in commit 5ccbe20b118828f35fd64a887d77fb9b72ad1a6e