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

Clarify error messages in FieldRefValidator #1653

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
17 changes: 8 additions & 9 deletions src/main/java/soot/jimple/validation/FieldRefValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public void validate(Body body, List<ValidationException> exceptions) {
return;
}

for (Unit unit : body.getUnits().getNonPatchingChain()) {
Stmt s = (Stmt) unit;
for (Unit u : body.getUnits().getNonPatchingChain()) {
Stmt s = (Stmt) u;
if (!s.containsFieldRef()) {
continue;
}
Expand All @@ -66,26 +66,25 @@ public void validate(Body body, List<ValidationException> exceptions) {
try {
SootField field = v.getField();
if (field == null) {
exceptions.add(new UnitValidationException(unit, body, "Resolved field is null: " + fr.toString()));
exceptions.add(new UnitValidationException(u, body, "Resolved field is null: " + fr.toString()));
} else if (!field.isStatic() && !field.isPhantom()) {
exceptions
.add(new UnitValidationException(unit, body, "Trying to get a static field which is non-static: " + v));
exceptions.add(new UnitValidationException(u, body, "Used StaticFieldRef for a non-static field: " + v));
}
} catch (ResolutionFailedException e) {
exceptions.add(new UnitValidationException(unit, body, "Trying to get a static field which is non-static: " + v));
exceptions.add(new UnitValidationException(u, body, "Unable to resolve FieldRef " + v + ": " + e.getMessage()));
tim-hoffman marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (fr instanceof InstanceFieldRef) {
InstanceFieldRef v = (InstanceFieldRef) fr;

try {
SootField field = v.getField();
if (field == null) {
exceptions.add(new UnitValidationException(unit, body, "Resolved field is null: " + fr.toString()));
exceptions.add(new UnitValidationException(u, body, "Resolved field is null: " + fr.toString()));
} else if (field.isStatic() && !field.isPhantom()) {
exceptions.add(new UnitValidationException(unit, body, "Trying to get an instance field which is static: " + v));
exceptions.add(new UnitValidationException(u, body, "Used InstanceFieldRef for a static field: " + v));
}
} catch (ResolutionFailedException e) {
exceptions.add(new UnitValidationException(unit, body, "Trying to get an instance field which is static: " + v));
exceptions.add(new UnitValidationException(u, body, "Unable to resolve FieldRef " + v + ": " + e.getMessage()));
tim-hoffman marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
throw new AssertionError("unknown field ref: " + fr);
Expand Down