Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor (kubernetes-model-core) : Refactor IntOrString class to avoid invalid field combinations #3806

Merged
merged 1 commit into from
Feb 9, 2022

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Feb 7, 2022

Description

Right now IntOrString determines whether the wapper object contains an
integer or string by the value of integer field kind - 0 for integer
and 1 for string.

This field is exposed via setters so it's also possible that user can
mutate object to produce invalid combinations. For example:

IntOrString i1 = new IntOrString("23");
    
i1.setIntVal(32);
// Would print "23"
System.out.println(Serialization.jsonMapper().writeValueAsString(i1));

Refactor IntOrString class to remove these intVal,strVal,kind
fields and just rely on one Object field; use instanceOf to
distinguish whether enclosing object is integer or string.

We faced an issue due to this behavior in
eclipse-jkube/jkube#1126

Signed-off-by: Rohan Kumar rohaan@redhat.com

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@rohanKanojia rohanKanojia marked this pull request as ready for review February 7, 2022 08:34
StrVal = strVal;
this.additionalProperties = additionalProperties;
}
private transient Object value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this transient? If serialized using Java Serialization it will be ignored (which renders the class useless).

…d invalid field combinations

Right now IntOrString determines whether the wapper object contains an
integer or string by the value of integer field `kind` - `0` for integer
and `1` for string.

This field is exposed via setters so it's also possible that user can
mutate object to produce invalid combinations. For example:
```
IntOrString i1 = new IntOrString("23");

i1.setIntVal(32);
// Would print "23"
System.out.println(Serialization.jsonMapper().writeValueAsString(i1));
```

Refactor IntOrString class to remove these `intVal`,`strVal`,`kind`
fields and just rely on one `Object` field; use `instanceOf` to
distinguish whether enclosing object is integer or string.

We faced an issue due to this behavior in
eclipse-jkube/jkube#1126

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@rohanKanojia rohanKanojia changed the title refactor (kubernetes-model-core) : Remove field setters from IntOrString to avoid invalid field combinations refactor (kubernetes-model-core) : Refactor IntOrString class to avoid invalid field combinations Feb 9, 2022
@sonarcloud
Copy link

sonarcloud bot commented Feb 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

90.0% 90.0% Coverage
0.0% 0.0% Duplication

@rohanKanojia rohanKanojia removed the wip label Feb 9, 2022
@manusa manusa merged commit 33eccf5 into fabric8io:master Feb 9, 2022
@manusa manusa mentioned this pull request Apr 21, 2022
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants