-
Notifications
You must be signed in to change notification settings - Fork 0
Update readme and add examples #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f1d7ede
only check distinct for borrowed or higher permissions in invocation
CatarinaGamboa bb6d6b4
add example for urlconnection reuse
CatarinaGamboa e1352e3
url connection set property example
CatarinaGamboa 4ba1475
add examples urlconnection property with several methods
CatarinaGamboa 57df128
add example for timertask
CatarinaGamboa a7035ec
add example result set without calling next
CatarinaGamboa ea84ba6
add example for resultsetforwardonly
CatarinaGamboa c051a61
updated
CatarinaGamboa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,203 @@ | ||
| # latte: Lightweight Aliasing Tracking for Java | ||
| # Latte: Lightweight Aliasing Tracking for Java | ||
|
|
||
| Small project following the paper https://arxiv.org/pdf/2309.05637.pdf | ||
| Latte is a lightweight static analysis tool for tracking aliasing in Java programs. This tool allows you to annotate your programs with permissions where aliases are tracked to prevent bugs related to unexpected object references and side effects. | ||
|
|
||
| For more details, check our [research paper](https://arxiv.org/pdf/2309.05637). | ||
|
|
||
| ## Overview | ||
|
|
||
| Latte enables developers to identify and track aliasing relationships in their Java code using a permission-based type system. The tool statically verifies aliasing properties to help prevent common concurrency and memory management bugs. | ||
|
|
||
| ## Latte Annotations System | ||
|
|
||
| Latte uses annotations to specify the permissions of fields and parameters to track their uniqueness properties and the aliases that are created throughout the program: | ||
|
|
||
| - For parameters: | ||
| - `@Free` - For parameters that are globally unique. When a caller passes an argument to a `@Free` parameter, they cannot observe that value again. | ||
| - `@Borrowed` - For parameters that are unique in the callee's scope but may be stored elsewhere on the heap or stack. | ||
| - For fields: | ||
| - `@Unique` - For fields that cannot be aliased with other fields. | ||
| - For both: | ||
| - `@Shared` - For parameters or fields that can be shared, so they have no uniqueness guarantees. | ||
|
|
||
| Local variables are not annotated and start with a default annotation that allows them to take the assignment's permissions. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| latte-umbrella/ | ||
| ├── src/ | ||
| │ └── main/ | ||
| │ └── java/ | ||
| │ ├── latte/ | ||
| │ │ └── latte_umbrella/ | ||
| │ │ └── App.java # Main application entry point | ||
| │ └── examples/ # Test examples for the analysis | ||
| │ └── test/ | ||
| │ └── java/ | ||
| │ ├── AppTest.java # Creating JUnit tests | ||
| │ └── examples/ # Java classes to be used in the JUnit tests | ||
|
|
||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Java 11 or higher | ||
| - Maven | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Java 11 or higher | ||
| - Maven | ||
|
|
||
| ### Installation | ||
|
|
||
| Clone the repository and build with Maven: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/your-username/latte.git | ||
| cd latte | ||
| mvn clean install | ||
| ``` | ||
|
|
||
| To use Latte in your Java projects, you need to: | ||
| 1. Add the latte.jar to your project dependencies | ||
| 2. Import the specifications in your files (e.g., `import specification.Free`) | ||
|
|
||
|
|
||
| ### Usage | ||
|
|
||
| Run the tool against your Java code by executing the main application: | ||
|
|
||
| ```bash | ||
| java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App [options] <file-to-analyze> | ||
| ``` | ||
|
|
||
| ## Running Examples | ||
|
|
||
| The project includes example files to test the analysis capabilities: | ||
|
|
||
| ```bash | ||
| # Run the analysis on a specific example | ||
| java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App src/main/java/examples/Example1.java | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| Here is an example of Java classes using the Latte annotations: | ||
|
|
||
| ```java | ||
| class Node { | ||
| @Unique Object value; // Field value is Unique | ||
| @Unique Node next; // Field next is Unique | ||
|
|
||
|
|
||
| public Node (@Free Object value, @Free Node next) { | ||
| // We can assign @Free objects to Unique fields given that they have no aliases | ||
| this.value = value; | ||
| this.next = next; | ||
| } | ||
| } | ||
|
|
||
| public class MyStack { | ||
|
|
||
| @Unique Node root; // Field root is Unique | ||
|
|
||
| public MyStack(@Free Node root) { | ||
| this.root = root; // Since root is @Free we can assign it to root:@Unique | ||
| } | ||
|
|
||
| void push(@Free Object value) { | ||
| Node r; // Local variables start with a default annotation that allows | ||
| Node n; // them to take the assignment's permissions | ||
|
|
||
| r = this.root; // r is an alias to this.root with permission @Unique | ||
| this.root = null; // Nullify this.root so there is only one pointer to the | ||
| // value of the root, no other aliases | ||
| n = new Node(value, r); // Create new root with values that have no aliases. The constructors | ||
| // always return an new object that is @Free | ||
| this.root = n; // Replace root with a new value that is @Free and so can be assigned | ||
| // to an @Unique field | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| Tests can be run using Maven: | ||
|
|
||
| ```bash | ||
| mvn test | ||
| ``` | ||
|
|
||
| You can also test the tool directly on the example files: | ||
|
|
||
| ```bash | ||
| java -cp target/latte-umbrella-1.0.0.jar latte.latte_umbrella.App src/main/java/examples/MyStack.java | ||
| ``` | ||
|
|
||
| ## Contributing | ||
|
|
||
| We welcome contributions to Latte! Here's how to get started: | ||
|
|
||
| ### Development Workflow | ||
|
|
||
| 1. **Create a new branch for your feature:** | ||
| ```bash | ||
| git checkout -b feature/your-feature-name | ||
| ``` | ||
|
|
||
| 2. **Make your changes and commit them:** | ||
| ```bash | ||
| git add . | ||
| git commit -m "Description of your changes" | ||
| ``` | ||
|
|
||
| 3. **Set the upstream branch and push your changes:** | ||
| ```bash | ||
| git push --set-upstream origin feature/your-feature-name | ||
| ``` | ||
|
|
||
| 4. **Create a Pull Request:** | ||
| - Go to the repository on GitHub | ||
| - Click on "Pull Requests" > "New Pull Request" | ||
| - Select your branch | ||
| - Fill in the PR template with details about your changes | ||
| - Request a review from a team member | ||
|
|
||
| 5. **Address review feedback** and update your PR as needed | ||
|
|
||
| ### Code Standards | ||
|
|
||
| - Follow Java code conventions | ||
| - Write unit tests for new functionality | ||
| - Update documentation for any changes | ||
|
|
||
| ## Known Limitations | ||
|
|
||
| The tool is still under active development, and some features are limited: | ||
|
|
||
| - Does not support if statements without else branches | ||
| - Limited verification of aliases related to while loops | ||
| - Limited support for complex collections and generics | ||
|
|
||
| ## Future Work | ||
|
|
||
| We are continuously improving Latte to support more complex Java patterns and enhance the aliasing tracking capabilities. | ||
|
|
||
| ## Contributing Issues | ||
|
|
||
| If you encounter any problems while using Latte, please add an Issue to the repository with: | ||
| - A description of the problem | ||
| - Code sample that demonstrates the issue | ||
| - Expected vs. actual behavior | ||
|
|
||
| ## License | ||
|
|
||
| [Your license here] | ||
|
|
||
| ## Contact | ||
|
|
||
| [Your contact information here] | ||
This file contains hidden or 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
94 changes: 94 additions & 0 deletions
94
latte-umbrella/src/test/examples/ResultSetForwardOnly.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package examples; | ||
|
|
||
|
|
||
| import java.util.TimerTask; | ||
|
|
||
| import specification.Borrowed; | ||
| import specification.Free; | ||
| import specification.Unique; | ||
|
|
||
| public class ResultSetForwardOnly { | ||
| /* | ||
| * Error ResultSet is FORWARD_ONLY and we try to get a value before | ||
| */ | ||
| public static void example6367737(Connection con, String username, String password ) throws Exception { | ||
|
|
||
| // Step 1) Prepare the statement | ||
| PreparedStatement pstat = | ||
| con.prepareStatement("select typeid from users where username=? and password=?"); | ||
|
|
||
| // Step 2) Set parameters for the statement | ||
| pstat.setString(1, username); | ||
| pstat.setString(2, password); | ||
|
|
||
| // Step 3) Execute the query | ||
| ResultSet rs = pstat.executeQuery(); | ||
|
|
||
| // Step 4) Process the result | ||
| int rowCount=0; | ||
| while(rs.next()){ | ||
| rowCount++; | ||
| } | ||
|
|
||
| // ERROR! because it is FORWARD_ONLY, we cannot go back and check beforeFirst | ||
| rs.beforeFirst(); | ||
|
|
||
| int typeID = 0; // ... | ||
|
|
||
| // To be correct we need to change the resultset to be scrollable | ||
| /*PreparedStatement pstat = | ||
| con.prepareStatement("select typeid from users where username=? and password=?", | ||
| ResultSet.TYPE_SCROLL_SENSITIVE, | ||
| ResultSet.CONCUR_UPDATABLE); | ||
| */ | ||
| } | ||
|
|
||
|
|
||
| class Connection{ | ||
|
|
||
| // Result sets created using the returned PreparedStatement object will by default be type TYPE_FORWARD_ONLY | ||
| // and have a concurrency level of CONCUR_READ_ONLY. | ||
| @Unique // @StateRefinement (return, to="TYPE_FORWARD_ONLY, CONCUR_READ_ONLY") | ||
| public PreparedStatement prepareStatement(String s) { | ||
| return new PreparedStatement(); | ||
| } | ||
|
|
||
| @Unique // @StateRefinement (return, to="type == resultSetType") | ||
| public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency){ | ||
| return new PreparedStatement(); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| // @Ghost("type") | ||
| class PreparedStatement{ | ||
|
|
||
| void setString(int index, String s){} | ||
|
|
||
| // @StateRefinement(return, to="type != TYPE_FORWARD_ONLY, col == -1") | ||
| ResultSet executeQuery(String s){return null;} | ||
|
|
||
| // @StateRefinement(return, to="type, col == -1") | ||
| ResultSet executeQuery(){return null;} | ||
| } | ||
|
|
||
| // @Ghost("type") | ||
| class ResultSet{ | ||
|
|
||
| // @StateRefinement(this, type == ) | ||
| void beforeFirst(){} | ||
|
|
||
| // @StateRefinement(this, col > 0) | ||
| float getFloat(String s){return 0;} | ||
|
|
||
| // @StateRefinement(this, col > 0) | ||
| int getInt(int s){return 0;} | ||
|
|
||
| // @StateRefinement(this, col == old(col) + 1) | ||
| boolean next(){return true;} | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Duplicate 'Prerequisites' header detected; consider removing the redundant section for clarity.