You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by StephanEwen <gi...@git.apache.org> on 2016/04/05 15:30:10 UTC

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

GitHub user StephanEwen opened a pull request:

    https://github.com/apache/flink/pull/1853

    [FLINK-3700] [core] Add 'Preconditions' utility class.

    The functionality that Flink uses from Guava is super simple and limited.
    We get a big dependency that has caused a lot of pain in the past, simply to get access to some simple utility methods. This has cause us quite a bit of pain in the past, because of Guava version conflicts and the necessary dependency shading.
    
    In order to reduce the dependency on Guava, this adds a simple Flink Preconditions class.
    
    While referencing well established libraries is a good idea for standalone apps, it is a problem for frameworks like Flink, if the dependencies are not well-behaved with respect to version compatibility. Guava is not well behaved in that sense.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/StephanEwen/incubator-flink flink_preconditions

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/1853.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1853
    
----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1853#discussion_r59518788
  
    --- Diff: flink-core/src/main/java/org/apache/flink/util/Preconditions.java ---
    @@ -0,0 +1,213 @@
    +/*
    + * 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.
    + */
    +
    +// ----------------------------------------------------------------------------
    +//  This class is largely adapted from "com.google.common.base.Preconditions",
    +//  which is part of the "Guava" library.
    +//
    +//  Because of frequent issues with dependency conflicts, this class was
    +//  added to the Flink code base to reduce dependency on Guava.
    +// ----------------------------------------------------------------------------
    +
    +package org.apache.flink.util;
    +
    +import org.apache.flink.annotation.Internal;
    +
    +import javax.annotation.Nullable;
    +
    +/**
    + * A collection of static utility methods to validate input.
    + * 
    + * <p>This class is modelled after Google Guava's Preconditions class, and partly takes code
    + * from that class. We add this code to the Flink code base in order to reduce external
    + * dependencies.
    + */
    +@Internal
    +public final class Preconditions {
    +
    +	// ------------------------------------------------------------------------
    +	//  Null checks
    +	// ------------------------------------------------------------------------
    +	
    +	/**
    +	 * Ensures that the given object reference is not null.
    +	 * Upon violation, a {@code NullPointerException} with no message is thrown.
    +	 * 
    +	 * @param reference The object reference
    +	 * @return The object reference itself (generically typed).
    +	 * 
    +	 * @throws NullPointerException Thrown, if the passed reference was null.
    +	 */
    +	public static <T> T checkNotNull(T reference) {
    --- End diff --
    
    True, I have been using that quite a bit. There are, however, a few signatures missing (like message with placeholders and var-arg parameters) as well as separate functions like `checkArgument` and `checkState`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by uce <gi...@git.apache.org>.
Github user uce commented on the pull request:

    https://github.com/apache/flink/pull/1853#issuecomment-206299884
  
    +1.
    
    I know of some other places where I've used Guava's Hasher or Cache, which we can also remove in order to be able to remove our Guava dependency.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by ZackPierce <gi...@git.apache.org>.
Github user ZackPierce commented on a diff in the pull request:

    https://github.com/apache/flink/pull/1853#discussion_r59289246
  
    --- Diff: flink-core/src/main/java/org/apache/flink/util/Preconditions.java ---
    @@ -0,0 +1,213 @@
    +/*
    + * 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.
    + */
    +
    +// ----------------------------------------------------------------------------
    +//  This class is largely adapted from "com.google.common.base.Preconditions",
    +//  which is part of the "Guava" library.
    +//
    +//  Because of frequent issues with dependency conflicts, this class was
    +//  added to the Flink code base to reduce dependency on Guava.
    +// ----------------------------------------------------------------------------
    +
    +package org.apache.flink.util;
    +
    +import org.apache.flink.annotation.Internal;
    +
    +import javax.annotation.Nullable;
    +
    +/**
    + * A collection of static utility methods to validate input.
    + * 
    + * <p>This class is modelled after Google Guava's Preconditions class, and partly takes code
    + * from that class. We add this code to the Flink code base in order to reduce external
    + * dependencies.
    + */
    +@Internal
    +public final class Preconditions {
    +
    +	// ------------------------------------------------------------------------
    +	//  Null checks
    +	// ------------------------------------------------------------------------
    +	
    +	/**
    +	 * Ensures that the given object reference is not null.
    +	 * Upon violation, a {@code NullPointerException} with no message is thrown.
    +	 * 
    +	 * @param reference The object reference
    +	 * @return The object reference itself (generically typed).
    +	 * 
    +	 * @throws NullPointerException Thrown, if the passed reference was null.
    +	 */
    +	public static <T> T checkNotNull(T reference) {
    --- End diff --
    
    For what it is worth, `Objects.requireNonNull` has overloads with the same signature (as this and the next method down), and is [present in the JDK since 1.7](https://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull(T)). 
    
    Using `requireNonNull` instead may help reduce the burden of semi-standard code that Flink reimplements.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen closed the pull request at:

    https://github.com/apache/flink/pull/1853


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by tillrohrmann <gi...@git.apache.org>.
Github user tillrohrmann commented on the pull request:

    https://github.com/apache/flink/pull/1853#issuecomment-205811166
  
    +1 for merging :-)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on the pull request:

    https://github.com/apache/flink/pull/1853#issuecomment-208312455
  
    Merging this...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-3700] [core] Add 'Preconditions' utilit...

Posted by StephanEwen <gi...@git.apache.org>.
Github user StephanEwen commented on the pull request:

    https://github.com/apache/flink/pull/1853#issuecomment-209507866
  
    Manually merged in 885d543be8a8c0d1acdffa0003e394347d5376ef


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---