Skip to content

Commit

Permalink
fix some pmd warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenartur committed Aug 25, 2024
1 parent 7b89c83 commit 21db447
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To try out some tools and create build strategy sample.

To build including war file that contains update site use

mvn -Dinclude=web -Pjacoco verify
`mvn -Dinclude=web -Pjacoco verify`

The product can be found in "sandbox_product/target" and the war file in "sandbox_web/target".

Expand Down Expand Up @@ -69,45 +69,45 @@ Code based on Java 17 starting with 2022-12, Java 11 up to 2022-06

Everything is work in progress unless explicitly noted

1) sandbox_cleanup_application

Only placeholder for what should start a cleanup as commandline application similar to the codeformatting wrapper

eclipse -nosplash -consolelog -debug -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config MyCodingStandards.ini MyClassToBeFormatted.java

see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75333

2) sandbox_encoding_quickfix

Partly implementation what should help to make usage of platform encoding visible by change of api use.
See https://openjdk.java.net/jeps/400 for affected api when *not* specifying default encoding.

3) sandbox_extra_search

Partly implementation of what should offer a curated search for interesting classes that have to be taken into account
when updating a java code base to newer eclipse and java version.

4) sandbox_usage_view

Table view that lists all objects in the code and sorts it by name. That should help to find uses of the similar variable name for
what in fact is refering to the same object. Sometimes in an old code base you find deviations like camelcase or not, underscores and other small changes.
These changes are able to confuse a developer

5) sandbox_platform_helper

Poc for quickfix to change code according to new possibilities in
https://www.eclipse.org/eclipse/news/4.20/platform_isv.php#simpler-status-creation.

6) sandbox_tools

While to ForLoop Converter
Already merged into Eclipse jdt

7) sandbox_functional_converter

Iterator to functional loop converter
https://github.com/carstenartur/sandbox/wiki/Functional-Converter
Or see netbeans to learn how it works
1. sandbox_cleanup_application
Only placeholder for what should start a cleanup as commandline application similar to the codeformatting wrapper
eclipse -nosplash -consolelog -debug -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config MyCodingStandards.ini MyClassToBeFormatted.java
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75333
2. sandbox_encoding_quickfix
Partly implementation what should help to make usage of platform encoding visible by change of api use.
See https://openjdk.java.net/jeps/400 for affected api when *not* specifying default encoding.
3. sandbox_extra_search
Partly implementation of what should offer a curated search for interesting classes that have to be taken into account
when updating a java code base to newer eclipse and java version.
4. sandbox_usage_view
Table view that lists all objects in the code and sorts it by name. That should help to find uses of the similar variable name for
what in fact is refering to the same object. Sometimes in an old code base you find deviations like camelcase or not, underscores and other small changes.
These changes are able to confuse a developer
5. sandbox_platform_helper
Poc for quickfix to change code according to new possibilities in
https://www.eclipse.org/eclipse/news/4.20/platform_isv.php#simpler-status-creation.
6. sandbox_tools
While to ForLoop Converter
Already merged into Eclipse jdt
7. sandbox_functional_converter
Iterator to functional loop converter
https://github.com/carstenartur/sandbox/wiki/Functional-Converter
Or see netbeans to learn how it works

# Installation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ private static CodeFormatter createCodeFormatter(Map options, int mode) {
return formatter;
}
} catch (CoreException e) {
org.eclipse.jdt.internal.core.util.Util.log(e.getStatus());
Util.log(e.getStatus());
break;
}
}
}
}
}
org.eclipse.jdt.internal.core.util.Util.log(IStatus.WARNING,
Util.log(IStatus.WARNING,
"Unable to instantiate formatter extension '" + formatterId + "', returning built-in formatter."); //$NON-NLS-1$ //$NON-NLS-2$
}
return new DefaultCodeFormatter(currentOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ public Boolean containsContinue() {
}
public static class VariablesVisitor extends GenericVisitor {

public VariablesVisitor() {
// TODO Auto-generated constructor stub
}

public Set getInnervariables() {
// TODO Auto-generated method stub
return null;

Check failure on line 104 in sandbox_functional_converter/src/org/sandbox/jdt/internal/corext/fix/helper/PreconditionsChecker.java

View workflow job for this annotation

GitHub Actions / pmd-code-scan

Return an empty collection rather than null.

For any method that returns an collection (such as an array, Collection or Map), it is better to return an empty one rather than a null reference. This removes the need for null checking all results and avoids inadvertent NullPointerExceptions. See Effective Java, 3rd Edition, Item 54: Return empty collections or arrays instead of null ReturnEmptyCollectionRatherThanNull (Priority: 1, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.4.0/pmd_rules_java_errorprone.html#returnemptycollectionratherthannull
Expand Down

0 comments on commit 21db447

Please sign in to comment.