Skip to content

Commit

Permalink
Replace with getSystemResourceAsStream
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Jun 21, 2024
1 parent 5d18264 commit ebf223a
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -2306,27 +2306,23 @@ public Constructor<?>[] getConstructors() throws SecurityException {
}

private Method[] filterOutDeconstructorsFromMethods(Method[] in) {
if (this.getClassLoader() != null) {
Set<String> isPattern = new HashSet<>();
ClassModel cm = null;
try (InputStream resource = this.getClassLoader().getResourceAsStream(getName() + ".class")) {
if (resource == null) {
return in;
}
byte[] bytes = resource.readAllBytes();
cm = ClassFile.of().parse(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (MethodModel mm : cm.methods()) {
PatternAttribute pa = mm.findAttribute(Attributes.pattern()).orElse(null);
if (pa != null) isPattern.add(mm.methodName().stringValue());
Set<String> isPattern = new HashSet<>();
ClassModel cm = null;
try (InputStream resource = ClassLoader.getSystemResourceAsStream(getName() + ".class")) {
if (resource == null) {
return in;
}
Method[] ret = Arrays.stream(in).filter(m -> !isPattern.contains(m.getName())).toArray(Method[]::new);
return ret;
} else {
return in;
byte[] bytes = resource.readAllBytes();
cm = ClassFile.of().parse(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (MethodModel mm : cm.methods()) {
PatternAttribute pa = mm.findAttribute(Attributes.pattern()).orElse(null);
if (pa != null) isPattern.add(mm.methodName().stringValue());
}
Method[] ret = Arrays.stream(in).filter(m -> !isPattern.contains(m.getName())).toArray(Method[]::new);
return ret;
}

/**
Expand Down Expand Up @@ -2417,7 +2413,7 @@ public Deconstructor<?>[] getDeclaredDeconstructors() throws SecurityException {

private Deconstructor<?>[] getDeclaredDeconstructors0(Class<?>[] params, int which) {
ArrayList<Deconstructor<?>> decs = new ArrayList<>();
try(InputStream is = this.getClassLoader().getResourceAsStream(getName() + ".class")) {
try(InputStream is = ClassLoader.getSystemResourceAsStream(getName() + ".class")) {
byte[] bytes = is.readAllBytes();
ClassModel cm = ClassFile.of().parse(bytes);
for (MethodModel mm : cm.methods()) {
Expand Down

0 comments on commit ebf223a

Please sign in to comment.