Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-7738] don't dump raw stack traces to System.err #1064

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public boolean matches(String requirement) {
return range.getRecommendedVersion().compareTo(version) == 0;
}
} catch (InvalidVersionSpecificationException ex) {
// TODO error reporting
ex.printStackTrace();
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this information is required, it should be ad debug log level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish these classes were documented better, and I wish this one and several others were non-public. That said, it does seem it's used in only one other place where we do:

         if (!matcher.matches(requirement.getValue())) {
                getLog().debug("Toolchain " + this + " doesn't match required property: " + key);
                return false;
            }

That is, a false result already logs at debug level.

}
}
Expand Down
52 changes: 0 additions & 52 deletions maven-core/src/test/java/org/apache/maven/MavenTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
.map(Dependency::new)
.collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

@elharo elharo Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is test code, debug logging seems too weak. If this is a problem worth paying attention to, or that might explain why a test has failed or flaked, then bubble the IOException to immediately fail the test with the root cause rather than waiting for it to fail down the line.

On the other hand, if the test shouldn't and doesn't fail when this exception is thrown, then no debug log is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further investigation, this immensely over-engineered class is used in exactly one test method testCacheKey which doesn't even enter this method when it runs.

// ignore
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.maven.cli.logging.impl.UnsupportedSlf4jBindingConfiguration;
import org.codehaus.plexus.util.PropertyUtils;
Expand All @@ -42,8 +39,6 @@ public class Slf4jConfigurationFactory {
public static final String RESOURCE = "META-INF/maven/slf4j-configuration.properties";

public static Slf4jConfiguration getConfiguration(ILoggerFactory loggerFactory) {
Map<URL, Set<Object>> supported = new LinkedHashMap<>();

String slf4jBinding = loggerFactory.getClass().getCanonicalName();

try {
Expand All @@ -52,19 +47,18 @@ public static Slf4jConfiguration getConfiguration(ILoggerFactory loggerFactory)

while (resources.hasMoreElements()) {
URL resource = resources.nextElement();

Properties conf = PropertyUtils.loadProperties(resource.openStream());

String impl = conf.getProperty(slf4jBinding);

if (impl != null) {
return (Slf4jConfiguration) Class.forName(impl).newInstance();
try {
Properties conf = PropertyUtils.loadProperties(resource.openStream());
String impl = conf.getProperty(slf4jBinding);
if (impl != null) {
return (Slf4jConfiguration) Class.forName(impl).newInstance();
}
} catch (IOException | ClassNotFoundException | IllegalAccessException | InstantiationException ex) {
// ignore and move on to the next
}

supported.put(resource, conf.keySet());
}
} catch (IOException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
} catch (IOException ex) {
// ignore
}

return new UnsupportedSlf4jBindingConfiguration();
Expand Down