@Override
	public Position offsetToPosition(int charOffset, Bias bias) {
		// Covering out-of-bounds offset cases, which otherwise crash in the base impl.
		if (charOffset <= 0)
			return position(0, 0);
		else if (charOffset >= getLength()) {
			int paragraph = getParagraphs().size() - 1;
			return position(paragraph, getParagraphLength(paragraph));
		}

		return super.offsetToPosition(charOffset, bias);
	}
Code area with additional parameter checks for some common edge cases.

@author Matt Coley
recaf-ui/src/main/java/software/coley/recaf/ui/control/richtext/SafeCodeArea.java