You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/10/10 16:30:22 UTC

[isis] branch v2 updated: ISIS-2158: fixes OpenJDK-11 cross compilation issue

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

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/v2 by this push:
     new 5122c33  ISIS-2158: fixes OpenJDK-11 cross compilation issue
5122c33 is described below

commit 5122c3330584f2d6fa60febd7c78cca0ae5b8fe6
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Oct 10 18:30:12 2019 +0200

    ISIS-2158: fixes OpenJDK-11 cross compilation issue
---
 .../isis/commons/internal/assertions/_Ensure.java  | 29 ++++++++++++--------
 .../Ensure_GivenValueThatDoesMatchTest.java        |  4 +--
 .../Ensure_GivenValueThatDoesNotMatchTest.java     |  2 +-
 .../isis/metamodel/adapter/oid/Oid_Marshaller.java |  1 +
 .../org/apache/isis/metamodel/consent/Veto.java    |  7 +++--
 .../isis/metamodel/facetapi/FacetAbstract.java     | 31 +++++++++++++---------
 ...ctAdapterContext_ObjectAdapterByIdProvider.java |  2 +-
 7 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/assertions/_Ensure.java b/core/commons/src/main/java/org/apache/isis/commons/internal/assertions/_Ensure.java
index ad213aa..a249d18 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/assertions/_Ensure.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/assertions/_Ensure.java
@@ -19,8 +19,8 @@
 
 package org.apache.isis.commons.internal.assertions;
 
+import java.util.function.Function;
 import java.util.function.Predicate;
-import java.util.function.Supplier;
 
 import static org.apache.isis.commons.internal.base._With.requires;
 
@@ -49,23 +49,30 @@ public final class _Ensure {
      *
      * @throws IllegalArgumentException
      *             if predicate tests to false.
+     * @deprecated might break build on OpenJDK-11 (or cross compilation builds in general)
      */
-    public static <T> T ensureThatArg(final T arg, final Predicate<? super T> predicate, final String message) {
+    @Deprecated
+    public static <T> T ensureThatArg(
+            final T arg, 
+            final Predicate<? super T> predicate, 
+            final Function<T, String> messageFunction) {
+        
         requires(predicate, "predicate");
         if (!predicate.test(arg)) {
-            throw new IllegalArgumentException(message);
+            requires(messageFunction, "messageFunction");
+            throw new IllegalArgumentException(messageFunction.apply(arg));
         }
         return arg;
     }
 
-    public static <T> T ensureThatArg(final T arg, final Predicate<? super T> predicate, final Supplier<String> messageSupplier) {
-        requires(predicate, "predicate");
-        if (!predicate.test(arg)) {
-            requires(messageSupplier, "messageSupplier");
-            throw new IllegalArgumentException(messageSupplier.get());
-        }
-        return arg;
-    }
+//    public static <T> T ensureThatArg(final T arg, final Predicate<T> predicate, final Supplier<String> messageSupplier) {
+//        requires(predicate, "predicate");
+//        if (!predicate.test(arg)) {
+//            requires(messageSupplier, "messageSupplier");
+//            throw new IllegalArgumentException(messageSupplier.get());
+//        }
+//        return arg;
+//    }
 
     /**
      * To ensure that the current state of this object (instance fields) is
diff --git a/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesMatchTest.java b/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesMatchTest.java
index e0b9963..4892ef2 100644
--- a/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesMatchTest.java
+++ b/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesMatchTest.java
@@ -32,14 +32,14 @@ public class Ensure_GivenValueThatDoesMatchTest {
     @Test
     public void whenCallEnsureThatArgThenShouldReturnOriginalObject() {
         final String object = "foo";
-        final String returnedObject = _Ensure.ensureThatArg(object, is(not(nullValue(String.class)))::matches, ()->"some message");
+        final String returnedObject = _Ensure.ensureThatArg(object, is(not(nullValue(String.class)))::matches, $->String.format("some message %s", $));
         assertThat(returnedObject, sameInstance(object));
     }
 
     @Test
     public void whenCallEnsureThatArgWithOverloadedShouldReturnOriginalObject() {
         final String object = "foo";
-        final String returnedObject = _Ensure.ensureThatArg(object, is(not(nullValue(String.class)))::matches, "some message");
+        final String returnedObject = _Ensure.ensureThatArg(object, is(not(nullValue(String.class)))::matches, $->"some message");
         assertThat(returnedObject, sameInstance(object));
     }
 
diff --git a/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesNotMatchTest.java b/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesNotMatchTest.java
index aee59fe..a95648f 100644
--- a/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesNotMatchTest.java
+++ b/core/commons/src/test/java/org/apache/isis/commons/internal/assertions/Ensure_GivenValueThatDoesNotMatchTest.java
@@ -31,7 +31,7 @@ public class Ensure_GivenValueThatDoesNotMatchTest {
     @Test
     public void whenCallEnsureThatArgOverloadedShouldThrowIllegalArgumentExceptionUsingSuppliedMessage() {
         try {
-            _Ensure.ensureThatArg("foo", is(nullValue())::matches, "my message");
+            _Ensure.ensureThatArg("foo", is(nullValue())::matches, $->"my message");
             fail();
         } catch (final IllegalArgumentException ex) {
             assertThat(ex.getMessage(), is("my message"));
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/adapter/oid/Oid_Marshaller.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/adapter/oid/Oid_Marshaller.java
index 894ec2f..1fe1f01 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/adapter/oid/Oid_Marshaller.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/adapter/oid/Oid_Marshaller.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.commons.internal.assertions._Assert;
 import org.apache.isis.commons.internal.assertions._Ensure;
 import org.apache.isis.commons.internal.base._Casts;
 import org.apache.isis.commons.internal.base._Strings;
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/consent/Veto.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/consent/Veto.java
index 20ce9cd..feee12a 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/consent/Veto.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/consent/Veto.java
@@ -19,10 +19,9 @@
 
 package org.apache.isis.metamodel.consent;
 
-import org.apache.isis.commons.internal.base._Strings;
 import org.apache.isis.metamodel.facetapi.Facet;
 
-import static org.apache.isis.commons.internal.assertions._Ensure.ensureThatArg;
+import static org.apache.isis.commons.internal.base._With.requiresNotEmpty;
 
 public class Veto extends ConsentAbstract {
 
@@ -36,10 +35,10 @@ public class Veto extends ConsentAbstract {
      * viewers.
      *
      * @param reasonVeteod
-     *            - must not be <tt>null</tt>
+     *            - must not be empty or <tt>null</tt>
      */
     public Veto(final String reasonVetoed) {
-        super(null, ensureThatArg(reasonVetoed, _Strings::isNotEmpty, "requires a non empty string"));
+        super(null, requiresNotEmpty(reasonVetoed, "reasonVetoed")); 
     }
 
     public Veto(final InteractionResult interactionResult) {
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facetapi/FacetAbstract.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facetapi/FacetAbstract.java
index 87a04f3..6867b8b 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facetapi/FacetAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facetapi/FacetAbstract.java
@@ -21,13 +21,14 @@ package org.apache.isis.metamodel.facetapi;
 
 import java.util.Map;
 import java.util.Objects;
-import java.util.stream.Stream;
 
-import org.apache.isis.commons.internal.assertions._Ensure;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
 import org.apache.isis.metamodel.MetaModelContext;
 
 import static org.apache.isis.commons.internal.base._With.requires;
 
+import lombok.val;
+
 
 public abstract class FacetAbstract implements Facet, MetaModelContext.Delegating {
 
@@ -93,16 +94,22 @@ public abstract class FacetAbstract implements Facet, MetaModelContext.Delegatin
     public void setUnderlyingFacet(final Facet underlyingFacet) {
         if(underlyingFacet != null) {
             if(underlyingFacet instanceof MultiTypedFacet) {
-                final MultiTypedFacet multiTypedFacet = (MultiTypedFacet) underlyingFacet;
-                final boolean matches = compatible(multiTypedFacet);
+                val multiTypedFacet = (MultiTypedFacet) underlyingFacet;
+                val matches = compatible(multiTypedFacet);
                 if(!matches) {
                     throw new IllegalArgumentException("illegal argument, expected underlying facet (a multi-valued facet) to have equivalent to the facet type (or facet types) of this facet");
                 }
             } else {
-                _Ensure.ensureThatArg(
-                        underlyingFacet.facetType(), 
-                        type->Objects.equals(type, facetType), 
-                        ()->String.format("type-missmatch: underlying facet's type '%s' must match this facet's type '%s'"));
+                
+                val underlyingFacetType = underlyingFacet.facetType();
+                if(!Objects.equals(underlyingFacetType, facetType)) {
+                    val msg = String.format(
+                            "type-missmatch: underlying facet's type '%s' "
+                            + "must match this facet's type '%s'", 
+                            underlyingFacetType, facetType);
+                    throw _Exceptions.unrecoverable(msg);
+                }
+ 
             }
         }
         this.underlyingFacet = underlyingFacet;
@@ -114,10 +121,10 @@ public abstract class FacetAbstract implements Facet, MetaModelContext.Delegatin
             return multiTypedFacet.containsFacetTypeOf(this.facetType);
         }
 
-        final MultiTypedFacet thisAsMultiTyped = (MultiTypedFacet) this;
-        final Stream<Class<? extends Facet>> facetTypes = thisAsMultiTyped.facetTypes();
-        return facetTypes
-                .anyMatch(facetType->multiTypedFacet.containsFacetTypeOf(facetType));
+        val thisAsMultiTyped = (MultiTypedFacet) this;
+        
+        return thisAsMultiTyped.facetTypes()
+                .anyMatch(thisAsMultiTyped::containsFacetTypeOf);
     }
 
     /**
diff --git a/core/runtime/src/main/java/org/apache/isis/runtime/system/persistence/adaptermanager/ObjectAdapterContext_ObjectAdapterByIdProvider.java b/core/runtime/src/main/java/org/apache/isis/runtime/system/persistence/adaptermanager/ObjectAdapterContext_ObjectAdapterByIdProvider.java
index d3177cc..67a38d6 100644
--- a/core/runtime/src/main/java/org/apache/isis/runtime/system/persistence/adaptermanager/ObjectAdapterContext_ObjectAdapterByIdProvider.java
+++ b/core/runtime/src/main/java/org/apache/isis/runtime/system/persistence/adaptermanager/ObjectAdapterContext_ObjectAdapterByIdProvider.java
@@ -211,7 +211,7 @@ class ObjectAdapterContext_ObjectAdapterByIdProvider implements ObjectAdapterByI
             pojo = objectAdapterContext.instantiateAndInjectServices(spec);
         }
 
-        _Ensure.ensure("unlikely", !(pojo instanceof Oid));
+        _Ensure.ensure("Pojo most likely should not be an Oid", !(pojo instanceof Oid));
 
         return pojo;
     }