theonedev/onedev · error · ValidationException

Link spec not allowed to link to the target issue

Error message

Link spec not allowed to link to the target issue

What it means

IssueLink.validate() checks that both ends of a bidirectional link satisfy the spec's issue queries. Each LinkSpec can define a parsed issue query restricting which issues may be linked; this error is thrown when the target issue does not match getSpec().getParsedIssueQuery(source issue's project). The spec intentionally disallows this link.

Source

Thrown at server-core/src/main/java/io/onedev/server/model/IssueLink.java:97

	}

	public void setPosition(int position) {
		this.position = position;
	}

	public void validate() {
		if (getSource().equals(getTarget()))
			throw new ValidationException("Cannot link to self");
		if (getSpec().getOpposite() != null) {
			if (getSource().getTargetLinks().stream()
					.anyMatch(it -> it.getSpec().equals(getSpec()) && it.getTarget().equals(getTarget())))
				throw new ValidationException("Source issue already linked to target issue via specified link spec");
			if (!getSpec().isMultiple()
					&& getSource().getTargetLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))
				throw new ValidationException(
						"Link spec is not multiple and the source issue is already linked to another issue via this link spec");
			if (!getSpec().getParsedIssueQuery(getSource().getProject()).matches(getTarget()))
				throw new ValidationException("Link spec not allowed to link to the target issue");
			if (!getSpec().getOpposite().isMultiple()
					&& getTarget().getSourceLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))
				throw new ValidationException(
						"Opposite side of link spec is not multiple and the target issue is already linked to another issue via this link spec");
			if (!getSpec().getOpposite().getParsedIssueQuery(getSource().getProject())
					.matches(getSource()))
				throw new ValidationException("Opposite side of link spec not allowed to link to the source issue");
		} else {
			if (getSource().getLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())
					&& it.getLinked(getSource()).equals(getTarget())))
				throw new ValidationException("Specified issues already linked via specified link spec");
			if (!getSpec().isMultiple()
					&& getSource().getLinks().stream().anyMatch(it -> it.getSpec().equals(getSpec())))
				throw new ValidationException(
						"Link spec is not multiple and source issue is already linked to another issue via this link spec");
			var parsedIssueQuery = getSpec().getParsedIssueQuery(getSource().getProject());
			if (!parsedIssueQuery.matches(getSource()) || !parsedIssueQuery.matches(getTarget()))
				throw new ValidationException("Link spec not allowed to link specified issues");

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the target issue matches the link spec's allowed-issue query (Administration > Links) and pick a target that satisfies it.
  2. Adjust the spec's issue query to include the states/projects/attributes of the issues you want to link.
  3. Link via a different spec whose query permits the target issue.
Defensive patterns

Strategy: validation

Validate before calling

var query = link.getSpec().getParsedIssueQuery(link.getSource().getProject());
if (!query.matches(link.getTarget())) throw new IllegalStateException("target not allowed by spec query");

Try / catch

try { IssueLink.createLink(link); } catch (ValidationException e) { // show which spec/query rejected the target }

Prevention

When it happens

Trigger: createLink called where the spec (with an opposite) defines an issue query and getTarget() fails that query when evaluated in the source issue's project.

Common situations: Admin scoped the link spec to e.g. 'State is Requirement' but the user links a bug; issues live in different projects and the query evaluates against the source's project; the query was tightened after the UI allowed the link to be drafted.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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