pharo icon indicating copy to clipboard operation
pharo copied to clipboard

Handle invlid interval case in extract method

Open balsa-sarenac opened this issue 9 months ago • 1 comments

This method can fail when extractionInterval is invalid:

ReCompositeExtractMethodRefactoring >> getExtractedSource
	| source |
	source := class sourceCodeFor: selector.
	source ifNil: [ self refactoringError: 'Invalid source' ].
	((extractionInterval first between: 1 and: (self startLimit: source size))
		and: [extractionInterval last between: 1 and: source size])
			ifFalse: [self refactoringError: 'Invalid interval'].
	^source copyFrom: extractionInterval first to: extractionInterval last

fix:

ReCompositeExtractMethodRefactoring >> getExtractedSource
	| source |
	source := class sourceCodeFor: selector.
	source ifNil: [ self refactoringError: 'Invalid source' ].
	((extractionInterval first between: 1 and: (self startLimit: source size))
		and: [extractionInterval last between: 1 and: source size])
			ifFalse: [self refactoringError: 'Invalid interval'].
	(extractionInterval first > extractionInterval last)
		ifTrue: [ self refactoringError: 'Invalid interval' ].
	^source copyFrom: extractionInterval first to: extractionInterval last

balsa-sarenac avatar May 12 '25 12:05 balsa-sarenac

Tx balsa.

Ducasse avatar May 13 '25 13:05 Ducasse