Skip to content

Commit 48d83f0

Browse files
authored
Mini articles/java unknown stack trace (eugenp#11627)
* unknown source in stack trace * Improved comment * creating an intentional exception Co-authored-by: Sameer <d7495b5879fca1ec1367476a5395a60a8e9baec9>
1 parent 9ec066f commit 48d83f0

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

core-java-modules/core-java-exceptions-3/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
</dependency>
2525
</dependencies>
2626

27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-compiler-plugin</artifactId>
32+
<version>3.8.1</version>
33+
<configuration>
34+
<compilerArgs>
35+
<!-- Comment the arg below to print complete stack trace information -->
36+
<!-- <arg>-g:none</arg>-->
37+
</compilerArgs>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
2743
<properties>
2844
<h2.version>1.4.191</h2.version>
2945
</properties>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.unknownsourcestacktrace;
2+
3+
import com.baeldung.unknownsourcestacktrace.dto.User;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
public class Main {
8+
private static final Logger logger = LoggerFactory.getLogger(Main.class);
9+
private static final int SHORT_NAME_LIMIT = 10;
10+
11+
public static void main(String[] args) {
12+
User user = new User();
13+
user.setName("Tom");
14+
15+
logger.info(getGreetingMessage(user.getName()));
16+
}
17+
18+
private static String getGreetingMessage(String name) {
19+
return "Welcome " + getShortenedName(name) + "!";
20+
}
21+
22+
private static String getShortenedName(String name) {
23+
return name.substring(0, SHORT_NAME_LIMIT);
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.unknownsourcestacktrace.dto;
2+
3+
public class User {
4+
private String name;
5+
6+
public String getName() {
7+
return name;
8+
}
9+
10+
public void setName(String name) {
11+
this.name = name;
12+
}
13+
}

0 commit comments

Comments
 (0)