ctubbsii commented on code in PR #2552:
URL: https://github.com/apache/thrift/pull/2552#discussion_r850791222
##########
lib/java/src/org/apache/thrift/meta_data/FieldMetaData.java:
##########
@@ -68,21 +64,24 @@ public static void addStructMetaDataMap(Class<? extends
TBase> sClass, Map<? ext
* {@link FieldMetaData#addStructMetaDataMap(Class, Map)} from
a different
* thread during static initialization of the Thrift class is
possible.
*/
- public static Map<? extends TFieldIdEnum, FieldMetaData>
getStructMetaDataMap(
- Class<? extends TBase> sClass) {
+ public static <T extends TBase<T, F>, F extends TFieldIdEnum> Map<F,
FieldMetaData> getStructMetaDataMap(
+ Class<T> sClass) {
// Note: Do not use synchronized on this method declaration - it leads to
a deadlock.
// Similarly, do not trigger sClass.newInstance() while holding a lock on
structMap,
// it will lead to the same deadlock.
// See: https://issues.apache.org/jira/browse/THRIFT-5430 for details.
- if (!structMap.containsKey(sClass)){ // Load class if it hasn't been loaded
- try{
- sClass.newInstance();
- } catch (InstantiationException e){
+ if (!structMap.containsKey(sClass)) { // Load class if it hasn't been
loaded
+ try {
+ sClass.getDeclaredConstructor().newInstance();
+ } catch (InstantiationException e) {
throw new RuntimeException("InstantiationException for TBase class: "
+ sClass.getName() + ", message: " + e.getMessage());
- } catch (IllegalAccessException e){
+ } catch (IllegalAccessException e) {
throw new RuntimeException("IllegalAccessException for TBase class: "
+ sClass.getName() + ", message: " + e.getMessage());
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("ReflectiveOperationException for TBase
class: " + sClass.getName() + ", message: " + e.getMessage());
Review Comment:
```suggestion
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e.getClass().getSimpleName() + " for
TBase class: " + sClass.getName()", e);
```
This can set the cause, so you don't need to serialize the message of the
cause inside this exception's message. Also, both of the above exceptions are
instances of ReflectiveOperationException, so they can be deleted in favor of
just this one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]