You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置FileEntityStoreService?激活时遇除零异常问询

Fixing java.lang.ArithmeticException: / by zero in Apache Polygene FileEntityStore

Got it, let's tackle this issue head-on. The root problem here is that the slices configuration property for FileEntityStoreService isn't being applied correctly—your assumption about a default value of 1 is spot-on, but in your current setup, that default isn't kicking in, leading to a division-by-zero when the store tries to calculate entity file paths.

Here are two straightforward, reliable ways to fix this:

1. Explicitly Set Defaults in Your Assembly Code

You can define the default slices value directly when assembling the FileEntityStoreAssembler. Modify your code to add a withDefaults block that explicitly sets slices to 1:

import org.apache.polygene.api.common.Visibility;
import org.apache.polygene.api.structure.Application;
import org.apache.polygene.bootstrap.Energy4Java;
import org.apache.polygene.entitystore.file.assembly.FileEntityStoreAssembler;
import org.apache.polygene.index.rdf.assembly.RdfNativeSesameStoreAssembler;
import org.apache.polygene.library.fileconfig.FileConfigurationAssembler;

public class FileStoreException {
    public static void main(String[] args) throws Exception {
        Energy4Java polygene = new Energy4Java();
        Application application = polygene.newApplication(factory -> factory.newApplicationAssembly(
            module -> {
                new FileConfigurationAssembler()
                    .visibleIn(Visibility.application)
                    .assemble(module);
                // Add this withDefaults block to set the slices default
                new FileEntityStoreAssembler()
                    .withConfig(module, Visibility.application)
                    .withDefaults(properties -> properties.set("slices", 1)) // <-- Fix right here
                    .assemble(module);
                new RdfNativeSesameStoreAssembler()
                    .withConfig(module, Visibility.application)
                    .assemble(module);
                module.defaultServices();
            }) 
        );
        application.activate();
    }
}

This guarantees that even if no external configuration is present, the slices value will default to 1, eliminating the division-by-zero error during activation.

2. Use a Configuration Properties File

Since you're already using FileConfigurationAssembler, you can externalize the setting with a properties file. Create a file named filestore.properties (place it in your classpath root, or configure the file assembler to point to its path) with this line:

org.apache.polygene.entitystore.file.slices=1

This approach is ideal if you want to keep configuration separate from your codebase, making it easier to adjust values later without recompiling.

Why This Fixes the Issue

Looking at your stack trace, the error occurs in FileEntityStoreMixin.getDataFile() where the code divides by the slices value to map entities to their storage files. By setting slices to a positive integer (1 is the intended default), you avoid the invalid division-by-zero scenario. The default value should be applied automatically, but in your setup, the config initialization wasn't picking it up—explicitly setting it closes that gap.

内容的提问来源于stack exchange,提问作者Nina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:05:34