theonedev/onedev · error · ValidationException

Reference project not specified: <referenceString>

Error message

Reference project not specified: <referenceString>

What it means

EntityReference.of parses references of the form '#number' or 'path#number'. When the path part is empty (string starts with '#') and no currentProject was supplied, there is no project context to resolve the number against, so a ValidationException 'Reference project not specified' is thrown.

Source

Thrown at server-core/src/main/java/io/onedev/server/entityreference/EntityReference.java:73

	private static Long parseReferenceNumber(String numberString) {
		try {
			return Long.valueOf(numberString);
		} catch (NumberFormatException e) {
			throw new ValidationException("Invalid reference number: " + numberString);
		}
	}

	public static EntityReference of(String type, String referenceString, @Nullable Project currentProject) {
		var projectService = OneDev.getInstance(ProjectService.class);
		var index = referenceString.indexOf('#');
		if (index != -1) {
			var projectPath = referenceString.substring(0, index);
			var number = parseReferenceNumber(referenceString.substring(index + 1));
			if (projectPath.length() == 0) {
				if (currentProject != null)
					return EntityReference.of(type, currentProject, number);
				else
					throw new ValidationException("Reference project not specified: " + referenceString);
			} else {
				var project = projectService.findByPath(projectPath);
				if (project != null)
					return EntityReference.of(type, project, number);
				else
					throw new ValidationException("Reference project not found: " + projectPath);
			}
		}
		index = referenceString.indexOf('-');
		if (index != -1) {
			var projectKey = referenceString.substring(0, index);
			var number = parseReferenceNumber(referenceString.substring(index + 1));
			var project = projectService.findByKey(projectKey);
			if (project != null)
				return EntityReference.of(type, project, number);
			else
				throw new ValidationException("Reference project not found with key: " + projectKey);
		}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Pass the current project as the third argument so '#number' can be resolved in that context.
  2. Use a fully qualified reference like "projectPath#number" instead of a bare '#number'.
  3. Use the '-number' (projectKey-number) form, e.g. "PRJ-123".
  4. If no project can be determined, reject the input earlier with a clearer message.

Example fix

// before
EntityReference.of("issue", "#123", null);
// after
EntityReference.of("issue", "#123", currentProject); // or "myproj#123"
Defensive patterns

Strategy: validation

Validate before calling

if (referenceString.startsWith("#") && currentProject == null)
    throw new IllegalArgumentException("Reference '" + referenceString + "' needs a current project");

Type guard

boolean resolvableWithoutProject(String ref) {
    return !ref.startsWith("#");
}

Try / catch

try {
    EntityReference ref = EntityReference.of("issue", input, currentProject);
} catch (ValidationException e) {
    if (e.getMessage().startsWith("Reference project not specified")) {
        // require a project context or ask user to qualify the reference
    }
}

Prevention

When it happens

Trigger: Calling EntityReference.of(type, "#123", null) — a project-less '#number' reference with currentProject == null.

Common situations: Background/system code that has no request-scoped project calling of() with a bare '#number' string; extracting a reference from user input and losing the current project context.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/281a766a7598e170. Report an issue: GitHub.