Skip to content

Commit

Permalink
Drop reflection, call existing method
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveeclipse committed Jun 22, 2020
1 parent a5f52df commit 2149124
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is the changelog for SpotBugs. This follows [Keep a Changelog v1.0.0](http:
Currently the versioning policy of this project follows [Semantic Versioning v2.0.0](http://semver.org/spec/v2.0.0.html).

## Unreleased - 2020-??-??
### Fixed
* Use method call instead of reflection to get BCEL frame type ([#1176](https://github.com/spotbugs/spotbugs/issues/1176))

## 4.0.5 - 2020-06-20
### Fixed
Expand Down
51 changes: 1 addition & 50 deletions spotbugs/src/main/java/edu/umd/cs/findbugs/StackMapAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package edu.umd.cs.findbugs;

import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
Expand All @@ -43,7 +40,6 @@

import edu.umd.cs.findbugs.OpcodeStack.Item;
import edu.umd.cs.findbugs.OpcodeStack.JumpInfo;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
import edu.umd.cs.findbugs.classfile.IAnalysisCache;
import edu.umd.cs.findbugs.classfile.MethodDescriptor;
Expand Down Expand Up @@ -135,52 +131,7 @@ static List<Item> getInitialLocals(MethodDescriptor descriptor) {
return locals;
}

static final @CheckForNull Field frame_type_field;
static {
Field f;
try {
f = AccessController.doPrivileged((PrivilegedAction<Field>) () -> {
Class<StackMapEntry> c = StackMapEntry.class;
Field result;
try {
result = c.getDeclaredField("frame_type");
result.setAccessible(true);
return result;
} catch (NoSuchFieldException e1) {
throw new AssertionError("frame_type field doesn't exist");
} catch (SecurityException e2) {
return null;
}

});
} catch (Exception e) {
AnalysisContext.logError("Unable to create frame_type accessor", e);
f = null;
}
if (DEBUG) {
System.out.println("Frame type field is null:" + (f == null));
}
frame_type_field = f;
}

static int getFrameType(StackMapEntry e) {
if (frame_type_field == null) {
return -1;
}
try {
return (Integer) frame_type_field.get(e);
} catch (IllegalArgumentException e1) {
return -1;
} catch (IllegalAccessException e1) {
return -1;
}
}

static private @CheckForNull JumpInfoFromStackMap getFromStackMap(IAnalysisCache analysisCache, MethodDescriptor descriptor) {
if (frame_type_field == null) {
return null;
}

Method method;
try {
method = analysisCache.getMethodAnalysis(Method.class, descriptor);
Expand Down Expand Up @@ -211,7 +162,7 @@ static int getFrameType(StackMapEntry e) {
int pc = 0;
for (StackMapEntry e : stackMapTable.getStackMap()) {
pc += e.getByteCodeOffset();
int rawFrameType = getFrameType(e);
int rawFrameType = e.getFrameType();
StackFrameType stackFrameType = StackFrameType.get(rawFrameType);
switch (stackFrameType) {
case SAME_FRAME:
Expand Down

0 comments on commit 2149124

Please sign in to comment.