-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Sonarcube violations fixed. #1481
Sonarcube violations fixed. #1481
Conversation
ping @juherr |
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.
Few minor changes and some open points.
@@ -31,7 +32,7 @@ | |||
private static String[] testClassPaths; | |||
|
|||
/** The additional class loaders to find classes in. */ | |||
private static final List<ClassLoader> classLoaders = new Vector<>(); | |||
private static final Collection<ClassLoader> classLoaders = new ConcurrentLinkedDeque<>(); |
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.
Do we really need a concurrent collection? Why not just ArrayList?
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.
I am not sure about the intent behind having this collection as a concurrent one. The method that directly adds elements into this collection is org.testng.internal.PackageUtils#addClassLoader
and I don't see any direct invocations to this method from within TestNG. But that being said, I don't know if there are external customers (like the IntelliJ plugin or the surefire plugin or the eclipse plugin) which makes use of this method and how do they do it. If this method gets invoked from concurrent threads then there's a very good chance of triggering ConcurrentModificationException
(if an ArrayList
is used). That was why I was playing it safe by making use of a concurrent collection (In short adhering to the existing codebase, but just replacing Vector
with a concurrent collection.
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.
ok
|
||
} | ||
|
||
private static List<Class<?>> newList(Class<?>...elements) { |
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.
I'm not sure for that:
List<Class<?>> ctxTest = Arrays.asList(ITestContext.class, XmlTest.class);
mapping.put(Test.class.getSimpleName(), Collections.singletonList(ITestContext.class));
instead?
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.
This won't work because the Arrays.asList(ITestContext.class, XmlTest.class);
when invoked results in a List<Class<? extends Serializable>
(both ITestResult
and XmlTest
implement Serializable
) and so Java deduces this type. I tried this already and since it wasn't working is why I resorted to this approach.
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.
And what about
List<Class<?>> ctxTest = Arrays.<Class<?>>asList(ITestContext.class, XmlTest.class);
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.
@juherr... nice ! I never knew we could use Arrays.asList()
in that fashion wherein we specify explicitly the return type... (Guess its time for me to go back and read more about generics
). Yes, that would work. But now that brings me back to the question...
Apart from the succinctness (which is the only thing that stands obvious to my naive eyes), how is what you suggested different from what I have as an implementation in newList()
? I am curious. Can you please tell me ?
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 is totally debatable but I think we don't need a specific method to do a so simple thing which takes only 1 line.
* @param sb the file content | ||
*/ | ||
private static void writeFile(@Nullable File outDir, String fileName, String sb, @Nullable String encoding) { | ||
private static void writeFile(@Nullable File outputFolder, String filename, String sb, @Nullable String encoding) { | ||
File outDir = outputFolder; |
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.
I don't understand the value add of this rule.
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 general rule is that method parameters are not supposed to be altered within a method but they should instead be copied to a different variable and then operated upon.
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.
ok, but it's mostly a design issue somewhere or you need to find a better name for this attributes. Because variation on min/maj is error prone.
@@ -40,6 +40,8 @@ | |||
public static final String REPORTER_OUTPUT = "reporter-output.html"; | |||
public static final String METHODS_NOT_RUN = "methods-not-run.html"; | |||
public static final String TESTNG_XML = "testng.xml.html"; | |||
private static final String TD_A_TARGET_MAIN_FRAME_HREF = "<td><a target='mainFrame' href='"; | |||
private static final String TD = "</td>"; |
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.
maybe END_TD
or CLOSE_TD
instead
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.
Fixed.
Below violations were fixed: * Reorder modifiers to comply with JLS. * Convert field into local variable. * Remove usage of synchronized class Vector and replace with non-threadsafe/threadsafe alternative. * Remove un-used imports. * Remove redundant array creation when translating to List * Refactor map initialisation to a static block/constructor * Return empty array instead of null. * Use Integer.toString() instead of string concatenation. * Use %n instead of \n to produce platform-specific line separator
6e8ba80
to
a4a7562
Compare
@juherr - I fixed all the comments and pushed in the changes. Please let me know if this now good to be merged. |
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.
LGTM 👍
Ping @cbeust
Below violations were fixed:
Fixes # .
Did you remember to?
CHANGES.txt
We encourage pull requests that:
If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.