sharanggupta opened a new pull request, #796:
URL: https://github.com/apache/commons-vfs/pull/796

   Fixes [VFS-864](https://issues.apache.org/jira/browse/VFS-864).
   
   **What**
   
   JSch calls `Logger.isEnabled(level)` before it calls `Logger.log(level, 
msg)`. The Commons Logging bridge in `SftpClientFactory.JSchLogger` answered 
the WARN question with `LOG.isDebugEnabled()`, while `log(WARN, msg)` writes 
with `LOG.warn(msg)`. So with the usual INFO or WARN configuration for 
`org.apache.commons.vfs2.provider.sftp.SftpClientFactory`, every JSch warning 
(host key, authentication and algorithm warnings) was silently dropped; they 
only showed up with DEBUG enabled.
   
   **How**
   
   `isEnabled(WARN)` now checks `isWarnEnabled()`, which matches what 
`log(WARN, ...)` does and what the other levels already do.
   
   To test this without depending on the test logging configuration (the test 
classpath routes Commons Logging to Log4j 2 with the root at ERROR, where WARN 
and DEBUG are both disabled and the bug is invisible), `JSchLogger` now takes 
the `Log` in its constructor and is package-private instead of private. The 
static `JSch.setLogger(new JSchLogger(LOG))` call is unchanged in effect. 
Nothing public changes; japicmp is part of the default goal and passed.
   
   **Tests**
   
   `SftpClientFactoryTest` builds a `JSchLogger` around a Commons Logging 
`SimpleLog` set to DEBUG, WARN and ERROR and checks `isEnabled` for every JSch 
level. Without the fix `testIsEnabledAtWarnLevel` fails (`isEnabled(WARN)` is 
`false` at WARN level); with it all three pass.
   
   Verified locally with the default `mvn` goal on `commons-vfs2` on Java 17 
(3228 tests, RAT, japicmp, Javadoc, SpotBugs, PMD, Checkstyle all pass; the 
skipped tests are the provider suites that need external servers, unchanged by 
this PR) and the SFTP tests on Java 8.
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute? Claude (Anthropic) helped draft the fix and the tests; I reviewed 
all of it, ran the builds and checked that the new test fails without the 
change.
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to