diff options
author | Evgeny Mandrikov <Godin@users.noreply.github.com> | 2016-08-16 04:06:56 +0200 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2016-08-16 04:06:56 +0200 |
commit | 28a112ca6c6f46cd385f00aa932ec0e334e045a7 (patch) | |
tree | 9d92399e1a2e797a87d560e49fc092e0017a113d /org.jacoco.core.test/src/org/jacoco/core/test/validation | |
parent | c6f2b6b7e887eb645b8aba928ff0134cfe66ec28 (diff) | |
download | platform_external_jacoco-28a112ca6c6f46cd385f00aa932ec0e334e045a7.tar.gz platform_external_jacoco-28a112ca6c6f46cd385f00aa932ec0e334e045a7.tar.bz2 platform_external_jacoco-28a112ca6c6f46cd385f00aa932ec0e334e045a7.zip |
Do not violate JVMS regarding initialization of final fields (#434)
Without this change instrumented classes can't pass checks
and cause IllegalAccessError starting from OpenJDK 9 EA b127
(see https://bugs.openjdk.java.net/browse/JDK-8157181).
Diffstat (limited to 'org.jacoco.core.test/src/org/jacoco/core/test/validation')
3 files changed, 147 insertions, 0 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleClassTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleClassTest.java new file mode 100644 index 00000000..47820e68 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleClassTest.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation; + +import org.jacoco.core.analysis.ICounter; +import org.jacoco.core.test.validation.targets.BadCycleClass; +import org.junit.Test; + +/** + * Test of "bad cycles" with classes. + */ +public class BadCycleClassTest extends BadCycleTestBase { + + public BadCycleClassTest() throws Exception { + super(BadCycleClass.class); + } + + @Test + public void test() throws Exception { + loader.loadClass(BadCycleClass.Child.class.getName()).newInstance(); + + analyze(BadCycleClass.Child.class); + assertLine("1", ICounter.FULLY_COVERED); + assertLine("2", ICounter.FULLY_COVERED); + assertLine("3", ICounter.FULLY_COVERED); + } + +} diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleTestBase.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleTestBase.java new file mode 100644 index 00000000..dd7b4992 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/BadCycleTestBase.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.Collection; + +import org.jacoco.core.analysis.Analyzer; +import org.jacoco.core.analysis.CoverageBuilder; +import org.jacoco.core.analysis.IClassCoverage; +import org.jacoco.core.analysis.ISourceFileCoverage; +import org.jacoco.core.data.ExecutionDataStore; +import org.jacoco.core.test.InstrumentingLoader; + +class BadCycleTestBase extends ValidationTestBase { + + protected final InstrumentingLoader loader = new InstrumentingLoader(); + + BadCycleTestBase(final Class<?> target) throws Exception { + super(target); + } + + BadCycleTestBase(final String srcFolder, final Class<?> target) + throws Exception { + super(srcFolder, target); + } + + @Override + public final void setup() throws Exception { + // nop + } + + @Override + protected final void run(Class<?> targetClass) throws Exception { + // nop + } + + final void analyze(Class<?> cls) throws IOException { + final byte[] bytes = loader.getClassBytes(cls.getName()); + final ExecutionDataStore store = loader.collect(); + + final CoverageBuilder builder = new CoverageBuilder(); + final Analyzer analyzer = new Analyzer(store, builder); + analyzer.analyzeClass(bytes, "TestTarget"); + final Collection<IClassCoverage> classes = builder.getClasses(); + assertEquals(1, classes.size(), 0.0); + classCoverage = classes.iterator().next(); + final Collection<ISourceFileCoverage> files = builder.getSourceFiles(); + assertEquals(1, files.size(), 0.0); + sourceCoverage = files.iterator().next(); + + source = Source.getSourceFor(srcFolder, target); + } + +} diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/BadCycleClass.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/BadCycleClass.java new file mode 100644 index 00000000..44e40cd1 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/BadCycleClass.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.targets; + +public class BadCycleClass { + + public static class Base { + static final Child b = new Child(); + + static { + b.someMethod(); + } + } + + public static class Child extends Base { + + static { + Stubs.nop("child clinit"); // $line-3$ + } + + public Child() { + Stubs.nop("child init"); // $line-1$ + } + + void someMethod() { + Stubs.nop("child someMethod"); // $line-2$ + } + + } + + public static void main(String[] args) { + new Child(); + } + +} |