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

Removed compilation warnings #110

Closed
wants to merge 7 commits into from
Closed

Removed compilation warnings #110

wants to merge 7 commits into from

Conversation

chsxf
Copy link

@chsxf chsxf commented Dec 12, 2014

I have updated the code to removed several compilation warnings.

@stleary
Copy link
Owner

stleary commented Mar 16, 2015

Hi Christophe,
Sorry for not responding sooner.

  • One of your changed files, Zipper.java, is no longer part of the project and should not be included in this pull request.
  • In JSONObject.java and Property.java, I am not sure that the annotation @SuppressWarnings("unchecked") is advisable to add to the code. Can you explain why you think this is the best solution?
    Thanks, Sean

@chsxf
Copy link
Author

chsxf commented Mar 17, 2015

Thanks for your answer @stleary.
I've updated my branch to reflex recent deletions in the repository.

Concerning the @SuppressWarnings part, I've added it to remove the warnings I get when Object are casted to something else, resulting in unchecked cast.

Eventually, I can provide another commit ignoring only the specific cast lines.

@stleary
Copy link
Owner

stleary commented Mar 18, 2015

I think SupressWarnings and unchecked casts are equally annoying. I note that the problem lines are all casts to generics, e.g.

    return new JSONObject((Map<String, Object>) value).toString();

What would you think about something like,

    return new JSONObject((Map<?, ?>) value).toString();

[Note: I am not going to be able to commit any changes until the unit test suite is completed, which will take a little while. But it would be good to get rid of the warnings in a safe way. Let me know what you think.]

@chsxf
Copy link
Author

chsxf commented Mar 21, 2015

Thank you for the tip. I've pushed a new commit using <?> and no warning anymore.
I think we're good now.

@stleary
Copy link
Owner

stleary commented Mar 21, 2015

Thanks! As mentioned earlier, I need to hold off on commits until the unit tests are done. If you wish to contribute, the repository is: https://github.com/stleary/JSON-Java-unit-test.

@stleary
Copy link
Owner

stleary commented May 3, 2015

Thanks for the pull request. I think removing warnings is advisable if there is 100% certainty that the code is not affected. My bad for suggesting Map and Collection<?>. That invokes the JSONObject(Object) and JSONArray(Object) ctors, and incidentally breaks the unit tests. To summarize:

  • Properties.java change should be OK. properties.propertyNames() returns an Enumeration<? extends Object>.
  • JSONObject casts to Class should be OK. object.getClass() returns a Class<? extends Object>.
  • All other casts need to have @SuppressWarnings restored, but not at function level. Instead, please try something like this to limit the scope to just the line where the cast occurs:
  •         } else if (value instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) value;
                new JSONObject(map).write(writer, indentFactor, indent);
            }
    

@chsxf
Copy link
Author

chsxf commented May 3, 2015

I've restored "local" @SuppressWarnings for the specific lines. Now we should be OK.

@stleary
Copy link
Owner

stleary commented May 4, 2015

Looks good. Leaving it up for a day or so in case of additional comments. Will have to hand merge, looks like there is a formatting issue in JSONObject.

@chsxf
Copy link
Author

chsxf commented May 4, 2015

The formatting issue should be fixed now, allowing you to automerge.

stleary added a commit that referenced this pull request May 6, 2015
@stleary
Copy link
Owner

stleary commented May 6, 2015

Thanks, merged on a separate branch.

@stleary stleary closed this May 6, 2015
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.

2 participants