3636import org .objectweb .asm .MethodVisitor ;
3737import org .objectweb .asm .Opcodes ;
3838import org .objectweb .asm .Type ;
39+ import org .slf4j .Logger ;
40+ import org .slf4j .LoggerFactory ;
3941
4042import com .google .common .collect .Multimap ;
4143import com .synopsys .method .analyzer .core .model .MethodUse ;
@@ -120,6 +122,9 @@ private static String formatQualifiedName(String internalName) {
120122 */
121123 private static class MethodReferenceVisitor extends MethodVisitor {
122124
125+ /** Logger reference to output information to the application log files */
126+ private final Logger logger = LoggerFactory .getLogger (getClass ());
127+
123128 private final MethodReferenceRegistry referenceRegistry ;
124129
125130 private final String currentClassName ;
@@ -194,8 +199,8 @@ private void register(String owner, String name, String descriptor) {
194199 // Treat all arrays as "object", instead of a unique array "class"
195200 String effectiveOwner = (owner .startsWith ("[" ) ? "java/lang/Object" : owner );
196201
197- Type returnType = Type . getReturnType (descriptor );
198- Type [] arguments = Type . getArgumentTypes (descriptor );
202+ Type returnType = getReturnType (descriptor );
203+ Type [] arguments = getArgumentTypes (descriptor );
199204
200205 List <String > argumentList = Stream .of (arguments )
201206 .map (Type ::getClassName )
@@ -206,6 +211,38 @@ private void register(String owner, String name, String descriptor) {
206211 referenceRegistry .registerReference (formatQualifiedName (effectiveOwner ), name , argumentList , returnType .getClassName (), useReference , currentLine );
207212 }
208213
214+ private Type getReturnType (String descriptor ) {
215+ try {
216+ return Type .getReturnType (descriptor );
217+ } catch (StringIndexOutOfBoundsException e ) {
218+ // IDETECT-3909 This can occur for malformed signatures which are just the type, not the method, for an
219+ // unknown reason
220+ logger .warn ("Malformed method descriptor, attempting type-only processing: {}:{} ({})" , currentClassName , currentMethodName , descriptor );
221+
222+ try {
223+ return Type .getType (descriptor );
224+ } catch (StringIndexOutOfBoundsException e2 ) {
225+ // IDETECT-3909 This can occur for malformed signatures which are just the type, not the method, for
226+ // an unknown reason
227+ logger .warn ("Malformed method descriptor, skipping reference processing: {}:{} ({})" , currentClassName , currentMethodName , descriptor );
228+
229+ return Type .getType (descriptor );
230+ }
231+ }
232+ }
233+
234+ private Type [] getArgumentTypes (String descriptor ) {
235+ try {
236+ return Type .getArgumentTypes (descriptor );
237+ } catch (StringIndexOutOfBoundsException e ) {
238+ // IDETECT-3909 This can occur for malformed signatures which are just the type, not the method, for an
239+ // unknown reason
240+ logger .warn ("Malformed method descriptor, skipping arguments: {}:{} ({})" , currentClassName , currentMethodName , descriptor );
241+
242+ return new Type [] {};
243+ }
244+ }
245+
209246 }
210247
211248}
0 commit comments