Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge "dx: Support v53 class files built from language level 8 sources."
Browse files Browse the repository at this point in the history
  • Loading branch information
15characterlimi authored and Gerrit Code Review committed Aug 16, 2017
2 parents 091bbc6 + 6988f30 commit ba2b8e2
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 28 deletions.
10 changes: 6 additions & 4 deletions dx/src/com/android/dx/cf/direct/DirectClassFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public class DirectClassFile implements ClassFile {
* See http://en.wikipedia.org/wiki/Java_class_file for an up-to-date
* list of version numbers. Currently known (taken from that table) are:
*
* J2SE 7.0 = 51 (0x33 hex),
* J2SE 6.0 = 50 (0x32 hex),
* J2SE 5.0 = 49 (0x31 hex),
* Java SE 9 = 53 (0x35 hex),
* Java SE 8 = 52 (0x34 hex),
* Java SE 7 = 51 (0x33 hex),
* Java SE 6.0 = 50 (0x32 hex),
* Java SE 5.0 = 49 (0x31 hex),
* JDK 1.4 = 48 (0x30 hex),
* JDK 1.3 = 47 (0x2F hex),
* JDK 1.2 = 46 (0x2E hex),
Expand All @@ -71,7 +73,7 @@ public class DirectClassFile implements ClassFile {
*
* Note: if you change this, please change "java.class.version" in System.java.
*/
private static final int CLASS_FILE_MAX_MAJOR_VERSION = 52;
private static final int CLASS_FILE_MAX_MAJOR_VERSION = 53;

/** maximum {@code .class} file minor version */
private static final int CLASS_FILE_MAX_MINOR_VERSION = 0;
Expand Down
22 changes: 20 additions & 2 deletions dx/src/com/android/dx/command/dexer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,15 @@ private boolean processAllFiles() {
}

// remaining files
FileNameFilter filter = new RemoveModuleInfoFilter(new NotFilter(mainPassFilter));
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], new NotFilter(mainPassFilter));
processOne(fileNames[i], filter);
}
} else {
// without --main-dex-list
FileNameFilter filter = new RemoveModuleInfoFilter(ClassPathOpener.acceptAll);
for (int i = 0; i < fileNames.length; i++) {
processOne(fileNames[i], ClassPathOpener.acceptAll);
processOne(fileNames[i], filter);
}
}
} catch (StopProcessing ex) {
Expand Down Expand Up @@ -1159,6 +1161,22 @@ public boolean accept(String path) {
}
}

/**
* Filters "module-info.class" out of the paths accepted by delegate.
*/
private static class RemoveModuleInfoFilter implements FileNameFilter {
protected final FileNameFilter delegate;

public RemoveModuleInfoFilter(FileNameFilter delegate) {
this.delegate = delegate;
}

@Override
public boolean accept(String path) {
return delegate.accept(path) && !("module-info.class".equals(path));
}
}

/**
* A quick and accurate filter for when file path can be trusted.
*/
Expand Down
2 changes: 1 addition & 1 deletion dx/tests/003-magic-version-access/class-version-51.0.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# classfile with the highest valid version 51.0 (0x33.0x00)
# classfile with the valid version 51.0 (0x33.0x00)
#

cafe babe # magic
Expand Down
3 changes: 1 addition & 2 deletions dx/tests/003-magic-version-access/class-version-51.1.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# classfile with a minor version 1 higher than the highest valid
# version. 51.0 (0x33.0x00)
# classfile with the valid version 51.1 (0x33.0x01)
#

cafe babe # magic
Expand Down
3 changes: 1 addition & 2 deletions dx/tests/003-magic-version-access/class-version-51.65535.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# classfile with an invalid version, with the same major version
# as the highest valid version. 51.65535 (0x33.0xffff)
# classfile with the valid version 51.65535 (0x33.0xffff)
#

cafe babe # magic
Expand Down
3 changes: 1 addition & 2 deletions dx/tests/003-magic-version-access/class-version-52.1.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# classfile with an invalid version, with a higher major version
# than the highest valid version. 52.1 (0x34.0x01)
# classfile with the valid version 52.1 (0x34.0x01)
#

cafe babe # magic
Expand Down
3 changes: 1 addition & 2 deletions dx/tests/003-magic-version-access/class-version-52.65535.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# classfile with an invalid version, with a higher major version
# than the highest valid version. 52.65535 (0x34.0xffff)
# classfile with the valid version 52.65535 (0x34.0xffff)
#

cafe babe # magic
Expand Down
3 changes: 1 addition & 2 deletions dx/tests/003-magic-version-access/class-version-53.0.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# classfile with an invalid version, with a higher major version
# than the highest valid version. 53.0 (0x35.0x00)
# classfile with the valid version 53.0 (0x35.0x00)
#

cafe babe # magic
Expand Down
26 changes: 26 additions & 0 deletions dx/tests/003-magic-version-access/class-version-53.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# classfile with an invalid version, with a higher minor version
# than the highest valid version. 53.1 (0x35.0x01)
#

cafe babe # magic
0001 # minor_version
0035 # major_version
0005 # constant_pool_count

#
# constant_pool
#
01 0005 "Small" # 0001: utf8["Small"]
01 0010 "java/lang/Object" # 0002: utf8["java/lang/Object"]
07 0001 # 0003: class[Small]
07 0002 # 0004: class[java/lang/Object]

ffff # access_flags
0003 # this_class
0004 # super_class
0000 # interfaces_count
0000 # fields_count
0000 # methods_count

0000 # attributes_count
26 changes: 26 additions & 0 deletions dx/tests/003-magic-version-access/class-version-53.65535.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# classfile with an invalid version, with the same major version
# as the highest valid version. 53.65535 (0x35.0xffff)
#

cafe babe # magic
ffff # minor_version
0035 # major_version
0005 # constant_pool_count

#
# constant_pool
#
01 0005 "Small" # 0001: utf8["Small"]
01 0010 "java/lang/Object" # 0002: utf8["java/lang/Object"]
07 0001 # 0003: class[Small]
07 0002 # 0004: class[java/lang/Object]

ffff # access_flags
0003 # this_class
0004 # super_class
0000 # interfaces_count
0000 # fields_count
0000 # methods_count

0000 # attributes_count
26 changes: 26 additions & 0 deletions dx/tests/003-magic-version-access/class-version-54.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# classfile with an invalid version, with a higher major version
# than the highest valid version. 54.0 (0x36.0x00)
#

cafe babe # magic
0000 # minor_version
0036 # major_version
0005 # constant_pool_count

#
# constant_pool
#
01 0005 "Small" # 0001: utf8["Small"]
01 0010 "java/lang/Object" # 0002: utf8["java/lang/Object"]
07 0001 # 0003: class[Small]
07 0002 # 0004: class[java/lang/Object]

ffff # access_flags
0003 # this_class
0004 # super_class
0000 # interfaces_count
0000 # fields_count
0000 # methods_count

0000 # attributes_count
79 changes: 71 additions & 8 deletions dx/tests/003-magic-version-access/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,91 @@ begin classfile
magic: cafebabe
minor_version: 0001
major_version: 0034
constant_pool_count: 0005

trouble parsing:
unsupported class file version 52.1
...while parsing class-version-52.1.txt
constant_pool:
0001: utf8{"Small"}
0002: utf8{"java/lang/Object"}
0003: type{Small}
0004: type{java.lang.Object}
end constant_pool
access_flags: public|final|super|interface|abstract|synthetic|annotation|enum|89ce
this_class: type{Small}
super_class: type{java.lang.Object}
interfaces_count: 0000
fields_count: 0000
methods_count: 0000
attributes_count: 0000
end classfile
reading class-version-52.65535.txt...
begin classfile
magic: cafebabe
minor_version: ffff
major_version: 0034
constant_pool_count: 0005

trouble parsing:
unsupported class file version 52.65535
...while parsing class-version-52.65535.txt
constant_pool:
0001: utf8{"Small"}
0002: utf8{"java/lang/Object"}
0003: type{Small}
0004: type{java.lang.Object}
end constant_pool
access_flags: public|final|super|interface|abstract|synthetic|annotation|enum|89ce
this_class: type{Small}
super_class: type{java.lang.Object}
interfaces_count: 0000
fields_count: 0000
methods_count: 0000
attributes_count: 0000
end classfile
reading class-version-53.0.txt...
begin classfile
magic: cafebabe
minor_version: 0000
major_version: 0035
constant_pool_count: 0005

constant_pool:
0001: utf8{"Small"}
0002: utf8{"java/lang/Object"}
0003: type{Small}
0004: type{java.lang.Object}
end constant_pool
access_flags: public|final|super|interface|abstract|synthetic|annotation|enum|89ce
this_class: type{Small}
super_class: type{java.lang.Object}
interfaces_count: 0000
fields_count: 0000
methods_count: 0000
attributes_count: 0000
end classfile
reading class-version-53.1.txt...
begin classfile
magic: cafebabe
minor_version: 0001
major_version: 0035

trouble parsing:
unsupported class file version 53.1
...while parsing class-version-53.1.txt
reading class-version-53.65535.txt...
begin classfile
magic: cafebabe
minor_version: ffff
major_version: 0035

trouble parsing:
unsupported class file version 53.65535
...while parsing class-version-53.65535.txt
reading class-version-54.0.txt...
begin classfile
magic: cafebabe
minor_version: 0000
major_version: 0036

trouble parsing:
unsupported class file version 53.0
...while parsing class-version-53.0.txt
unsupported class file version 54.0
...while parsing class-version-54.0.txt
reading small-class.txt...
begin classfile
magic: cafebabe
Expand Down
9 changes: 6 additions & 3 deletions dx/tests/003-magic-version-access/run
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ check_accepted class-version-50.65535.txt
check_accepted class-version-51.0.txt
check_accepted class-version-51.65535.txt
check_accepted class-version-52.0.txt
check_accepted class-version-52.1.txt
check_accepted class-version-52.65535.txt
check_accepted class-version-53.0.txt

# Too big (throws an exception)
check_rejected class-version-52.1.txt
check_rejected class-version-52.65535.txt
check_rejected class-version-53.0.txt
check_rejected class-version-53.1.txt
check_rejected class-version-53.65535.txt
check_rejected class-version-54.0.txt

# Show that we can dump the access flags even when they
# don't make any sense.
Expand Down

0 comments on commit ba2b8e2

Please sign in to comment.