Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform.

fork into my github

下载源码

git clone git@github.com:aiclr/spring-framework.git

切换到想编译的分支

git checkout -b 5.3.x origin/5.3.x

5.3.20

编译源码 官方说明文档

env:

  • archlinux
  • git
  • jdk / openjdk 11
  • idea 2022.2

直接运行 ./gradlew build 不出意外的话会出现下面列出的意外 解决问题后使用 *idea 打开项目

error

执行命令

./gradlew clean build

异常日志

spring-framework/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java:74: warning: [deprecation] isAccessible() in AccessibleObject has been deprecated
                if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
                          ^
error: warnings found and -Werror specified
1 error
1 warning

解决方案:
添加 @SuppressWarnings(“deprecation”)

vim spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java

code:

	/**
	 * Invoke a suspending function and converts it to {@link Mono} or
	 * {@link Flux}.
	 */
	@SuppressWarnings("deprecation")
	public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args) {
		KFunction<?> function = Objects.requireNonNull(ReflectJvmMapping.getKotlinFunction(method));
		if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
			KCallablesJvm.setAccessible(function, true);
		}
        ......
    }

bug

spring 文件是否为空 boolean isEmpty();

  • org.springframework.web.multipart.MultipartFile
    • org.springframework.web.multipart.support.StandardMultipartHttpServletRequest
    • org.springframework.web.multipart.commons.CommonsMultipartFile
    • org.springframework.mock.web.MockMultipartFile
  • MultipartFile 的 isEmpty() 方法是根据文件大小进行判断,不是判断对象是否为 null。 规范使用防止 NPE

source code

    StandardMultipartHttpServletRequest
    @Override
    public boolean isEmpty()
    {
        return (this.part.getSize() == 0);
    }
    CommonsMultipartFile
    @Override
    public boolean isEmpty()
    {
        return (this.size == 0);
    }
    MockMultipartFile
    @Override
    public boolean isEmpty()
    {
        return (this.content.length == 0);
    }