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
Fix issue S1130 Exceptions in 'throws' clauses should not be superfluous #9073
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -612,7 +612,7 @@ public static String getCookie(HttpServletRequest req, String name, String defau | |
private static final Pattern ICON_SIZE = Pattern.compile("\\d+x\\d+"); | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static String validateIconSize(String iconSize) throws SecurityException { | ||
public static String validateIconSize(String iconSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Effective Java 3rd Edition §74 says:
This PR removes the |
||
if (!ICON_SIZE.matcher(iconSize).matches()) { | ||
throw new SecurityException("invalid iconSize"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ public boolean hasMoreElements() { | |
} | ||
|
||
@Override | ||
public T nextElement() throws NoSuchElementException { | ||
public T nextElement() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creates an unused import for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for identifying this problem, we'll be looking very quickly at how to ensure that 'Indepth' doesn't reproduce this issue again. |
||
return cur.nextElement(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -818,7 +818,7 @@ public interface JenkinsHolder { | |
* @since 2.98 | ||
*/ | ||
@NonNull | ||
public static Jenkins get() throws IllegalStateException { | ||
public static Jenkins get() { | ||
Jenkins instance = getInstanceOrNull(); | ||
if (instance == null) { | ||
throw new IllegalStateException("Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong."); | ||
|
@@ -832,7 +832,7 @@ public static Jenkins get() throws IllegalStateException { | |
*/ | ||
@Deprecated | ||
@NonNull | ||
public static Jenkins getActiveInstance() throws IllegalStateException { | ||
public static Jenkins getActiveInstance() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Effective Java 3rd Edition §74 says:
This PR removes the |
||
return get(); | ||
} | ||
|
||
|
@@ -2514,7 +2514,7 @@ public String getUrlChildPrefix() { | |
* @since 1.66 | ||
* @see <a href="https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML">Hyperlinks in HTML</a> | ||
*/ | ||
public @Nullable String getRootUrl() throws IllegalStateException { | ||
public @Nullable String getRootUrl() { | ||
final JenkinsLocationConfiguration config = JenkinsLocationConfiguration.get(); | ||
String url = config.getUrl(); | ||
if (url != null) { | ||
|
@@ -3042,7 +3042,7 @@ public InitMilestone getInitLevel() { | |
* @throws IOException Failed to save the configuration | ||
* @throws IllegalArgumentException Negative value has been passed | ||
*/ | ||
public void setNumExecutors(/* @javax.annotation.Nonnegative*/ int n) throws IOException, IllegalArgumentException { | ||
public void setNumExecutors(/* @javax.annotation.Nonnegative*/ int n) throws IOException { | ||
if (n < 0) { | ||
throw new IllegalArgumentException("Incorrect field \"# of executors\": " + n + ". It should be a non-negative number."); | ||
} | ||
|
@@ -3282,15 +3282,15 @@ public void onDeleted(TopLevelItem item) throws IOException { | |
return true; | ||
} | ||
|
||
@Override public synchronized <I extends TopLevelItem> I add(I item, String name) throws IOException, IllegalArgumentException { | ||
@Override public synchronized <I extends TopLevelItem> I add(I item, String name) throws IOException { | ||
if (items.containsKey(name)) { | ||
throw new IllegalArgumentException("already an item '" + name + "'"); | ||
} | ||
items.put(name, item); | ||
return item; | ||
} | ||
|
||
@Override public void remove(TopLevelItem item) throws IOException, IllegalArgumentException { | ||
@Override public void remove(TopLevelItem item) throws IOException { | ||
items.remove(item.getName()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -592,7 +592,7 @@ public synchronized int maxNumberOnDisk() { | |
return numberOnDisk.max(); | ||
} | ||
|
||
protected final synchronized void proposeNewNumber(int number) throws IllegalStateException { | ||
protected final synchronized void proposeNewNumber(int number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Effective Java 3rd Edition §74 says:
This PR removes the |
||
if (number <= maxNumberOnDisk()) { | ||
throw new IllegalStateException("JENKINS-27530: cannot create a build with number " + number + " since that (or higher) is already in use among " + numberOnDisk); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effective Java 3rd Edition §74 says:
This PR removes the
throws
keyword on this unchecked exception (good), but it does not add the Javadoc@throws
tag (bad).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dilemma is either to keep the existing code which returns unchecked exceptions or to validate the PR which fixes this case but does not declare the exception unchecked. Another solution would be to make these corrections manually. According to Sonar's estimate, it would take around 5 hours of work to remediate the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a dilemma for me, as I simply won't approve this PR unless the changes I requested are made. According to my estimate, it would take around 15 minutes of work to make the requested changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a suggestion for improvement that you are free to reject. Would you like me to close the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a net improvement if it trades one problem for another. I see no reason for this PR to be closed once the requested changes are made.