private static void checkEnoughSpace(Program program, Address addr, int existingDataLen,
			DataTypeInstance dti, ClearDataMode clearMode) throws CodeUnitInsertionException {
		// NOTE: method not invoked when clearMode == ClearDataMode.CLEAR_SINGLE_DATA
		Listing listing = program.getListing();
		Address end = null;
		Address newEnd = null;
		try {
			end = addr.addNoWrap(existingDataLen - 1);
			newEnd = addr.addNoWrap(dti.getLength() - 1);
		}
		catch (AddressOverflowException e) {
			throw new CodeUnitInsertionException(
				"Not enough space to create DataType " + dti.getDataType().getDisplayName());
		}

		Instruction instr = listing.getInstructionAfter(end);
		if (instr != null && instr.getMinAddress().compareTo(newEnd) <= 0) {
			throw new CodeUnitInsertionException(
				"Not enough space to create DataType " + dti.getDataType().getDisplayName());
		}

		Data definedData = listing.getDefinedDataAfter(end);
		if (definedData == null || definedData.getMinAddress().compareTo(newEnd) > 0) {
			listing.clearCodeUnits(addr, addr, false);
			return;
		}

		if ((clearMode == ClearDataMode.CLEAR_ALL_UNDEFINED_CONFLICT_DATA ||
			clearMode == ClearDataMode.CLEAR_ALL_DEFAULT_CONFLICT_DATA) &&
			!isDataClearingDenied(definedData.getDataType(), clearMode)) {
			checkForDefinedData(dti, listing, newEnd, definedData.getMaxAddress(), clearMode);
		}
		else if (clearMode != ClearDataMode.CLEAR_ALL_CONFLICT_DATA) {
			throw new CodeUnitInsertionException(
				"Not enough space to create DataType " + dti.getDataType().getDisplayName());
		}
		listing.clearCodeUnits(addr, newEnd, false);
	}
Create data where existing data may already exist.
@param program the program
@param addr data address (offcut data address only allowed if clearMode == ClearDataMode.CLEAR_ALL_CONFLICT_DATA)
@param newType new data-type being applied
@param length data length (used only for Dynamic newDataType which has canSpecifyLength()==true)
@param stackPointers see {@link #reconcileAppliedDataType(DataType, DataType, boolean)}
@param clearMode see CreateDataMode
@return new data created
@throws CodeUnitInsertionException if data creation failed
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataUtilities.java