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

[GitHub] flink pull request #2371: [FLINK-4309] Potential null pointer dereference in...

GitHub user tsunny opened a pull request:

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

    [FLINK-4309] Potential null pointer dereference in DelegatingCo\u2026

    Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
    If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the [How To Contribute guide](http://flink.apache.org/how-to-contribute.html).
    In addition to going through the list, please provide a meaningful description of your changes.
    
    - [ ] General
      - The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
      - The pull request addresses only one issue
      - Each commit in the PR has a meaningful commit message (including the JIRA id)
    
    - [ ] Documentation
      - Documentation has been added for new functionality
      - Old documentation affected by the pull request has been updated
      - JavaDoc for public methods has been added
    
    - [ ] Tests & Build
      - Functionality added by the pull request is covered by tests
      - `mvn clean verify` has been executed successfully locally or a Travis build has passed
    
    \u2026nfiguration#keySet()

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

    $ git pull https://github.com/tsunny/flink FLINK-4309

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

    https://github.com/apache/flink/pull/2371.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 #2371
    
----
commit 4de73e7c6a27fb854e43ea8a9e19b1b8a24b07bd
Author: Sunny T <su...@sunnys-macbook-pro-3.local>
Date:   2016-08-14T22:50:08Z

    [FLINK-4309] Fixed Potential null pointer dereference in DelegatingConfiguration#keySet()

----


---
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 issue #2371: [FLINK-4309] Potential null pointer dereference in Delega...

Posted by wuchong <gi...@git.apache.org>.
Github user wuchong commented on the issue:

    https://github.com/apache/flink/pull/2371
  
    LGTM +1


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74901158
  
    --- Diff: flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java ---
    @@ -56,6 +57,7 @@ public DelegatingConfiguration() {
     	 */
     	public DelegatingConfiguration(Configuration backingConfig, String prefix)
     	{
    +		Preconditions.checkNotNull(backingConfig);
     		this.backingConfig = backingConfig;
    --- End diff --
    
    Trivial note: We can also write `this.backingConfig = checkNotNull(backingConfig)` here.


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74893448
  
    --- Diff: flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java ---
    @@ -178,14 +178,19 @@ public String toString() {
     
     	@Override
     	public Set<String> keySet() {
    +
    --- End diff --
    
    We usually don't have an empty line when a method block starts (also applies to lines 185 and in `DelegatingConfigurationTest` lines 96 and 110).


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74893687
  
    --- Diff: flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java ---
    @@ -178,14 +178,19 @@ public String toString() {
     
     	@Override
     	public Set<String> keySet() {
    +
     		final HashSet<String> set = new HashSet<String>();
    -		final int prefixLen = this.prefix == null ? 0 : this.prefix.length();
     
     		for (String key : this.backingConfig.keySet()) {
    -			if (key.startsWith(this.prefix)) {
    +
    +			if (this.prefix == null) {
    --- End diff --
    
    Yes, we can use can use `addAll`


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74893573
  
    --- Diff: flink-core/src/test/java/org/apache/flink/configuration/DelegatingConfigurationTest.java ---
    @@ -88,4 +90,49 @@ private String typeParamToString(Class<?>[] classes) {
     			assertTrue("Foo method '" + configurationMethod.getName() + "' has not been wrapped correctly in DelegatingConfiguration wrapper", hasMethod);
     		}
     	}
    +	
    +	@Test
    +	public void testDelegationConfigurationWithNullPrefix() {
    +
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal("test-key", "value");
    +
    +		DelegatingConfiguration configuration = new DelegatingConfiguration(
    +				backingConf, null);
    +		Set<String> keySet = configuration.keySet();
    +
    +		assertEquals(keySet, backingConf.keySet());
    +
    +	}
    +
    +	@Test
    +	public void testDelegationConfigurationWithPrefix() {
    +
    +		String prefix = "pref-";
    +		String expectedKey = "key";
    +
    +		/*
    +		 * Key matches the prefix
    +		 */
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal(prefix + expectedKey, "value");
    +
    +		DelegatingConfiguration configuration = new DelegatingConfiguration(backingConf, prefix);
    +		Set<String> keySet = configuration.keySet();
    +		
    --- End diff --
    
    empty line


---
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 issue #2371: [FLINK-4309] Potential null pointer dereference in Delega...

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

    https://github.com/apache/flink/pull/2371
  
    Thanks for addressing our comments! I'm going to merge this later today.


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74724570
  
    --- Diff: flink-core/src/test/java/org/apache/flink/configuration/DelegatingConfigurationTest.java ---
    @@ -88,4 +90,49 @@ private String typeParamToString(Class<?>[] classes) {
     			assertTrue("Foo method '" + configurationMethod.getName() + "' has not been wrapped correctly in DelegatingConfiguration wrapper", hasMethod);
     		}
     	}
    +	
    +	@Test
    +	public void testDelegationConfigurationWithNullPrefix() {
    +
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal("test-key", "value");
    +
    +		DelegatingConfiguration configuration = new DelegatingConfiguration(
    +				backingConf, null);
    +		Set<String> keySet = configuration.keySet();
    +
    +		assertEquals(keySet, backingConf.keySet());
    +
    +	}
    +
    +	@Test
    +	public void testDelegationConfigurationWithPrefix() {
    +
    +		String prefix = "pref-";
    +
    +		/*
    +		 * Key matches the prefix
    +		 */
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal("pref-key", "value");
    --- End diff --
    
    I think `"pref-"` can be replaced by the `prefix` variable, just to make it consistent.


---
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 issue #2371: [FLINK-4309] Potential null pointer dereference in Delega...

Posted by tsunny <gi...@git.apache.org>.
Github user tsunny commented on the issue:

    https://github.com/apache/flink/pull/2371
  
    No problem. Happy to contribute. Thanks for the review comments.


---
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 issue #2371: [FLINK-4309] Potential null pointer dereference in Delega...

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

    https://github.com/apache/flink/pull/2371
  
    Changes look good all in all. Could you also add a `org.apache.flink.util.Preconditions.checkNotNull` check for the backing config in the constructor?


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

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


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74720168
  
    --- Diff: flink-core/src/test/java/org/apache/flink/configuration/DelegatingConfigurationTest.java ---
    @@ -88,4 +89,51 @@ private String typeParamToString(Class<?>[] classes) {
     			assertTrue("Foo method '" + configurationMethod.getName() + "' has not been wrapped correctly in DelegatingConfiguration wrapper", hasMethod);
     		}
     	}
    +	
    +	@Test
    +	public void testDelegationConfigurationWithNullPrefix() {
    +
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal("test-key", "value");
    +
    +		DelegatingConfiguration configuration = new DelegatingConfiguration(
    +				backingConf, null);
    +		Set<String> keySet = configuration.keySet();
    +
    +		assertTrue(keySet.equals(backingConf.keySet()));
    --- End diff --
    
    minor, it's better to use `assertEquals(keySet, backingConf.keySet())`  here I think. Below is the same


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74893388
  
    --- Diff: flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java ---
    @@ -178,14 +178,19 @@ public String toString() {
     
     	@Override
     	public Set<String> keySet() {
    +
     		final HashSet<String> set = new HashSet<String>();
    -		final int prefixLen = this.prefix == null ? 0 : this.prefix.length();
     
     		for (String key : this.backingConfig.keySet()) {
    -			if (key.startsWith(this.prefix)) {
    +
    +			if (this.prefix == null) {
    --- End diff --
    
    Can we move the condition out of the loop? The condition does not change over different iteration so we don't have to perform it every time.


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74893581
  
    --- Diff: flink-core/src/test/java/org/apache/flink/configuration/DelegatingConfigurationTest.java ---
    @@ -88,4 +90,49 @@ private String typeParamToString(Class<?>[] classes) {
     			assertTrue("Foo method '" + configurationMethod.getName() + "' has not been wrapped correctly in DelegatingConfiguration wrapper", hasMethod);
     		}
     	}
    +	
    +	@Test
    +	public void testDelegationConfigurationWithNullPrefix() {
    +
    +		Configuration backingConf = new Configuration();
    +		backingConf.setValueInternal("test-key", "value");
    +
    +		DelegatingConfiguration configuration = new DelegatingConfiguration(
    +				backingConf, null);
    +		Set<String> keySet = configuration.keySet();
    +
    +		assertEquals(keySet, backingConf.keySet());
    +
    --- End diff --
    
    empty line


---
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 #2371: [FLINK-4309] Potential null pointer dereference in...

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

    https://github.com/apache/flink/pull/2371#discussion_r74894098
  
    --- Diff: flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java ---
    @@ -178,14 +178,19 @@ public String toString() {
     
     	@Override
     	public Set<String> keySet() {
    +
     		final HashSet<String> set = new HashSet<String>();
    -		final int prefixLen = this.prefix == null ? 0 : this.prefix.length();
     
     		for (String key : this.backingConfig.keySet()) {
    -			if (key.startsWith(this.prefix)) {
    +
    +			if (this.prefix == null) {
    --- End diff --
    
    Actually, it's probably better to just return the keySet of the backing config.


---
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 issue #2371: [FLINK-4309] Potential null pointer dereference in Delega...

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

    https://github.com/apache/flink/pull/2371
  
    Thanks for your contribution @tsunny. Your changes look good. I only had a minor comment.


---
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.
---