Skip to content

Class#newInstance deprecation with Java 9#431

Closed
FSchumacher wants to merge 11 commits intoapache:trunkfrom
FSchumacher:newinstance-deprecation
Closed

Class#newInstance deprecation with Java 9#431
FSchumacher wants to merge 11 commits intoapache:trunkfrom
FSchumacher:newinstance-deprecation

Conversation

@FSchumacher
Copy link
Contributor

Description

Change invocation of Class#newInstance to Class#getConstructor#newInstance
And do some cleanup using StringUtils.isNotBlank

Motivation and Context

Java 9 deprecates Class#newInstance, so this will get rid of the deprecation warnings

How Has This Been Tested?

ran tests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

@pmouawad
Copy link
Contributor

Hello Felix,
I guess this is a first step before generalization ?
As I see other places in code where newInstance() is used.

Regards

@codecov-io
Copy link

Codecov Report

Merging #431 into trunk will increase coverage by <.01%.
The diff coverage is 4.16%.

Impacted file tree graph

@@             Coverage Diff             @@
##              trunk    #431      +/-   ##
===========================================
+ Coverage     58.59%   58.6%   +<.01%     
- Complexity    10633   10635       +2     
===========================================
  Files          1196    1196              
  Lines         76040   76039       -1     
  Branches       7357    7356       -1     
===========================================
+ Hits          44558   44564       +6     
+ Misses        28974   28969       -5     
+ Partials       2508    2506       -2
Impacted Files Coverage Δ Complexity Δ
...ore/org/apache/jmeter/gui/action/ActionRouter.java 6.61% <0%> (ø) 3 <0> (ø) ⬇️
...jmeter/gui/action/AddThinkTimeBetweenEachStep.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...jmeter/protocol/http/sampler/AccessLogSampler.java 7.69% <0%> (+0.07%) 3 <0> (ø) ⬇️
test/src/org/apache/jorphan/test/AllTests.java 81.25% <50%> (ø) 17 <0> (ø) ⬇️
...re/org/apache/jmeter/engine/DistributedRunner.java 85.71% <0%> (+3.36%) 32% <0%> (+1%) ⬆️
...s/org/apache/jmeter/timers/PoissonRandomTimer.java 78.37% <0%> (+5.4%) 10% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95361b1...b36e220. Read the comment docs.

@FSchumacher
Copy link
Contributor Author

Well, I don't know, if we can generalize it, but it is surely the first hits, only. There will be more, when I have slept a bit.

@jmetertea
Copy link
Contributor

jmetertea commented Nov 12, 2018

@FSchumacher
Copy link
Contributor Author

According to https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html
It should be replaced by
clazz.getDeclaredConstructor().newInstance()
see also https://stackoverflow.com/questions/53257073/java-9-replace-class-newinstance

Thanks for the info, I read the same article before I started and then made such a mess :) I prepared a new pull request #435 and will close this one.

@FSchumacher FSchumacher deleted the newinstance-deprecation branch November 27, 2018 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants