The following issues were found

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxHomeController.java
18 issues
Avoid unused private fields such as 'logger'.
Design

Line: 33

              @RequestMapping("/wx/home")
@Validated
public class WxHomeController {
    private final Log logger = LogFactory.getLog(WxHomeController.class);

    @Autowired
    private LitemallAdService adService;

    @Autowired

            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 33

              @RequestMapping("/wx/home")
@Validated
public class WxHomeController {
    private final Log logger = LogFactory.getLog(WxHomeController.class);

    @Autowired
    private LitemallAdService adService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

                  private final Log logger = LogFactory.getLog(WxHomeController.class);

    @Autowired
    private LitemallAdService adService;

    @Autowired
    private LitemallGoodsService goodsService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                  private LitemallAdService adService;

    @Autowired
    private LitemallGoodsService goodsService;

    @Autowired
    private LitemallBrandService brandService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 42

                  private LitemallGoodsService goodsService;

    @Autowired
    private LitemallBrandService brandService;

    @Autowired
    private LitemallTopicService topicService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 45

                  private LitemallBrandService brandService;

    @Autowired
    private LitemallTopicService topicService;

    @Autowired
    private LitemallCategoryService categoryService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 48

                  private LitemallTopicService topicService;

    @Autowired
    private LitemallCategoryService categoryService;

    @Autowired
    private WxGrouponRuleService grouponService;

    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 51

                  private LitemallCategoryService categoryService;

    @Autowired
    private WxGrouponRuleService grouponService;

    @Autowired
    private LitemallCouponService couponService;

    private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(9);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 54

                  private WxGrouponRuleService grouponService;

    @Autowired
    private LitemallCouponService couponService;

    private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(9);

    private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();


            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 64

              
    @GetMapping("/cache")
    public Object cache(@NotNull String key) {
        if (!key.equals("litemall_cache")) {
            return ResponseUtil.fail();
        }

        // 清除缓存
        HomeCacheManager.clearAll();

            

Reported by PMD.

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxGrouponRuleService.java
18 issues
Avoid unused private fields such as 'logger'.
Design

Line: 19

              
@Service
public class WxGrouponRuleService {
    private final Log logger = LogFactory.getLog(WxGrouponRuleService.class);

    @Autowired
    private LitemallGrouponRulesService grouponRulesService;
    @Autowired
    private LitemallGrouponService grouponService;

            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 19

              
@Service
public class WxGrouponRuleService {
    private final Log logger = LogFactory.getLog(WxGrouponRuleService.class);

    @Autowired
    private LitemallGrouponRulesService grouponRulesService;
    @Autowired
    private LitemallGrouponService grouponService;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 22

                  private final Log logger = LogFactory.getLog(WxGrouponRuleService.class);

    @Autowired
    private LitemallGrouponRulesService grouponRulesService;
    @Autowired
    private LitemallGrouponService grouponService;
    @Autowired
    private LitemallGoodsService goodsService;


            

Reported by PMD.

Avoid unused private fields such as 'grouponService'.
Design

Line: 24

                  @Autowired
    private LitemallGrouponRulesService grouponRulesService;
    @Autowired
    private LitemallGrouponService grouponService;
    @Autowired
    private LitemallGoodsService goodsService;


    public List<GrouponRuleVo> queryList(Integer page, Integer size) {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 26

                  @Autowired
    private LitemallGrouponService grouponService;
    @Autowired
    private LitemallGoodsService goodsService;


    public List<GrouponRuleVo> queryList(Integer page, Integer size) {
        return queryList(page, size, "add_time", "desc");
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 38

                      Page<LitemallGrouponRules> grouponRulesList = (Page<LitemallGrouponRules>)grouponRulesService.queryList(page, size, sort, order);

        Page<GrouponRuleVo> grouponList = new Page<GrouponRuleVo>();
        grouponList.setPages(grouponRulesList.getPages());
        grouponList.setPageNum(grouponRulesList.getPageNum());
        grouponList.setPageSize(grouponRulesList.getPageSize());
        grouponList.setTotal(grouponRulesList.getTotal());

        for (LitemallGrouponRules rule : grouponRulesList) {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 39

              
        Page<GrouponRuleVo> grouponList = new Page<GrouponRuleVo>();
        grouponList.setPages(grouponRulesList.getPages());
        grouponList.setPageNum(grouponRulesList.getPageNum());
        grouponList.setPageSize(grouponRulesList.getPageSize());
        grouponList.setTotal(grouponRulesList.getTotal());

        for (LitemallGrouponRules rule : grouponRulesList) {
            Integer goodsId = rule.getGoodsId();

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 40

                      Page<GrouponRuleVo> grouponList = new Page<GrouponRuleVo>();
        grouponList.setPages(grouponRulesList.getPages());
        grouponList.setPageNum(grouponRulesList.getPageNum());
        grouponList.setPageSize(grouponRulesList.getPageSize());
        grouponList.setTotal(grouponRulesList.getTotal());

        for (LitemallGrouponRules rule : grouponRulesList) {
            Integer goodsId = rule.getGoodsId();
            LitemallGoods goods = goodsService.findById(goodsId);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 41

                      grouponList.setPages(grouponRulesList.getPages());
        grouponList.setPageNum(grouponRulesList.getPageNum());
        grouponList.setPageSize(grouponRulesList.getPageSize());
        grouponList.setTotal(grouponRulesList.getTotal());

        for (LitemallGrouponRules rule : grouponRulesList) {
            Integer goodsId = rule.getGoodsId();
            LitemallGoods goods = goodsService.findById(goodsId);
            if (goods == null)

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 49

                          if (goods == null)
                continue;

            GrouponRuleVo grouponRuleVo = new GrouponRuleVo();
            grouponRuleVo.setId(goods.getId());
            grouponRuleVo.setName(goods.getName());
            grouponRuleVo.setBrief(goods.getBrief());
            grouponRuleVo.setPicUrl(goods.getPicUrl());
            grouponRuleVo.setCounterPrice(goods.getCounterPrice());

            

Reported by PMD.

litemall-core/src/main/java/org/linlinjava/litemall/core/notify/AliyunSmsSender.java
18 issues
Logger calls should be surrounded by log level guards.
Design

Line: 118

                              smsResult.setSuccessful(true);
            }else {
                smsResult.setSuccessful(false);
                logger.error("短信发送失败:"+response.getData());
            }

            return smsResult;
        } catch (ServerException e) {
            e.printStackTrace();

            

Reported by PMD.

The class 'AliyunSmsSender' is suspected to be a Data Class (WOC=20.000%, NOPA=0, NOAM=8, WMC=17)
Design

Line: 22

              /*
 * 阿里云短信服务
 */
public class AliyunSmsSender implements SmsSender {
    private final Log logger = LogFactory.getLog(AliyunSmsSender.class);

    private String regionId;
    private String accessKeyId;
    private String accessKeySecret;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 23

               * 阿里云短信服务
 */
public class AliyunSmsSender implements SmsSender {
    private final Log logger = LogFactory.getLog(AliyunSmsSender.class);

    private String regionId;
    private String accessKeyId;
    private String accessKeySecret;
    private String sign;

            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 23

               * 阿里云短信服务
 */
public class AliyunSmsSender implements SmsSender {
    private final Log logger = LogFactory.getLog(AliyunSmsSender.class);

    private String regionId;
    private String accessKeyId;
    private String accessKeySecret;
    private String sign;

            

Reported by PMD.

This final field could be made static
Design

Line: 30

                  private String accessKeySecret;
    private String sign;

    private final String okCode = "OK";

    public String getRegionId() {
        return regionId;
    }


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 30

                  private String accessKeySecret;
    private String sign;

    private final String okCode = "OK";

    public String getRegionId() {
        return regionId;
    }


            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 94

                        如果开发者在阿里云短信申请的模板参数是其他命名,请开发者自行调整这里的代码,或者直接写死。
         */
        String templateParam = "{}";
        if(params.length == 1){
            Map<String, String> data = new HashMap<>();
            data.put("code", params[0]);
            templateParam = JacksonUtil.toJson(data);
        }
        else if(params.length > 1){

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 99

                          data.put("code", params[0]);
            templateParam = JacksonUtil.toJson(data);
        }
        else if(params.length > 1){
            Map<String, String> data = new HashMap<>();
            data.put("code", params[0]);
            for(int i = 1; i < params.length; i++){
                data.put("code" + i, params[i]);
            }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 113

                          CommonResponse response = client.getCommonResponse(request);
            SmsResult smsResult = new SmsResult();
            smsResult.setResult(response);
            String code =  Jackson.jsonNodeOf(response.getData()).get("Code").asText();
            if (response.getHttpResponse().isSuccess() && okCode.equals(code) ){
                smsResult.setSuccessful(true);
            }else {
                smsResult.setSuccessful(false);
                logger.error("短信发送失败:"+response.getData());

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 113

                          CommonResponse response = client.getCommonResponse(request);
            SmsResult smsResult = new SmsResult();
            smsResult.setResult(response);
            String code =  Jackson.jsonNodeOf(response.getData()).get("Code").asText();
            if (response.getHttpResponse().isSuccess() && okCode.equals(code) ){
                smsResult.setSuccessful(true);
            }else {
                smsResult.setSuccessful(false);
                logger.error("短信发送失败:"+response.getData());

            

Reported by PMD.

litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java
18 issues
Avoid reassigning parameters such as 'content'
Design

Line: 134

                   * @param charset  编码方式
     * @return DataSign签名
     */
    private String encrypt(String content, String keyValue, String charset) {
        if (keyValue != null) {
            content = content + keyValue;
        }
        byte[] src;
        try {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 24

               */
public class ExpressService {

    private final Log logger = LogFactory.getLog(ExpressService.class);
    //请求url
    private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";

    private ExpressProperties properties;


            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 24

               */
public class ExpressService {

    private final Log logger = LogFactory.getLog(ExpressService.class);
    //请求url
    private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";

    private ExpressProperties properties;


            

Reported by PMD.

Private field 'ReqURL' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 26

              
    private final Log logger = LogFactory.getLog(ExpressService.class);
    //请求url
    private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";

    private ExpressProperties properties;

    public ExpressProperties getProperties() {
        return properties;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 26

              
    private final Log logger = LogFactory.getLog(ExpressService.class);
    //请求url
    private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";

    private ExpressProperties properties;

    public ExpressProperties getProperties() {
        return properties;

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 46

                   */
    public String getVendorName(String vendorCode) {
        for (Map<String, String> item : properties.getVendors()) {
            if (item.get("code").equals(vendorCode))
                return item.get("name");
        }
        return null;
    }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 72

                          String result = getOrderTracesByJson(expCode, expNo);
            ObjectMapper objMap = new ObjectMapper();
            ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
            ei.setShipperName(getVendorName(expCode));
            return ei;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }


            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 74

                          ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
            ei.setShipperName(getVendorName(expCode));
            return ei;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        return null;
    }

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 86

                   *
     * @throws Exception
     */
    private String getOrderTracesByJson(String expCode, String expNo) throws Exception {
        String requestData = "{'OrderCode':'','ShipperCode':'" + expCode + "','LogisticCode':'" + expNo + "'}";

        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
        params.put("EBusinessID", properties.getAppId());

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 111

                   * @param charset 编码方式
     * @throws Exception
     */
    private String MD5(String str, String charset) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(str.getBytes(charset));
        byte[] result = md.digest();
        StringBuilder sb = new StringBuilder(32);
        for (int i = 0; i < result.length; i++) {

            

Reported by PMD.

litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java
17 issues
This class has too many methods, consider refactoring it.
Design

Line: 15

              import java.security.SecureRandom;

@RunWith(PowerMockRunner.class)
public class BCryptTest {

    @Rule
    public final ExpectedException thrown = ExpectedException.none();

    @Test

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 18

              public class BCryptTest {

    @Rule
    public final ExpectedException thrown = ExpectedException.none();

    @Test
    public void testHashpwSaltIsNull() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", null);

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 21

                  public final ExpectedException thrown = ExpectedException.none();

    @Test
    public void testHashpwSaltIsNull() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", null);
    }

    @Test

            

Reported by PMD.

The String literal 'foo' appears 16 times in this file; the first occurrence is on line 23
Error

Line: 23

                  @Test
    public void testHashpwSaltIsNull() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", null);
    }

    @Test
    public void testHashpwSaltTooShort() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 27

                  }

    @Test
    public void testHashpwSaltTooShort() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "foo");
    }

    @Test

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 33

                  }

    @Test
    public void testHashpwInvalidSaltVersion() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "+2a$10$.....................");
    }

    @Test

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 39

                  }

    @Test
    public void testHashpwInvalidSaltVersion2() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "$1a$10$.....................");
    }

    @Test

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 45

                  }

    @Test
    public void testHashpwInvalidSaltRevision() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "$2+$10$.....................");
    }

    @Test

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 51

                  }

    @Test
    public void testHashpwInvalidSaltRevision2() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "$2a+10$.....................");
    }

    @Test

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 57

                  }

    @Test
    public void testHashpwSaltTooShort2() throws IllegalArgumentException {
        thrown.expect(IllegalArgumentException.class);
        BCrypt.hashpw("foo", "$2a$10+.....................");
    }

    @Test

            

Reported by PMD.

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCommentController.java
17 issues
The class 'WxCommentController' has a Standard Cyclomatic Complexity of 4 (Highest = 10).
Design

Line: 31

              @RestController
@RequestMapping("/wx/comment")
@Validated
public class WxCommentController {
    private final Log logger = LogFactory.getLog(WxCommentController.class);

    @Autowired
    private LitemallCommentService commentService;
    @Autowired

            

Reported by PMD.

The class 'WxCommentController' has a Modified Cyclomatic Complexity of 4 (Highest = 10).
Design

Line: 31

              @RestController
@RequestMapping("/wx/comment")
@Validated
public class WxCommentController {
    private final Log logger = LogFactory.getLog(WxCommentController.class);

    @Autowired
    private LitemallCommentService commentService;
    @Autowired

            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 32

              @RequestMapping("/wx/comment")
@Validated
public class WxCommentController {
    private final Log logger = LogFactory.getLog(WxCommentController.class);

    @Autowired
    private LitemallCommentService commentService;
    @Autowired
    private LitemallUserService userService;

            

Reported by PMD.

Avoid unused private fields such as 'logger'.
Design

Line: 32

              @RequestMapping("/wx/comment")
@Validated
public class WxCommentController {
    private final Log logger = LogFactory.getLog(WxCommentController.class);

    @Autowired
    private LitemallCommentService commentService;
    @Autowired
    private LitemallUserService userService;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

                  private final Log logger = LogFactory.getLog(WxCommentController.class);

    @Autowired
    private LitemallCommentService commentService;
    @Autowired
    private LitemallUserService userService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired

            

Reported by PMD.

Avoid unused private fields such as 'userService'.
Design

Line: 37

                  @Autowired
    private LitemallCommentService commentService;
    @Autowired
    private LitemallUserService userService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private LitemallGoodsService goodsService;
    @Autowired

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                  @Autowired
    private LitemallUserService userService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private LitemallGoodsService goodsService;
    @Autowired
    private LitemallTopicService topicService;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 41

                  @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private LitemallGoodsService goodsService;
    @Autowired
    private LitemallTopicService topicService;

    private Object validate(LitemallComment comment) {
        String content = comment.getContent();

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

                  @Autowired
    private LitemallGoodsService goodsService;
    @Autowired
    private LitemallTopicService topicService;

    private Object validate(LitemallComment comment) {
        String content = comment.getContent();
        if (StringUtils.isEmpty(content)) {
            return ResponseUtil.badArgument();

            

Reported by PMD.

The method 'validate' has a Standard Cyclomatic Complexity of 10.
Design

Line: 45

                  @Autowired
    private LitemallTopicService topicService;

    private Object validate(LitemallComment comment) {
        String content = comment.getContent();
        if (StringUtils.isEmpty(content)) {
            return ResponseUtil.badArgument();
        }


            

Reported by PMD.

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/util/JwtHelper.java
17 issues
Avoid reassigning parameters such as 'date'
Design

Line: 75

              		return 0;
	}
	
	public  Date getAfterDate(Date date, int year, int month, int day, int hour, int minute, int second){
		if(date == null){
			date = new Date();
		}
		
		Calendar cal = new GregorianCalendar();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 37

              		    Date expireDate = getAfterDate(nowDate,0,0,0,2,0,0);
	        map.put("alg", "HS256");
	        map.put("typ", "JWT");
		    String token = JWT.create()
		    	// 设置头部信息 Header
		    	.withHeader(map)
		    	// 设置 载荷 Payload
		    	.withClaim("userId", userId)
		        .withIssuer(ISSUSER)

            

Reported by PMD.

Avoid printStackTrace(); use a logger call instead.
Design

Line: 53

              		        .sign(algorithm);
		    return token;
		} catch (JWTCreationException exception){
			exception.printStackTrace();
		}
		return null;
	}
	
	public Integer verifyTokenAndGetUserId(String token) {

            

Reported by PMD.

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallUserService.java
17 issues
This class has too many methods, consider refactoring it.
Design

Line: 16

              import java.util.List;

@Service
public class LitemallUserService {
    @Resource
    private LitemallUserMapper userMapper;

    public LitemallUser findById(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 18

              @Service
public class LitemallUserService {
    @Resource
    private LitemallUserMapper userMapper;

    public LitemallUser findById(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 27

                  public UserVo findUserVoById(Integer userId) {
        LitemallUser user = findById(userId);
        UserVo userVo = new UserVo();
        userVo.setNickname(user.getNickname());
        userVo.setAvatar(user.getAvatar());
        return userVo;
    }

    public LitemallUser queryByOid(String openId) {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 28

                      LitemallUser user = findById(userId);
        UserVo userVo = new UserVo();
        userVo.setNickname(user.getNickname());
        userVo.setAvatar(user.getAvatar());
        return userVo;
    }

    public LitemallUser queryByOid(String openId) {
        LitemallUserExample example = new LitemallUserExample();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 34

              
    public LitemallUser queryByOid(String openId) {
        LitemallUserExample example = new LitemallUserExample();
        example.or().andWeixinOpenidEqualTo(openId).andDeletedEqualTo(false);
        return userMapper.selectOneByExample(example);
    }

    public void add(LitemallUser user) {
        user.setAddTime(LocalDateTime.now());

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 34

              
    public LitemallUser queryByOid(String openId) {
        LitemallUserExample example = new LitemallUserExample();
        example.or().andWeixinOpenidEqualTo(openId).andDeletedEqualTo(false);
        return userMapper.selectOneByExample(example);
    }

    public void add(LitemallUser user) {
        user.setAddTime(LocalDateTime.now());

            

Reported by PMD.

Rather than using a lot of String arguments, consider using a container object for those values.
Design

Line: 49

                      return userMapper.updateByPrimaryKeySelective(user);
    }

    public List<LitemallUser> querySelective(String username, String mobile, Integer page, Integer size, String sort, String order) {
        LitemallUserExample example = new LitemallUserExample();
        LitemallUserExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(username)) {
            criteria.andUsernameLike("%" + username + "%");

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 59

                      if (!StringUtils.isEmpty(mobile)) {
            criteria.andMobileEqualTo(mobile);
        }
        criteria.andDeletedEqualTo(false);

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 71

              
    public int count() {
        LitemallUserExample example = new LitemallUserExample();
        example.or().andDeletedEqualTo(false);

        return (int) userMapper.countByExample(example);
    }

    public List<LitemallUser> queryByUsername(String username) {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 78

              
    public List<LitemallUser> queryByUsername(String username) {
        LitemallUserExample example = new LitemallUserExample();
        example.or().andUsernameEqualTo(username).andDeletedEqualTo(false);
        return userMapper.selectByExample(example);
    }

    public boolean checkByUsername(String username) {
        LitemallUserExample example = new LitemallUserExample();

            

Reported by PMD.

litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java
16 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 32

                  public void test() throws IOException {
        String test = getClass().getClassLoader().getResource("litemall.png").getFile();
        File testFile = new File(test);
        tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
        Resource resource = tencentStorage.loadAsResource("litemall.png");
        String url = tencentStorage.generateUrl("litemall.png");
        logger.info("test file " + test);
        logger.info("store file " + resource.getURI());
        logger.info("generate url " + url);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 35

                      tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
        Resource resource = tencentStorage.loadAsResource("litemall.png");
        String url = tencentStorage.generateUrl("litemall.png");
        logger.info("test file " + test);
        logger.info("store file " + resource.getURI());
        logger.info("generate url " + url);
    }

}
            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 36

                      Resource resource = tencentStorage.loadAsResource("litemall.png");
        String url = tencentStorage.generateUrl("litemall.png");
        logger.info("test file " + test);
        logger.info("store file " + resource.getURI());
        logger.info("generate url " + url);
    }

}
            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 37

                      String url = tencentStorage.generateUrl("litemall.png");
        logger.info("test file " + test);
        logger.info("store file " + resource.getURI());
        logger.info("generate url " + url);
    }

}
            

Reported by PMD.

Private field 'logger' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 24

              @SpringBootTest
public class TencentStorageTest {

    private Log logger = LogFactory.getLog(TencentStorageTest.class);
    @Autowired
    private TencentStorage tencentStorage;

    @Test
    public void test() throws IOException {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 24

              @SpringBootTest
public class TencentStorageTest {

    private Log logger = LogFactory.getLog(TencentStorageTest.class);
    @Autowired
    private TencentStorage tencentStorage;

    @Test
    public void test() throws IOException {

            

Reported by PMD.

Logger should be defined private static final and have the correct class
Error

Line: 24

              @SpringBootTest
public class TencentStorageTest {

    private Log logger = LogFactory.getLog(TencentStorageTest.class);
    @Autowired
    private TencentStorage tencentStorage;

    @Test
    public void test() throws IOException {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 26

              
    private Log logger = LogFactory.getLog(TencentStorageTest.class);
    @Autowired
    private TencentStorage tencentStorage;

    @Test
    public void test() throws IOException {
        String test = getClass().getClassLoader().getResource("litemall.png").getFile();
        File testFile = new File(test);

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 29

                  private TencentStorage tencentStorage;

    @Test
    public void test() throws IOException {
        String test = getClass().getClassLoader().getResource("litemall.png").getFile();
        File testFile = new File(test);
        tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
        Resource resource = tencentStorage.loadAsResource("litemall.png");
        String url = tencentStorage.generateUrl("litemall.png");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 30

              
    @Test
    public void test() throws IOException {
        String test = getClass().getClassLoader().getResource("litemall.png").getFile();
        File testFile = new File(test);
        tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png");
        Resource resource = tencentStorage.loadAsResource("litemall.png");
        String url = tencentStorage.generateUrl("litemall.png");
        logger.info("test file " + test);

            

Reported by PMD.

litemall-admin-api/src/test/java/org/linlinjava/litemall/admin/DbTest.java
16 issues
System.out.println is used
Design

Line: 30

                      int index1 = url.indexOf("3306/");
        int index2 = url.indexOf("?");
        String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);
    }

    @Test

            

Reported by PMD.

System.out.println is used
Design

Line: 31

                      int index2 = url.indexOf("?");
        String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);
    }

    @Test
    public void testFileCreate() throws IOException {

            

Reported by PMD.

System.out.println is used
Design

Line: 32

                      String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);
    }

    @Test
    public void testFileCreate() throws IOException {
        LocalDate localDate = LocalDate.now();

            

Reported by PMD.

System.out.println is used
Design

Line: 39

                  public void testFileCreate() throws IOException {
        LocalDate localDate = LocalDate.now();
        String fileName = localDate.toString() + ".sql";
        System.out.println(fileName);

        File file = new File("backup", fileName);
        file.getParentFile().mkdirs();
        file.createNewFile();
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 50

                  public void testFileDelete() throws IOException {
        LocalDate localDate = LocalDate.now();
        String fileName = localDate.toString() + ".sql";
        System.out.println(fileName);

        File file = new File("backup", fileName);
        file.deleteOnExit();
    }
}

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 20

              @SpringBootTest
public class DbTest {
    @Autowired
    private Environment environment;

    @Test
    public void test() {
        String user = environment.getProperty("spring.datasource.druid.username");
        String password = environment.getProperty("spring.datasource.druid.password");

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 23

                  private Environment environment;

    @Test
    public void test() {
        String user = environment.getProperty("spring.datasource.druid.username");
        String password = environment.getProperty("spring.datasource.druid.password");
        String url = environment.getProperty("spring.datasource.druid.url");
        int index1 = url.indexOf("3306/");
        int index2 = url.indexOf("?");

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 27

                      String user = environment.getProperty("spring.datasource.druid.username");
        String password = environment.getProperty("spring.datasource.druid.password");
        String url = environment.getProperty("spring.datasource.druid.url");
        int index1 = url.indexOf("3306/");
        int index2 = url.indexOf("?");
        String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);

            

Reported by PMD.

String.indexOf(char) is faster than String.indexOf(String).
Performance

Line: 28

                      String password = environment.getProperty("spring.datasource.druid.password");
        String url = environment.getProperty("spring.datasource.druid.url");
        int index1 = url.indexOf("3306/");
        int index2 = url.indexOf("?");
        String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 28

                      String password = environment.getProperty("spring.datasource.druid.password");
        String url = environment.getProperty("spring.datasource.druid.url");
        int index1 = url.indexOf("3306/");
        int index2 = url.indexOf("?");
        String db = url.substring(index1+5, index2);
        System.out.println(user);
        System.out.println(password);
        System.out.println(db);
    }

            

Reported by PMD.