简体   繁体   English

Nifi处理器中的Java ExceptionInInitializer错误

[英]Java ExceptionInInitializer Error in Nifi Processor

I am getting the ExceptionInIntializer error while create an instance of my Nifi processor's class (code below). 创建Nifi处理器类的实例(下面的代码)时,出现ExceptionInIntializer错误。 After looking online, this error results from having an error in the static initializer, which I do not have in my class. 联机查看后,此错误是由静态初始化程序中的错误导致的,而我在我的课程中没有这个错误。 Is there anything else in my code that may be causing this error? 我的代码中还有其他可能导致此错误的内容吗?

import ApplicationProperties;
import IndexAttributesUtil;
import ConvertRecordUtil;
import EntityTypeUpdates;
import ViewTypeUtil;
import QueryHelper;
import MServiceLocator;

public class RepProcessor extends AbstractProcessor {

    protected final Logger logger = LoggerFactory.getLogger(RepProcessor.class);
    private static final ApplicationProperties applicationProperties = new ApplicationProperties();

    protected static final PropertyDescriptor HOST = new PropertyDescriptor.Builder().name("Hostname")
            .description("").required(true)
            .defaultValue(applicationProperties.getHost()).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    protected static final PropertyDescriptor PORT = new PropertyDescriptor.Builder().name("Port")
            .description("").required(true).defaultValue(applicationProperties.getPort())
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    protected static final PropertyDescriptor TIMEOUT = new PropertyDescriptor.Builder().name("Timeout")
            .description("").required(true)
            .defaultValue(Integer.toString(applicationProperties.getTimeout()))
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    protected static final PropertyDescriptor MAIN_VIEW = new PropertyDescriptor.Builder().name("Main View")
            .description("").required(true).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    protected static final PropertyDescriptor SUB_VIEW = new PropertyDescriptor.Builder().name("Sub-View")
            .description("").required(false)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

    public static final PropertyDescriptor FETCH_SIZE = new PropertyDescriptor.Builder().name("fetch-size")
            .displayName("Fetch Size")
            .description("")
            .defaultValue("10000").required(true).addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR)
            .build();

    public static final PropertyDescriptor MAX_ROWS_PER_FLOW_FILE = new PropertyDescriptor.Builder()
            .name("max-rows-per-flow-file").displayName("Max Rows Per Flow File")
            .description("")
            .defaultValue("1000").required(true).addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR)
            .build();

    public static final PropertyDescriptor OUTPUT_BATCH_SIZE = new PropertyDescriptor.Builder()
            .name("output-batch-size").displayName("Output Batch Size")
            .description("")
            .defaultValue("0").required(true).addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR).build();

    public static final PropertyDescriptor MAX_FRAGMENTS = new PropertyDescriptor.Builder().name("max-fragments")
            .displayName("Maximum Number of Fragments")
            .description("")
            .defaultValue("0").required(true).addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR).build();

    public static final String A_VIEW = "A_VIEW";
    public static final String B_VIEW = "B_VIEW";
    public static final String C_VIEW = "C_VIEW";
    public static final String D_VIEW = "D_VIEW";
    public static final String E_VIEW = "E_VIEW";
    public static final String F_VIEW = "F_VIEW";
    public static final String G_VIEW = "G_VIEW";
    public static final String H_VIEW = "H_VIEW";
    public static final String I_VIEW = "I_TIE";
    public static final String J_MODE = "J_MODE";

    private long rowCounter = 0;
    private List<PropertyDescriptor> descriptors;
    private Set<Relationship> relationships;

    public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success")
            .description("All status updates will be routed to this relationship").build();
    public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure")
            .description("FlowFiles that failed to process.").build();

    protected MServiceLocator mService;
    private Gson gson = new Gson();

    protected QueryHelper queryHelper;
    protected EntityTypeUpdates EntityTypeUpdates = new EntityTypeUpdates();
    protected ResultSet rs;
    protected ResultSetMetaData rsmd;
    protected ViewTypeUtil viewTypeUtil = new ViewTypeUtil();
    protected IndexAttributesUtil indexAttributesUtil = new IndexAttributesUtil();
    protected ConvertRecordUtil ConvertRecordUtil = new ConvertRecordUtil();

    public RepProcessor() {
        logger.info("comes in the constructor");
        System.setProperty("javax.net.ssl.keyStore", applicationProperties.getKeyStore());
        System.setProperty("javax.net.ssl.keyStorePassword", applicationProperties.getKeyStorePassword());
        System.setProperty("javax.net.ssl.keyStoreType", applicationProperties.getKeyStoreType());
        System.setProperty("javax.net.ssl.trustStore", applicationProperties.getTrustStore());
        System.setProperty("javax.net.ssl.trustStorePassword", applicationProperties.getTrustStorePassword());
    }

    @Override
    protected void init(final ProcessorInitializationContext context) {
        final List<PropertyDescriptor> d = new ArrayList<>();

        d.add(HOST);
        d.add(PORT);
        d.add(TIMEOUT);
        d.add(MAIN_VIEW);
        d.add(SUB_VIEW);
        d.add(FETCH_SIZE);
        d.add(MAX_ROWS_PER_FLOW_FILE);
        d.add(MAX_FRAGMENTS);
        d.add(OUTPUT_BATCH_SIZE);

        this.descriptors = Collections.unmodifiableList(d);

        final Set<Relationship> relationships = new HashSet<>();
        relationships.add(REL_SUCCESS);
        relationships.add(REL_FAILURE);
        this.relationships = Collections.unmodifiableSet(relationships);
    }

    @Override
    protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
        return descriptors;
    }

    @OnScheduled
    public void onScheduled(final ProcessContext context) throws Exception {
        this.mService = makeMServiceLocator(context);
    }

    protected MServiceLocator makeMServiceLocator(ProcessContext context)
            throws NumberFormatException, Exception {
        return new MServiceLocator(context.getProperty(HOST).getValue(), context.getProperty(PORT).getValue(), Integer
                .parseInt(context.getProperty(TIMEOUT).getValue()));
    }

    @Override
    public Set<Relationship> getRelationships() {
        return this.relationships;
    }

    @Override
    public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
        // add code for onTrigger
    }
}

I'm creating the instance of this processor in my test class: 我正在测试类中创建此处理器的实例:

public class RepProcessorTest {

    EntityTypeUpdates EntityTypeUpdates;
    protected static QueryHelper queryHelper;
    RepProcessor repSpy;
    RepProcessor rep;
    MServiceLocator mService;
    ResultSet rs;
    ResultSetMetaData rsmd;

    @Before
    public void setup() throws NumberFormatException, Exception {
        rep = new RepProcessor();

    }

    @Test
    public void testOnTigger() throws Exception {
    }

This is the error where line 44 is rep = new RepProcessor(); 这是第44行是rep = new RepProcessor();的错误。

[ERROR] testOnTigger(processors.RepProcessorTest)  Time elapsed: 0.011 s  <<< ERROR!
java.lang.ExceptionInInitializerError
    at processors.RepProcessorTest.setup(RepProcessorTest.java:44)
Caused by: java.lang.NumberFormatException: null
    at processors.RepProcessorTest.setup(RepProcessorTest.java:44)
[ERROR] Errors:
[ERROR]   RepProcessorTest.setup:44 ExceptionInInitializer

The ExceptionInitializaerError means there is an error in some static code or object, and since you only have static variables, it is likely from creating one of the PropertyDescriptors. ExceptionInitializaerError表示某些静态代码或对象中有错误,并且由于您只有静态变量,因此很可能是通过创建PropertyDescriptor之一来实现的。

The error you posted shows that the cause of the error is NumberFormatException: null , which means some static code attempted to convert null into a number. 您发布的错误表明错误的原因是NumberFormatException: null ,这意味着某些静态代码试图将null转换为数字。

I would guess the issue is this property: 我猜问题是此属性:

protected static final PropertyDescriptor TIMEOUT = new PropertyDescriptor.Builder().name("Timeout")
        .description("").required(true)
        .defaultValue(Integer.toString(applicationProperties.getTimeout()))
        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();

If applicationProperties.getTimeout() is null, then it will pass null to Integer.toString() which would cause the error. 如果applicationProperties.getTimeout()为null,则它将null传递给Integer.toString() ,这将导致错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM