将 Lombok NonNull 注释添加到 JDO 实体字段后编译失败

发布于 2025-01-10 00:02:01 字数 5023 浏览 2 评论 0原文

基于 Apache Isis 2 SimpleApp JDO 项目 (https://github.com/ apache/isis-app-simpleapp/tree/jdo)我尝试稍微修改 SimpleObject 类来标记一些字段(namenotes< /代码>) 作为使用 Lombok 注释 @NonNull 不能为空。这意外地导致编译失败

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project simpleapp-jdo-module-simple: Compilation failure: Compilation failure: 
Error:  /home/runner/work/isis-app-simpleapp/isis-app-simpleapp/module-simple/target/generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java:[35,51] cannot find symbol
Error:    symbol:   class java
Error:    location: class domainapp.modules.simple.dom.so.QSimpleObject
Error:  /home/runner/work/isis-app-simpleapp/isis-app-simpleapp/module-simple/target/generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java:[36,51] cannot find symbol
Error:    symbol:   class java
Error:    location: class domainapp.modules.simple.dom.so.QSimpleObject
Error:  -> [Help 1]

相关 GitHub 操作: https://github .com/a-st/isis-app-simpleapp/runs/5330590432

DataNucleus 生成的类isis-app-simpleapp/module-simple/target/ generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java 看起来像这样

package domainapp.modules.simple.dom.so;

import javax.annotation.Generated;
import javax.jdo.query.*;
import org.datanucleus.api.jdo.query.*;

@Generated(value="org.datanucleus.jdo.query.JDOQueryProcessor")
public class QSimpleObject extends PersistableExpressionImpl<SimpleObject> implements PersistableExpression<SimpleObject>
{
    public static final QSimpleObject jdoCandidate = candidate("this");

    public static QSimpleObject candidate(String name)
    {
        return new QSimpleObject(null, name, 5);
    }

    public static QSimpleObject candidate()
    {
        return jdoCandidate;
    }

    public static QSimpleObject parameter(String name)
    {
        return new QSimpleObject(SimpleObject.class, name, ExpressionType.PARAMETER);
    }

    public static QSimpleObject variable(String name)
    {
        return new QSimpleObject(SimpleObject.class, name, ExpressionType.VARIABLE);
    }

    public final ObjectExpression<org.apache.isis.applib.services.repository.RepositoryService> repositoryService;
    public final ObjectExpression<org.apache.isis.applib.services.title.TitleService> titleService;
    public final ObjectExpression<org.apache.isis.applib.services.message.MessageService> messageService;
    public final ObjectExpression<@lombok.NonNull java.lang.String> name;
    public final ObjectExpression<@lombok.NonNull java.lang.String> notes;

    public QSimpleObject(PersistableExpression parent, String name, int depth)
    {
        super(parent, name);
        this.repositoryService = new ObjectExpressionImpl<org.apache.isis.applib.services.repository.RepositoryService>(this, "repositoryService");
        this.titleService = new ObjectExpressionImpl<org.apache.isis.applib.services.title.TitleService>(this, "titleService");
        this.messageService = new ObjectExpressionImpl<org.apache.isis.applib.services.message.MessageService>(this, "messageService");
        this.name = new StringExpressionImpl(this, "name");
        this.notes = new StringExpressionImpl(this, "notes");
    }

    public QSimpleObject(Class type, String name, ExpressionType exprType)
    {
        super(type, name, exprType);
        this.repositoryService = new ObjectExpressionImpl<org.apache.isis.applib.services.repository.RepositoryService>(this, "repositoryService");
        this.titleService = new ObjectExpressionImpl<org.apache.isis.applib.services.title.TitleService>(this, "titleService");
        this.messageService = new ObjectExpressionImpl<org.apache.isis.applib.services.message.MessageService>(this, "messageService");
        this.name = new StringExpressionImpl(this, "name");
        this.notes = new StringExpressionImpl(this, "notes");
    }
}

根据 Visual Studio Code,以下几行是导致问题(非法放置注释:类型注释必须直接位于它们要影响的类型的简单名称之前(或 []数组)Java(1610613796))

    public final ObjectExpression<@lombok.NonNull java.lang.String> name;
    public final ObjectExpression<@lombok.NonNull java.lang.String> notes;

在此处输入图像描述

源代码位于 https://github.com/a-st/isis-应用程序-simpleapp/tree/jdo-lombok-nonnull

Based on the Apache Isis 2 SimpleApp JDO project (https://github.com/apache/isis-app-simpleapp/tree/jdo) I tried to slightly modify the SimpleObject class to mark some fields (name and notes) as not nullable using the Lombok annotation @NonNull. This unexpectedly results in a compilation failure

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project simpleapp-jdo-module-simple: Compilation failure: Compilation failure: 
Error:  /home/runner/work/isis-app-simpleapp/isis-app-simpleapp/module-simple/target/generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java:[35,51] cannot find symbol
Error:    symbol:   class java
Error:    location: class domainapp.modules.simple.dom.so.QSimpleObject
Error:  /home/runner/work/isis-app-simpleapp/isis-app-simpleapp/module-simple/target/generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java:[36,51] cannot find symbol
Error:    symbol:   class java
Error:    location: class domainapp.modules.simple.dom.so.QSimpleObject
Error:  -> [Help 1]

Related GitHub Action: https://github.com/a-st/isis-app-simpleapp/runs/5330590432

The DataNucleus generated class isis-app-simpleapp/module-simple/target/generated-sources/annotations/domainapp/modules/simple/dom/so/QSimpleObject.java looks like this

package domainapp.modules.simple.dom.so;

import javax.annotation.Generated;
import javax.jdo.query.*;
import org.datanucleus.api.jdo.query.*;

@Generated(value="org.datanucleus.jdo.query.JDOQueryProcessor")
public class QSimpleObject extends PersistableExpressionImpl<SimpleObject> implements PersistableExpression<SimpleObject>
{
    public static final QSimpleObject jdoCandidate = candidate("this");

    public static QSimpleObject candidate(String name)
    {
        return new QSimpleObject(null, name, 5);
    }

    public static QSimpleObject candidate()
    {
        return jdoCandidate;
    }

    public static QSimpleObject parameter(String name)
    {
        return new QSimpleObject(SimpleObject.class, name, ExpressionType.PARAMETER);
    }

    public static QSimpleObject variable(String name)
    {
        return new QSimpleObject(SimpleObject.class, name, ExpressionType.VARIABLE);
    }

    public final ObjectExpression<org.apache.isis.applib.services.repository.RepositoryService> repositoryService;
    public final ObjectExpression<org.apache.isis.applib.services.title.TitleService> titleService;
    public final ObjectExpression<org.apache.isis.applib.services.message.MessageService> messageService;
    public final ObjectExpression<@lombok.NonNull java.lang.String> name;
    public final ObjectExpression<@lombok.NonNull java.lang.String> notes;

    public QSimpleObject(PersistableExpression parent, String name, int depth)
    {
        super(parent, name);
        this.repositoryService = new ObjectExpressionImpl<org.apache.isis.applib.services.repository.RepositoryService>(this, "repositoryService");
        this.titleService = new ObjectExpressionImpl<org.apache.isis.applib.services.title.TitleService>(this, "titleService");
        this.messageService = new ObjectExpressionImpl<org.apache.isis.applib.services.message.MessageService>(this, "messageService");
        this.name = new StringExpressionImpl(this, "name");
        this.notes = new StringExpressionImpl(this, "notes");
    }

    public QSimpleObject(Class type, String name, ExpressionType exprType)
    {
        super(type, name, exprType);
        this.repositoryService = new ObjectExpressionImpl<org.apache.isis.applib.services.repository.RepositoryService>(this, "repositoryService");
        this.titleService = new ObjectExpressionImpl<org.apache.isis.applib.services.title.TitleService>(this, "titleService");
        this.messageService = new ObjectExpressionImpl<org.apache.isis.applib.services.message.MessageService>(this, "messageService");
        this.name = new StringExpressionImpl(this, "name");
        this.notes = new StringExpressionImpl(this, "notes");
    }
}

According to Visual Studio Code the following lines are causing issues (Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)Java(1610613796))

    public final ObjectExpression<@lombok.NonNull java.lang.String> name;
    public final ObjectExpression<@lombok.NonNull java.lang.String> notes;

enter image description here

The source code is located at https://github.com/a-st/isis-app-simpleapp/tree/jdo-lombok-nonnull

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2025-01-17 00:02:02

问题似乎与 https://github.com/datanucleus/datanucleus- 有关jdo-query/issues/18 并通过指定解决

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-jdo-query</artifactId>
            <version>6.0.0-m1</version>
        </dependency>

Issue seems to be related to https://github.com/datanucleus/datanucleus-jdo-query/issues/18 and is solved with specifying

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-jdo-query</artifactId>
            <version>6.0.0-m1</version>
        </dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文