jbellis / jamm

Java Agent for Memory Measurements
Apache License 2.0
684 stars 125 forks source link

Exception on JVM version 10+46 #30

Closed mariswa closed 1 year ago

mariswa commented 6 years ago

Hey! Just installed JDK 10 build 10+46 and MemoryLayoutSpecification throws an exception

_> -- StackTrace --

java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 5 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3107) at java.base/java.lang.String.substring(String.java:1873) at org.github.jamm.MemoryLayoutSpecification.getEffectiveMemoryLayoutSpecification(MemoryLayoutSpecification.jav a:190) at org.github.jamm.MemoryLayoutSpecification.(MemoryLayoutSpecification.java:31) ..._

I suppose most probably it caused by version parsing code:

final String strSpecVersion = System.getProperty("java.specification.version");
        final boolean hasDot = strSpecVersion.indexOf('.') != -1;
        if (hasDot) {
            if ("1".equals(strSpecVersion.substring(0, strSpecVersion.indexOf('.')))) {
                // Java 1.6, 1.7, 1.8
                final String strVmVersion = System.getProperty("java.vm.version");
                final int vmVersion = Integer.parseInt(strVmVersion.substring(0, strVmVersion.indexOf('.')));
                modernJvm = vmVersion >= 17;
            }
        }

specifically by final int vmVersion = Integer.parseInt(strVmVersion.substring(0, strVmVersion.indexOf('.'))); when taking index of "." w\o any check

mebigfatguy commented 6 years ago

the version string is just "10" or "10+46"? Do you know what it is for jdk 9?

doesn't the 'hasDot' guard prevent you from entering that code?

mebigfatguy commented 6 years ago

What version are you running, as the line number 190 seems off from the HEAD revision

mariswa commented 6 years ago

Yep, have to install 9.0.4 and it works well now

Regards Marina

On Apr 11, 2018, at 9:13 PM, Dave Brosius notifications@github.com wrote:

the version string is just "10" i take it? Do you know what it is for jdk 9?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

mariswa commented 6 years ago

On latest 2 versions of community edition (3.5 and 3.6 i think) its the same. I also was wondering why line 190 seems it doesn't look exactly the line for vm version parsing but based on exception details it looks like that

Regards Marina

On Apr 11, 2018, at 9:18 PM, Dave Brosius notifications@github.com wrote:

What version are you running, as the line number 190 seems off from the HEAD revision

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

blerer commented 1 year ago

The new code should not suffer from that problem any more.