@@ -728,11 +728,14 @@ static private class KlassMap {
728728 */
729729 final public OriginalAndTransformedString sourceName ;
730730 final public HashMap <Integer , Location > lineMap ;
731+ private final ClassObjectReference objRef ;
731732
732733 @ SuppressWarnings ("unused" )
733734 final public ReferenceType refType ;
734735
735736 private KlassMap (Config config , ReferenceType refType ) throws AbsentInformationException {
737+ objRef = refType .classObject ();
738+
736739 String sourceName = refType .sourceName ();
737740 var lineMap = new HashMap <Integer , Location >();
738741
@@ -869,10 +872,34 @@ private IBreakpoint[] __internal__bindBreakpoints(String serverAbsPath, BpLineAn
869872
870873 clearExistingBreakpoints (serverAbsPath );
871874
875+ List <KlassMap > garbageCollectedKlassMaps = new ArrayList <>();
876+
872877 for (KlassMap mapping : klassMapSet ) {
873- bpListPerMapping = __internal__idempotentBindBreakpoints (mapping , lineInfo );
878+ if (mapping .objRef .isCollected ()) {
879+ // This still leaves us with a little race where it gets collected after this,
880+ // but before we start adding breakpoints to the gc'd class.
881+ garbageCollectedKlassMaps .add (mapping );
882+ continue ;
883+ }
884+
885+ try {
886+ bpListPerMapping = __internal__idempotentBindBreakpoints (mapping , lineInfo );
887+ }
888+ catch (ObjectCollectedException e ) {
889+ garbageCollectedKlassMaps .add (mapping );
890+ }
874891 }
875892
893+ garbageCollectedKlassMaps .forEach (klassMap -> {
894+ Set <ReplayableCfBreakpointRequest > z = replayableBreakpointRequestsByAbsPath_ .get (klassMap .sourceName .transformed );
895+ if (z != null ) {
896+ // TODO: stronger types WRT "transformed" and "non-transformed" paths, they shouldn't both be String they should be some distinct wrapper type
897+ z .removeIf (bpReq -> bpReq .serverAbsPath .equals (klassMap .sourceName .transformed ));
898+ }
899+
900+ klassMapSet .remove (klassMap );
901+ });
902+
876903 // return just the last one
877904 return bpListPerMapping ;
878905 }
0 commit comments