chinabugotech/hutool · error · BeanException

Get value of [{}] error!

Error message

Get value of [{}] error!

What it means

PropDesc.getValue(bean, targetType, ignoreError) invokes the underlying getter; if that getter throws (or reflection fails) and ignoreError is false, the exception is wrapped in a BeanException naming the field. With ignoreError true the failure is swallowed and the value is left null. This is the read-side counterpart of error 33.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/bean/PropDesc.java:214

	}

	/**
	 * 获取属性值,自动转换属性值类型<br>
	 * 首先调用字段对应的Getter方法获取值,如果Getter方法不存在,则判断字段如果为public,则直接获取字段值
	 *
	 * @param bean        Bean对象
	 * @param targetType  返回属性值需要转换的类型,null表示不转换
	 * @param ignoreError 是否忽略错误,包括转换错误和注入错误
	 * @return this
	 * @since 5.4.2
	 */
	public Object getValue(Object bean, Type targetType, boolean ignoreError) {
		Object result = null;
		try {
			result = getValue(bean);
		} catch (Exception e) {
			if (false == ignoreError) {
				throw new BeanException(e, "Get value of [{}] error!", getFieldName());
			}
		}

		if (null != result && null != targetType) {
			// 尝试将结果转换为目标类型,如果转换失败,返回null,即跳过此属性值。
			// 来自:issues#I41WKP@Gitee,当忽略错误情况下,目标类型转换失败应返回null
			// 如果返回原值,在集合注入时会成功,但是集合取值时会报类型转换错误
			return Convert.convertWithCheck(targetType, result, null, ignoreError);
		}
		return result;
	}

	/**
	 * 检查属性是否可读(即是否可以通过{@link #getValue(Object)}获取到值)
	 *
	 * @param checkTransient 是否检查Transient关键字或注解
	 * @return 是否可读
	 * @since 5.4.2

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Pass ignoreError=true to the copy/map API (e.g. copyProperties(src, tgt, CopyOptions.create().setIgnoreError(true))) to skip the failing property.
  2. Fix the throwing getter so it does not blow up on the input state.
  3. Exclude the problematic property via CopyOptions ignoreProperties.

Example fix

// before
BeanUtil.copyProperties(src, Target.class);
// after
BeanUtil.copyProperties(src, Target.class, CopyOptions.create().setIgnoreError(true));
Defensive patterns

Strategy: validation

Validate before calling

// use ignoreError=true on copy/map APIs to skip throwing getters
BeanUtil.copyProperties(src, T.class, CopyOptions.create().setIgnoreError(true));

Try / catch

try { return prop.getValue(bean, type, false); } catch (BeanException e) { return prop.getValue(bean, type, true); }

Prevention

When it happens

Trigger: A getter that itself throws (e.g. computes lazily and NPEs); a field whose getter is inaccessible; copyProperties/bean-to-bean mapping where ignoreError was not enabled.

Common situations: BeanUtil.copyProperties between beans with a faulty getter; BeanUtil.beanToMap hitting a getter that throws on certain states; record/class mismatch.

Related errors


AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14). Data as JSON: /api/errors/f8c41d92bd7e4282. Report an issue: GitHub.