groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 02/02: Allow illegal access scenarios to be tested using -Pgroovy.force.illegal.access=true property.
Date Thu, 18 Apr 2019 03:09:48 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 53345dc58a368c63e166d0a8a1daae61fa6dcaf0
Author: Paul King <paulk@asert.com.au>
AuthorDate: Thu Apr 18 13:09:10 2019 +1000

    Allow illegal access scenarios to be tested using -Pgroovy.force.illegal.access=true property.
    
    This doesn't affect the groovy runtime/compiler, it is just a system property which decides
    whether the tests will be run or not. We will try to have the build as warning free as
possible
    but still want the ability to test any still supported functionality which generates warnings.
    We may evolve this approach over time.
---
 gradle/test.gradle                                |  2 ++
 src/test/groovy/IllegalAccessScenariosTest.groovy | 39 +++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gradle/test.gradle b/gradle/test.gradle
index a2dae8a..d121b37 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -20,9 +20,11 @@ allprojects {
     tasks.withType(Test) {
         def jdk8 = ['-XX:+UseConcMarkSweepGC']
         def jdk9 = ['-Djava.locale.providers=COMPAT,SPI']
+//        def jdk9 = ['-Djava.locale.providers=COMPAT,SPI', '--illegal-access=debug']
         def common = ['-ea', "-Xms${groovyJUnit_ms}", "-Xmx${groovyJUnit_mx}", "-Duser.language=en"
]
         if (JavaVersion.current().isJava9Compatible()) {
             jvmArgs (*common, *jdk9)
+            systemProperty "groovy.force.illegal.access", findProperty("groovy.force.illegal.access")
         } else if (JavaVersion.current().isJava8Compatible()) {
             jvmArgs (*common, *jdk8)
         } else {
diff --git a/src/test/groovy/IllegalAccessScenariosTest.groovy b/src/test/groovy/IllegalAccessScenariosTest.groovy
new file mode 100644
index 0000000..44096b0
--- /dev/null
+++ b/src/test/groovy/IllegalAccessScenariosTest.groovy
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy
+
+import static groovy.test.GroovyAssert.isAtLeastJdk
+import static org.apache.groovy.util.SystemUtil.getBooleanSafe
+
+/**
+ * Tests for permissive member access. Typically such access is only allowed in Java via
means such
+ * as reflection.
+ *
+ * In JDK versions < 9, Groovy supports permissive access and no warnings are given by
the JDK.
+ * In JDK versions >= 9, Groovy supports permissive access but the JDK gives illegal access
warnings.
+ * At some point, the JDK may further restrict permissive access and Groovy's support for
this feature may be limited.
+ */
+class IllegalAccessScenariosTest extends GroovyTestCase {
+    void testPrivateFieldAccess() {
+        if (isAtLeastJdk('9.0') && !getBooleanSafe('groovy.force.illegal.access'))
return
+        def items = [1, 2, 3]
+        // size is a private field in ArrayList
+        assert items.size == 3
+    }
+} 


Mime
View raw message