Threads of a string or stringy threads? That's the question

  • 24
  • Locked
1. The getPartOfString method must return the substring between the first and the last tab characters. 2. The getPartOfString method should throw an exception if it receives invalid data: a) StringForFirstThreadTooShortException if the thread's name is FIRST_THREAD_NAME.
You can't complete this task, because you're not signed in.
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
DarthGizka
Level 24 , Wittenberg, Germany
8 June, 18:06
If it weren't for the helpful posts by null and Rom I wouldn't have been able to get my submission past the broken validator. However is responsible for the awful task specification and the even more awful submission validation code should be treated according to the following rules: 1) If their job contract specifies something like 'xxx USD' than they should be paid xxx unwashed, scratched dimes (because that is also consistent with the abbreviation 'USD'); if it says 'dollars' then they should be paid an amout of xxx in cheapest legal tender anywhere in the world that also goes by the name of 'dollar'. 2) Their salary should be paid out by a member of the International Space Station, only aboard said space station, only to the payee in person. Should the ISS resupply schedule be incompatible with the pay schedule then I suggest a dead drop somewhere in Antarctica or safe dropped into the Mariana trench.
Ian De Bie
Level 26 , Los Angeles, United States
8 November 2020, 17:31
the task conditions for this exercise is like reading a foreign language: gobbledygoop a) 1# : StringForFirstThreadTooShortException : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 b) java.lang.StringIndexOutOfBoundsException: String index out of range: -1 : StringForSecondThreadTooShortException : 2# c) RuntimeException : java.lang.StringIndexOutOfBoundsException: String index out of range: -1 : 3#
null
Level 26 , Orlando, United States
28 July 2020, 20:03
protected String getFormattedStringForOtherThread(Thread t, Throwable e, String string) { return String.format(string, e.getClass().getSimpleName(), e.getMessage(), t.getName()); } getName() call showing null in console output, but I got passed.
Rom
Level 26 , Paris, France
24 March, 13:32
To correct this, you use constructor in your exception class :
public class StringForFirstThreadTooShortException extends RuntimeException {
    StringForFirstThreadTooShortException(String s) {
        super(s);
    }
}
then,in your solution class you pass the message :
if (threadName.equals(Solution.FIRST_THREAD_NAME)) throw new StringForFirstThreadTooShortException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");
            else if (threadName.equals(Solution.SECOND_THREAD_NAME)) throw new StringForSecondThreadTooShortException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");
            else throw new RuntimeException("java.lang.StringIndexOutOfBoundsException: String index out of range: -1");