ContentTypeDetector should recognize future versions of Java class files #952
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.
Each time new version of bytecode comes out, we have following inconsistency between processing of classes by agent and processing of files:
offline instrumentation and report generation skip class file
which is IMO misleading and error-prone,
whereas on-the-fly instrumentation fails
This happens because
ContentTypeDetector
has strict version checkand used by
Instrumenter.instrumentAll
andAnalyzer.analyzeAll
,but not by
Instrumenter.instrument
andAnalyzer.analyzeClass
.This check was introduced in 73ae850 to distinguish class files from Mach-O fat/universal binaries, because both have
0xCAFEBABE
magic header.To resolve above inconsistencies, simplify
ContentTypeDetector
and to avoid constant need to update it when new bytecode version comes out, I propose to relax check by just checking that unsigned 2 bytes number at position of major version is greater or equal to45
(0x2D
, Java 1.0 - 1.1).For distinction from Mach-O this will be as good as current check: header of fat binary contains unsigned 4 bytes for number of architectures at a same place and in a same big-endian order where class file contains unsigned 2 bytes for minor and 2 bytes for major version, so both theoretically can be
46
and both will pass current check, however unlikely to see on practice single executable with such number of architectures.