Skip to content

Remove deprecated Integer constructor usage.#8391

Merged
mbien merged 5 commits intoapache:masterfrom
mbien:integer-constructors
Apr 8, 2025
Merged

Remove deprecated Integer constructor usage.#8391
mbien merged 5 commits intoapache:masterfrom
mbien:integer-constructors

Conversation

@mbien
Copy link
Member

@mbien mbien commented Apr 3, 2025

The feared Integer PR - this should hopefully be the last one in the chain.

part of #8257

@mbien mbien added Code cleanup Label for cleanup done on the Netbeans IDE ci:all-tests [ci] enable all tests ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Apr 3, 2025
Comment on lines -29 to +30
Integer ADDED_CHILD = new Integer(0);
Integer REMOVED_CHILD = new Integer(1);
Integer ADDED_CHILD = 0;
Integer REMOVED_CHILD = 1;
Copy link
Member Author

@mbien mbien Apr 3, 2025

Choose a reason for hiding this comment

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

switched all usages which compared with == to equals

usages in FolderObj and ChildrenSupportTest, no public API.

Comment on lines +137 to +149
public static final Object YES_OPTION = new Integer(JOptionPane.YES_OPTION);
public static final Object YES_OPTION = JOptionPane.YES_OPTION;

/** Return value if NO is chosen. */
public static final Object NO_OPTION = new Integer(JOptionPane.NO_OPTION);
public static final Object NO_OPTION = JOptionPane.NO_OPTION;

/** Return value if CANCEL is chosen. */
public static final Object CANCEL_OPTION = new Integer(JOptionPane.CANCEL_OPTION);
public static final Object CANCEL_OPTION = JOptionPane.CANCEL_OPTION;

/** Return value if OK is chosen. */
public static final Object OK_OPTION = new Integer(JOptionPane.OK_OPTION);
public static final Object OK_OPTION = JOptionPane.OK_OPTION;

/** Return value if user closes the window without pressing any button. */
public static final Object CLOSED_OPTION = new Integer(JOptionPane.CLOSED_OPTION);
public static final Object CLOSED_OPTION = JOptionPane.CLOSED_OPTION;
Copy link
Member Author

@mbien mbien Apr 3, 2025

Choose a reason for hiding this comment

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

i think this should be ok unless someone relied on the fact that YES_OPTION != OK_OPTION object identity wise (it has the same int value).

Considered making everything new Object but this would cause problems if someone would compare the values. BigInteger would work as last resort.

edit: this won't work

@mbien mbien removed the ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) label Apr 3, 2025
@mbien mbien force-pushed the integer-constructors branch from 3dd5b3c to 838983f Compare April 3, 2025 14:48
@mbien mbien added Platform [ci] enable platform tests (platform/*) and removed ci:all-tests [ci] enable all tests labels Apr 3, 2025
@mbien mbien force-pushed the integer-constructors branch from ef742fc to 7635ea1 Compare April 3, 2025 18:37
@mbien mbien added ci:all-tests [ci] enable all tests ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Apr 3, 2025
@mbien mbien force-pushed the integer-constructors branch from 7635ea1 to b53c321 Compare April 3, 2025 19:57
@mbien mbien marked this pull request as ready for review April 3, 2025 19:58
@mbien mbien added this to the NB26 milestone Apr 4, 2025
@mbien mbien force-pushed the integer-constructors branch from b53c321 to b1ebec8 Compare April 4, 2025 08:22
Comment on lines +97 to +103
public static final Object ADD_SPLITTER = new Integer(0);
public static final Object ADD_SPLITTER = new Object();

/** constraints constant for adding a component to the first (left/top) pane */
public static final Object ADD_FIRST = new Integer(1);
public static final Object ADD_FIRST = new Object();

/** constraints constant for adding a component to the second (right/bottom) pane */
public static final Object ADD_SECOND = new Integer(2);
public static final Object ADD_SECOND = new Object();
Copy link
Member Author

Choose a reason for hiding this comment

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

this panel is public unfortunately, but unused and deprecated. This should be still compatible unless someone casts down to Integer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could have kept 0, 1, and, 2...

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I think so. Not sure why I didn't. Will change it.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated it

*/
public static final String PROP_INFO_NOTIFICATION = "infoNotification"; // NOI18N

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this worth doing at all? The only advantage over simple auto boxing is to have unique Object instances for each option.

Do we really need that? Also it could break comparisons like ret.equals(0).

Object YES_OPTION = JOptionPane.YES_OPTION;

would make more sense.

Copy link
Member Author

@mbien mbien Apr 7, 2025

Choose a reason for hiding this comment

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

this doesn't work since two options (JOptionPane.YES_OPTION and JOptionPane.OK_OPTION) would have the same int value which would return the same Integer instance due to the vlaueOf() cache (also used by auto boxing). Two return options with the same identity would be an incompatible change. This fails several tests across NB (already tried with #8391 (comment)).

Also it could break comparisons like ret.equals(0)

this is hopefully unlikely since the return type is Object not Integer. It being an Integer is an implementation detail but not in the doc.

Copy link
Member Author

Choose a reason for hiding this comment

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

moved the NotifyDescriptor changes to a separate PR #8407

Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

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

Looks good save the last commit, where things got over-engineered.

@mbien
Copy link
Member Author

mbien commented Apr 8, 2025

extracted the NotifyDescriptor changes to a separate PR (including unit test to visualize the problem), linked from PR text

@mbien mbien requested a review from lkishalmi April 8, 2025 14:26
Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

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

LGTM.

@mbien
Copy link
Member Author

mbien commented Apr 8, 2025

thanks for review, will merge after looking through it for the last time.

Comment on lines +31 to +42
<ResourceString bundle="org/netbeans/modules/web/project/ui/wizards/Bundle.properties" key="LBL_NWP1_ProjectName_LabelMnemonic" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
<ResourceString bundle="" key="LBL_NWP1_ProjectName_LabelMnemonic" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

this example broke since the package was changed without updating the bundle path most likely. Will fix it.

@mbien mbien force-pushed the integer-constructors branch from 47275af to 5496ae9 Compare April 8, 2025 19:15
@mbien mbien removed the ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) label Apr 8, 2025
@mbien mbien merged commit a19ec46 into apache:master Apr 8, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all-tests [ci] enable all tests Code cleanup Label for cleanup done on the Netbeans IDE Platform [ci] enable platform tests (platform/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants