[Solved] o2o Error: addShopImg error:null / character to be escaped is missing

Operating system: Window10

1. During the JUnit test of ShopServiceTest, an error message is reported:addShopImg error:null as follows:

Solution: Modify the configuration information of PathUtil.java.

Check whether the two separators ofprivate static String separator=System. getProperty ("file. separator")are consistent and spelled correctly.

As long as the two separators are consistent and spelled correctly, there will be no null error message

2. The win10 system pops up:addShopImg error: character to be escaped is missing as follows:

Solution: Modify the configuration information of PathUtil.java.

Change all separator in replaceAll to Matcher quoteReplacement(separator)

Finally, the completely correct PathUtil.java source code is attached:

package com.imooc.o2o.util;

import java.util.regex.Matcher;

public class PathUtil {
	private static String separator = System.getProperty("file.separator");
	
	public static String getImgBasePath() {
		String os = System.getProperty("os.name");
		String basePath = "";
		if (os.toLowerCase().startsWith("win")) {
			basePath = "E:/Work/o2o/image";
		} else {
			basePath = "/home/Work/o2o/image";
		}
		basePath = basePath.replaceAll("/", Matcher.quoteReplacement(separator));
		return basePath;
	}
	
	public static String getShopImagePath(long shopId) {
		String imagePath = "upload/item/shop/" + shopId + "/";
		return imagePath.replaceAll("/", Matcher.quoteReplacement(separator));
	}
}

Read More: