> For the complete documentation index, see [llms.txt](https://dejvokep.gitbook.io/boostedyaml/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dejvokep.gitbook.io/boostedyaml/settings/loadersettings.md).

# LoaderSettings

Loader settings cover all options related explicitly (only) to file loading. Always refer to Javadoc for complementary information.

## Parsing untrusted YAML

If you load YAML from untrusted sources, keep the parser limits at their defaults or tighten them:

* `setMaxCollectionAliases(int)` limits alias expansion ("billion laughs" style attacks);
* `setCodePointLimit(int)` limits the size of the input document;
* `setAllowDuplicateKeys(false)` rejects documents with duplicate keys.

## Creating a builder

Settings introduced by BoostedYAML follow builder design pattern, e.g. you may build your own settings using:

```java
LoaderSettings.builder() /*configure*/ .build()
```

## Basic settings

### Create file if absent

```java
Builder#setCreateFileIfAbsent(boolean createFileIfAbsent)
```

Sets if to create a new file and save it if it does not exist automatically.

{% hint style="warning" %}
Not effective if there is no file associated with the document.
{% endhint %}

**Default:** `true` (enabled)

### Update automatically

```java
Builder#setAutoUpdate(boolean autoUpdate)
```

If enabled, automatically calls [`YamlFile#update()`](/boostedyaml/getting-started/updating-a-file.md#updating) after the document has been loaded.

{% hint style="warning" %}
Not effective if there are no defaults associated with the document.
{% endhint %}

**Default:** `false` (disabled)

## Advanced settings

### Error labels

```java
Builder#setErrorLabel(@NotNull String label)
```

Sets custom label for error messages.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setLabel\(java.lang.String\))\
**Related YAML spec (v1.2.2):** -

### Detailed errors

```java
Builder#setDetailedErrors(boolean detailedErrors)
```

Sets if to print detailed error messages.

**Default:** `true`\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setUseMarks\(boolean\))\
**Related YAML spec (v1.2.2):** -

### Allow duplicate keys

```java
Builder#setAllowDuplicateKeys(boolean allowDuplicateKeys)
```

Sets if to allow duplicate keys in sections (last key wins when loading).

**Default:** `true`\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setAllowDuplicateKeys\(boolean\))\
**Related YAML spec (v1.2.2):** -

### Max collection aliases

```java
Builder#setMaxCollectionAliases(int maxCollectionAliases)
```

Sets maximum aliases a collection can have to prevent memory leaks (see [Billion laughs attack](https://en.wikipedia.org/wiki/Billion_laughs_attack)).

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setMaxAliasesForCollections\(int\))\
**Related YAML spec (v1.2.2):** -

### Tag constructors

```java
Builder#setTagConstructors(@NotNull Map<Tag, ConstructNode> constructors)
```

Sets custom node to Java object constructors, per YAML tag.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setTagConstructors\(java.util.Map\))\
**Related YAML spec (v1.2.2):** [JSON schema tags](https://yaml.org/spec/1.2.2/#1021-tags), [failsafe schema tags](https://yaml.org/spec/1.2.2/#failsafe-schema)

### Schema

```java
Builder#setSchema(@NotNull Schema schema)
```

Sets custom schema to use. Schemas are used to resolve and determine object tags contained within a document. This setting replaces `setScalarResolver` available until the 1.3.6 release.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setSchema\(org.snakeyaml.engine.v2.schema.Schema\))\
**Related YAML spec (v1.2.2):** [JSON schema tags](https://yaml.org/spec/1.2.2/#1021-tags), [failsafe schema tags](https://yaml.org/spec/1.2.2/#failsafe-schema)

### Environment config

```java
Builder#setEnvironmentConfig(@Nullable EnvConfig envConfig)
```

Sets custom environment variable config.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setEnvConfig\(java.util.Optional\))\
**Related YAML spec (v1.2.2):** -

### Code point limit

```java
Builder#setCodePointLimit(int limit)
```

Sets the limit on the code point length of the incoming document. Please note that this is not the actual size of the document in bytes - that depends on the used encoding. Should a document exceed the limit, an `YamlEngineException` will be thrown while loading the document.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setCodePointLimit\(int\))\
**Related YAML spec (v1.2.2):** -

### Buffer size

```java
Builder#setBufferSize(int size)
```

Sets the buffer size in bytes for passed input streams. Alternatively, make sure that the passed streams are already buffered, when this setting rarely has any impact.

**Default:** defined by the parent method\
**Parent method docs (v2.10):** [click](https://javadoc.io/doc/org.snakeyaml/snakeyaml-engine/2.10/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setBufferSize\(java.lang.Integer\))\
**Related YAML spec (v1.2.2):** -
