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

Miscellaneous code cleanup #65

Merged
merged 6 commits into from
Nov 9, 2021
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 @@ -37,7 +37,7 @@
* @author Kohsuke Kawaguchi
*/
public class AccessRestrictionFactory {
private final Map<String,AccessRestriction> instances = new HashMap<String, AccessRestriction>();
private final Map<String,AccessRestriction> instances = new HashMap<>();
private final ClassLoader cl;

@SuppressFBWarnings("EI_EXPOSE_REP2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import org.apache.maven.plugin.logging.Log;
Expand Down Expand Up @@ -87,7 +88,7 @@ public class Checker {
* <li>internal name of a type + '.' + method name + method descriptor
* </ul>
*/
private final Map<String,Restrictions> restrictions = new HashMap<String,Restrictions>();
private final Map<String,Restrictions> restrictions = new HashMap<>();

private final AccessRestrictionFactory factory;

Expand Down Expand Up @@ -149,12 +150,11 @@ private void loadAccessRestrictions() throws IOException {
*
* @param isInTheInspectedModule
* This value shows up in {@link RestrictedElement#isInTheInspectedModule()}.
* @param stream
*/
public void loadRestrictions(InputStream stream, final boolean isInTheInspectedModule) throws IOException {
if (stream==null) return;

BufferedReader r = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
BufferedReader r = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
String className;
while ((className=r.readLine())!=null) {
InputStream is = dependencies.getResourceAsStream(className.replace('.','/') + ".class");
Expand Down Expand Up @@ -214,11 +214,7 @@ public boolean isInTheInspectedModule() {
public void visitEnd() {
try {
restrictions.put(keyName,build(factory));
} catch (ClassNotFoundException e) {
failure(e);
} catch (InstantiationException e) {
failure(e);
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
failure(e);
}
}
Expand All @@ -244,12 +240,9 @@ private void failure(Exception e) {
* Inspects a class for the restriction violations.
*/
public void checkClass(File clazz) throws IOException {
FileInputStream in = new FileInputStream(clazz);
try {
try (FileInputStream in = new FileInputStream(clazz)) {
ClassReader cr = new ClassReader(in);
cr.accept(new RestrictedClassVisitor(), SKIP_FRAMES);
} finally {
in.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -70,15 +69,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
File outputDir = new File(project.getBuild().getOutputDirectory());

List<URL> dependencies = new ArrayList<URL>();
for (Artifact a : (Collection<Artifact>)project.getArtifacts())
List<URL> dependencies = new ArrayList<>();
for (Artifact a : project.getArtifacts())
dependencies.add(a.getFile().toURI().toURL());
URL outputURL = outputDir.toURI().toURL();
dependencies.add(outputURL);
getLog().debug("inspecting\n" + dependencies.stream().map(URL::toString).collect(Collectors.joining("\n")));

final boolean[] failed = new boolean[1];
Checker checker = new Checker(new URLClassLoader(dependencies.toArray(new URL[dependencies.size()]), getClass().getClassLoader()),
Checker checker = new Checker(new URLClassLoader(dependencies.toArray(new URL[0]), getClass().getClassLoader()),
new ErrorListener() {
public void onError(Throwable t, Location loc, String msg) {
String locMsg = loc+" "+msg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public int hashCode() {
}

abstract static class Parser extends AnnotationVisitor {
private List<Type> restrictions = new ArrayList<Type>();
private List<Type> restrictions = new ArrayList<>();
private final RestrictedElement target;

protected Parser(RestrictedElement target) {
Expand Down