-
Notifications
You must be signed in to change notification settings - Fork 369
Added check to accept version 61, throw error for higher #521
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
Open
Mahmoud-Khawaja
wants to merge
7
commits into
javapathfinder:java-17
Choose a base branch
from
Mahmoud-Khawaja:class-version-check
base: java-17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4735d4
Added check to accept version 61, throw error for higher
Mahmoud-Khawaja ca050e7
removed the duplicated DEPRECATED_ATTR
Mahmoud-Khawaja 529d00f
Add Java 17 class file version check and unit tests
Mahmoud-Khawaja f7a361b
Add .class files for class version check
Mahmoud-Khawaja 1ddfeac
updated the tests
Mahmoud-Khawaja 77728d0
Add resource directory for .class files and update build.gradle to in…
Mahmoud-Khawaja be90f23
added .class files
Mahmoud-Khawaja 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
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
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,50 @@ | ||
package gov.nasa.jpf.jvm; | ||
|
||
import gov.nasa.jpf.util.test.TestJPF; | ||
import gov.nasa.jpf.vm.ClassParseException; | ||
import org.junit.Test; | ||
|
||
import java.io.*; | ||
|
||
public class FileVersionTest extends TestJPF { | ||
|
||
private static final String JAVA17_CLASS = "/TestClassJava17.class"; | ||
private static final String JAVA21_CLASS = "/TestClassJava21.class"; | ||
|
||
// loading a .class file into a byte array | ||
private byte[] loadClassFile(String resourceName) throws IOException { | ||
try (InputStream is = getClass().getResourceAsStream(resourceName)) { | ||
if (is == null) throw new IOException("Resource not found: " + resourceName); | ||
|
||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
// we choose here buffer size 1024 cause its enough to read most .class files in one or two iterations | ||
// smaller buffer size like 256 will require more operations and larger buffers will waster memory | ||
// i'm not sure which is suitable for this since the test classes we complied is empty but i think both could work | ||
byte[] buffer = new byte[1024]; | ||
int bytesRead; | ||
while ((bytesRead = is.read(buffer)) != -1) { | ||
bos.write(buffer, 0, bytesRead); | ||
} | ||
return bos.toByteArray(); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void testSupportedVersionJava17() throws IOException, ClassParseException { | ||
byte[] classData = loadClassFile(JAVA17_CLASS); | ||
ClassFile classFile = new ClassFile(classData); | ||
ClassFileReader reader = new ClassFileReaderAdapter(); | ||
// this should pass with no exceptions | ||
classFile.parse(reader); | ||
} | ||
|
||
@Test(expected = ClassParseException.class) | ||
public void testUnsupportedVersionJava21() throws IOException, ClassParseException { | ||
byte[] classData = loadClassFile(JAVA21_CLASS); | ||
ClassFile classFile = new ClassFile(classData); | ||
ClassFileReader reader = new ClassFileReaderAdapter(); | ||
// this should throw ClassParseException | ||
classFile.parse(reader); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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.
Please enable this test and ensure it throws an exception. The test looks good; what was the reason for commenting it out? Perhaps JPF loads the version of the class file that was compiled by the build process rather than the one in
src/tests
, which would explain that this test does not throw an exception and thus fails?In that case, try to find a way to make your manually uploaded class file take precedence in the class loader.