-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PrimAndStringOp bug in AstJavaTypeInference #12
Merged
msridhar
merged 2 commits into
wala:master
from
vazexqi:ASTJavaTypeInference-PrimAndStringOp-bug
Mar 29, 2013
Merged
PrimAndStringOp bug in AstJavaTypeInference #12
msridhar
merged 2 commits into
wala:master
from
vazexqi:ASTJavaTypeInference-PrimAndStringOp-bug
Mar 29, 2013
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ypeInference.JavaPrimitiveType This is a simple test case that illustrates the issue with type inference on a String + some primitive. The code is package javaonepointfive; public class TypeInferencePrimAndStringOp { public static void main(String[] args) { int a = 2; String result = "a" + a; } }
This ensures that when we need to use stringClass, it can be constructed directly from the cha field. Previously, it was only initialized after the call to super(…) in the constructor. However, by then it is too late because super(…) calls initialize() and solve() which need the stringClass field.
msridhar
added a commit
that referenced
this pull request
Mar 29, 2013
…gOp-bug PrimAndStringOp bug in AstJavaTypeInference
Nice report and fix; merged. Thanks! |
msridhar
added a commit
that referenced
this pull request
Mar 30, 2013
…gOp-bug Add the test file to com.ibm.wala.cast.java.test.data/src for pull request #12
msridhar
added a commit
that referenced
this pull request
Aug 7, 2013
…gOp-bug PrimAndStringOp bug in AstJavaTypeInference
msridhar
added a commit
that referenced
this pull request
Aug 7, 2013
…gOp-bug Add the test file to com.ibm.wala.cast.java.test.data/src for pull request #12
deepkiransangha
pushed a commit
to deepkiransangha/WALA
that referenced
this pull request
Jan 27, 2025
tejkart
pushed a commit
to tejkart/WALA
that referenced
this pull request
Jan 27, 2025
tejkart
pushed a commit
to tejkart/WALA
that referenced
this pull request
Jan 27, 2025
mh4535
pushed a commit
to mh4535/WALA
that referenced
this pull request
Jan 27, 2025
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
I was using AstJavaTypeInference and discovered a bug with the way that string + primitives are handled. I've included a test case in the pull request but here's the gist of it
Trying to infer the type of
result
ends with aUnexpected type: class com.ibm.wala.analysis.typeInference.JavaPrimitiveType
exception.Cause
After tracing it down, I found that PrimAndStringOp uses a field call
stringClass
in AstJavaTypeInference but that field does not get a chance to be initialized before it is used. That is because the first line in AstJavaTypeInference is a call to super that initializes the AbstractFixedPointSolver, which calls theinitialize()
andsolve()
functions, which in turn, calls theevaluate
function in PrimAndStringOp.Here's the original constructor for AstJavaTypeInference:
(Possible) Solution
I used lazy initialization for stringClass to ensure that it is initialized when it is first used in the
evaluate
function in PrimAndStringOp.