This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 01fe94f  fix enterprise cluster build on JDK 17 + add upstream-JDK 
build job.
     new 50fb68f  Merge pull request #3764 from mbien/build-on-jdk17
01fe94f is described below

commit 01fe94faf11d94cc4bf6f545bb97be54ddb087e3
Author: Michael Bien <mbie...@gmail.com>
AuthorDate: Fri Mar 11 15:53:57 2022 +0100

    fix enterprise cluster build on JDK 17 + add upstream-JDK build job.
---
 .github/workflows/linux-upstream-jdk.yml           | 56 ++++++++++++++++++++++
 .../modules/schema2beansdev/gen/JavaUtil.java      | 18 +++++--
 2 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/linux-upstream-jdk.yml 
b/.github/workflows/linux-upstream-jdk.yml
new file mode 100644
index 0000000..142c884
--- /dev/null
+++ b/.github/workflows/linux-upstream-jdk.yml
@@ -0,0 +1,56 @@
+# 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.
+
+name: Apache Netbeans
+
+on:
+  push:
+  pull_request:
+
+# job is intended for early detection of build failures on new JDKs
+jobs:
+  linux:
+    name: Check Build on Linux/JDK17
+    runs-on: ubuntu-latest
+    env:
+      ANT_OPTS: 
-Dmetabuild.jsonurl=https://raw.githubusercontent.com/apache/netbeans-jenkins-lib/master/meta/netbeansrelease.json
+
+    steps:
+
+      - name: Set up JDK 17
+        uses: actions/setup-java@v2
+        with:
+            distribution: 'zulu'
+            java-version: 17
+
+      - name: Checkout
+        uses: actions/checkout@v2
+
+      - name: Caching dependencies
+        uses: actions/cache@v2
+        with:
+          path: ~/.hgexternalcache
+          key: ${{ runner.os }}-${{ hashFiles('*/external/binaries-list', 
'*/*/external/binaries-list') }}
+          restore-keys: ${{ runner.os }}-
+
+      - name: Clean
+        run: ant -Dcluster.config=full clean
+
+      - name: Build (cluster.config=full)
+        run: ant -Dcluster.config=full build
+
+# todo: figure out if anything is testable post JDK 15
diff --git 
a/ide/schema2beans/src/org/netbeans/modules/schema2beansdev/gen/JavaUtil.java 
b/ide/schema2beans/src/org/netbeans/modules/schema2beansdev/gen/JavaUtil.java
index 6b176c4..6934834 100644
--- 
a/ide/schema2beans/src/org/netbeans/modules/schema2beansdev/gen/JavaUtil.java
+++ 
b/ide/schema2beans/src/org/netbeans/modules/schema2beansdev/gen/JavaUtil.java
@@ -835,6 +835,7 @@ public class JavaUtil {
         return cls.getName();
     }
 
+    @Deprecated
     public static int getOptimialHashMapSize(Object[] keys) {
         return getOptimialHashMapSize(keys, keys.length * 8);
     }
@@ -847,12 +848,13 @@ public class JavaUtil {
      *
      * @param maxSize the point at which to give up (the maximum size to try)
      */
+    @Deprecated
     public static int getOptimialHashMapSize(Object[] keys, int maxSize) {
         int keyLength = keys.length;
-        int defaultAnswer = keyLength + 1;
+        int defaultAnswer = keyLength * 3 / 2;
         try {
             java.lang.reflect.Field tableField = 
HashMap.class.getDeclaredField("table");
-            tableField.setAccessible(true);
+            tableField.setAccessible(true); // requires --add-opens for util 
package
             for (int tableSize = keyLength + 1; tableSize <= maxSize;
                  tableSize <<= 1) {
                 //System.out.println("tableSize="+tableSize);
@@ -874,10 +876,16 @@ public class JavaUtil {
                 }
                 return table.length;
             }
-        } catch (java.lang.IllegalAccessException e) {
-            return defaultAnswer;
-        } catch (java.lang.NoSuchFieldException e) {
+        } catch (IllegalAccessException | NoSuchFieldException e) {
             return defaultAnswer;
+        } catch (RuntimeException ex) {
+            // todo: remove this workaround post JDK 9+ migration (or entire 
method)
+            // modules on modern JDKs should prefere immutable collections 
anyway, e.g Map.of();
+            if 
(ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException"))
 {
+                return defaultAnswer;
+            } else {
+                throw ex;
+            }
         }
         return defaultAnswer;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to