User description
Motivation and Context
There were several places where some deprecated method calls were being used (some for internal project code, others for libraries). Where possible and obvious, I've replaced this code with the non-deprecated methods.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Refactoring (no changes to public API)
Checklist
- [x] I have read the contributing document.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed. (tested with
bazel test //java/... --test_size_filters=small)
PR Type
Enhancement, Bug fix, Tests
Description
-
Replaced deprecated newInstance with getDeclaredConstructor().newInstance for reflection-based object creation.
-
Updated SlowLoadableComponent constructors to use Duration.ofSeconds for timeout values.
-
Migrated from MockitoAnnotations.initMocks to MockitoAnnotations.openMocks in test setup methods.
-
Improved type safety in assertions using InstanceOfAssertFactories in tests.
Changes walkthrough 📝
| Relevant files |
|---|
| Enhancement | 7 files
DescribedOption.javaReplace deprecated newInstance with
getDeclaredConstructor().newInstance |
+3/-2 |
Types.javaUpdate GraphQL coercing methods to include additional parameters |
+10/-6 |
TerseFormatter.javaMake `levelNumberToCommonsLevelName` method static |
+1/-1 |
LocalNodeFactory.javaReplace deprecated newInstance with
getDeclaredConstructor().newInstance |
+3/-2 |
WebDriverDecorator.javaReplace deprecated newInstance with
getDeclaredConstructor().newInstance |
+1/-1 |
AjaxElementLocator.javaUse `Duration.ofSeconds` for timeout in `SlowLoadableComponent` |
+3/-2 |
SlowLoadableComponentTest.javaUse `Duration.ofSeconds` for timeout in `SlowLoadableComponent` |
+4/-4 |
|
| Tests | 6 files
RemoteLogsTest.javaReplace `initMocks` with `openMocks` in test setup |
+1/-1 |
TracedCommandExecutorTest.javaReplace `initMocks` with `openMocks` in test setup |
+1/-1 |
ExpectedConditionsTest.javaReplace `initMocks` with `openMocks` in test setup |
+1/-1 |
FluentWaitTest.javaReplace `initMocks` with `openMocks` in test setup |
+1/-1 |
WebDriverWaitTest.javaReplace `initMocks` with `openMocks` in test setup |
+1/-1 |
VirtualAuthenticatorTest.javaImprove type safety in assertions using `InstanceOfAssertFactories` |
+2/-1 |
|
Need help?
Type /help how to ... in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.
All committers have signed the CLA.
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for review
Reflection Error Handling
The updated code now catches additional exceptions (InvocationTargetException and NoSuchMethodException), but the error message doesn't reflect these new exception types, still referring only to field access and instantiation issues.
Object fieldInstance = field.get(clazz.getDeclaredConstructor().newInstance());
fieldValue = fieldInstance == null ? "" : fieldInstance.toString();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ignore) {
// We'll swallow this exception since we are just trying to get field's default value
Method Signature Changes
The method signatures have been updated to match the new GraphQL API, but there's no verification that the new parameters (graphQLContext, locale) are properly used in the method implementations.
public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) throws CoercingSerializeException {
if (o instanceof String) {
return (String) o;
}
if (o instanceof URL || o instanceof URI) {
return String.valueOf(o);
}
throw new CoercingSerializeException("Unable to coerce " + o);
}
@Override
public URI parseValue(Object input, GraphQLContext graphQLContext, Locale locale) throws CoercingParseValueException {
if (input == null) {
return null;
}
if (input instanceof URI) {
return (URI) input;
}
try {
if (input instanceof String) {
return new URI((String) input);
}
if (input instanceof URL) {
return ((URL) input).toURI();
}
} catch (URISyntaxException e) {
throw new CoercingParseValueException("Unable to create URI: " + input, e);
}
throw new CoercingParseValueException("Unable to create URI: " + input);
}
@Override
public URI parseLiteral(Value<?> input, CoercedVariables variables, GraphQLContext graphQLContext, Locale locale) throws CoercingParseLiteralException {
if (!(input instanceof StringValue)) {
throw new CoercingParseLiteralException("Cannot convert to URL: " + input);
}
try {
return new URI(((StringValue) input).getValue());
} catch (URISyntaxException e) {
throw new CoercingParseLiteralException("Unable to parse: " + input);
}
}
})
.build();
}
private static GraphQLScalarType urlType() {
return GraphQLScalarType.newScalar()
.name("Url")
.coercing(
new Coercing<URL, String>() {
@Override
public String serialize(Object o, GraphQLContext graphQLContext, Locale locale) throws CoercingSerializeException {
if (o instanceof String) {
return (String) o;
}
if (o instanceof URL || o instanceof URI) {
return String.valueOf(o);
}
throw new CoercingSerializeException("Unable to coerce " + o);
}
@Override
public URL parseValue(Object input, GraphQLContext graphQLContext, Locale locale) throws CoercingParseValueException {
if (input == null) {
return null;
}
if (input instanceof URL) {
return (URL) input;
}
try {
if (input instanceof String) {
return new URL((String) input);
}
if (input instanceof URI) {
return ((URI) input).toURL();
}
} catch (MalformedURLException e) {
throw new CoercingParseValueException("Unable to create URL: " + input, e);
}
throw new CoercingParseValueException("Unable to create URL: " + input);
}
@Override
public URL parseLiteral(Value<?> input, CoercedVariables variables, GraphQLContext graphQLContext, Locale locale) throws CoercingParseLiteralException {
if (!(input instanceof StringValue)) {
throw new CoercingParseLiteralException("Cannot convert to URL: " + input);
}
|
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| General |
Reduce excessive timeout value
The value 1000L seconds is extremely high for a timeout in a test. This could lead to very long test execution times if there's an issue. Consider using a more reasonable timeout value.
java/src/org/openqa/selenium/support/ui/SlowLoadableComponentTest.java [151]
public HasError() {
- super(new TickingClock(), Duration.ofSeconds(1000L));
+ super(new TickingClock(), Duration.ofSeconds(10L));
}
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies an excessively high timeout value (1000 seconds) in a test class, which could lead to very long test execution times if there's an issue. Reducing it to 10 seconds is a reasonable improvement that maintains test functionality while preventing unnecessarily long test runs.
| Medium
|
- [ ] Update <!-- /improve_multi --more_suggestions=true -->
| |